home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / DMA_API.TXT < prev    next >
Text File  |  1990-07-16  |  33KB  |  1,004 lines

  1.                  Virtual DMA Services (VDS)                              
  2.                         Version 1.00
  3.                    Printed July 16, 1990
  4.                      Table Of Contents
  5.  
  6.  
  7. Introduction..............................................1
  8.  
  9. Notes For Writing DMA Device Drivers......................2
  10.  
  11. Notes For DMA Service Environments........................3
  12.  
  13. Services..................................................6
  14.     Reserved Subfunctions.................................7
  15.     Get Version...........................................8
  16.     Lock DMA Region.......................................9
  17.     Unlock DMA Region....................................11
  18.     Scatter/Gather Lock Region...........................12
  19.     Scatter/Gather Unlock Region.........................14
  20.     Request DMA Buffer...................................15
  21.     Release DMA Buffer...................................16
  22.     Copy Into DMA Buffer.................................17
  23.     Copy Out Of DMA Buffer...............................18
  24.     Disable DMA Translation..............................19
  25.     Enable DMA Translation...............................20
  26.  
  27. Summary of Error Codes and Option Flags..................21
  28. .End Table C.
  29.  
  30.  
  31.                         INTRODUCTION
  32.  
  33.  
  34. DOS device  drivers which  perform DMA, program a controller
  35. with an address of a buffer region.  All software running in
  36. protected mode environments, whether running in virtual 8086
  37. mode or  in protected mode under a DOS extender, usually can
  38. not determine the physical address of their DMA region.  The
  39. DMA  controller   also  places   further  restrictions  upon
  40. acceptable DMA regions:  they must be in contiguous physical
  41. memory, on  XTs they  must be in the first 1Mb of memory and
  42. on XTs,  ATs and  compatibles they  must not  cross 64Kb  or
  43. 128Kb alignment  boundaries.   These  services  provide  the
  44. necessary support  to allow  a device  driver or application
  45. program to obtain the necessary information to program a DMA
  46. transfer using  either the  on board  DMA  controller  or  a
  47. busmaster DMA controller.
  48.  
  49. The services  are provided  through software  interrupt 4Bh.
  50. Programs  must   examine  bit   five  (5)  of  the  byte  at
  51. 0040:007Bh.   If the bit is set then they should use the DMA
  52. services.   Otherwise, the device can assume that all memory
  53. is mapped  linear = physical (probably running in real mode,
  54. this can  be a  dangerous  assumption,  if  the  machine  is
  55. actually running in virtual mode, because the protected mode
  56. software may  not support  this specification,  and there is
  57. not a method for checking for physical = linear).
  58.  
  59. An implementation  of the  DMA services  must provide either
  60. automatic remapping  of pages  to force regions of memory to
  61. be physically  contiguous or  support a  DMA buffer  with  a
  62. minimum size  of 16K,  if paging  is enabled  by the  system
  63. software.   Most 286  software can get by without supporting
  64. either option.
  65.  
  66. With the  exception of  the AX register and unless otherwise
  67. specified, all  registers and flags are preserved across DMA
  68. service calls.   The  AX register  contents are undefined on
  69. return unless  the carry  flag  is  set  in  which  case  AL
  70. contains an error code.
  71.  
  72.         NOTES FOR WRITING DMA DEVICE DRIVERS
  73.  
  74.  
  75. DMA devices that use these services must continually monitor
  76. bit five  (5) of  the byte  at 0040:007Bh before programming
  77. DMA.   The services  may be initialized or turned off at any
  78. time.
  79.  
  80. For example,  when a program begins using simulated expanded
  81. memory a  "LIMulator" will place the machine in Virtual 8086
  82. mode and  enable the  DMA services.  When all LIM memory has
  83. been deallocated it will return the machine to real mode and
  84. turn off the DMA services.
  85.  
  86. Note also  that the  type of DMA support provided may change
  87. dynamically.   For example,  the user  may run one protected
  88. mode environment,  exit it,  and then  run another protected
  89. mode environment.    In  this  case  the  services  will  be
  90. provided by two different implementations.
  91.  
  92. There are  various levels of support that device drivers can
  93. have for  DMA.    These options are listed below in order from
  94. best to worst:
  95.  
  96.      Support scatter/gather on the hardware adaptor
  97.      Break DMA    requests up  in software so that a buffer is
  98. never required
  99.      Break up  DMA into 16K or smaller pieces so the default
  100. buffer can be used
  101.      Force the user to override the buffer size
  102.  
  103. The last option is really not acceptable.  At the very least
  104. your software should chop up transfers into 16K pieces.  For
  105. example, it  is acceptable  to break  hard disk transfers at
  106. track boundaries.   A normal hard disk track will fit into a
  107. 16K buffer.
  108.  
  109. DMA devices  that are not as timing sensitive as disk drives
  110. should break  up transfers.  Ideally, all DMA adaptors would
  111. support scatter/gather in hardware.
  112.  
  113. In some  situations a  device driver  has  a  real  physical
  114. address that  it wants    to use    in a  DMA transfer.    These
  115. physical addresses  may be from memory allocated through XMS
  116. or INT    15h before DMA services were provided, or may be for
  117. memory that  exists on    an adapter  card,  etc.    In  these
  118. situations, DMA lock calls should not be called, because the
  119. service routines  must interpret  region addresses as linear
  120. addresses.     It  is    necessary,  however   to  call     the
  121. Disable/Enable Translation  services, if  the  standard  DMA
  122. controller is used for the transfer.
  123.  
  124. By convention, a buffer ID of zero in the DDS indicates that
  125. no buffer  has been  allocated.   Device driver software can
  126. check this field to determine if a buffer was allocated.
  127.  
  128.  
  129.         NOTES FOR IMPLEMENTING DMA SERVICES
  130.  
  131.  
  132. The recommended  method of  supporting these  services is to
  133. use a  DMA buffer  since it has been found to be faster than
  134. attempting to remap memory on 386 machines.  On 286 machines
  135. it is  possible to not implement a buffer; on these machines
  136. the software  calling the  services must already know how to
  137. split  up   transfers  to   deal  with     crossing  alignment
  138. boundaries.   It is  necessary    to  return  the  "No  buffer
  139. available" error  (04h) for  the Request  DMA Buffer service
  140. (07h).
  141.  
  142. All  implementations   of  these   services  should  provide
  143. mechanisms for    overriding the    size of  the DMA  buffer  or
  144. remap region.    Also,  all implementations  should provide a
  145. mechanism for  forcing the  buffer or remap region to reside
  146. in the    first megabyte    of  physical  memory.     The  actual
  147. mechanism for  doing this  will be implementation dependent.
  148. For example,  some programs  may use  a  configuration    file
  149. while others could use command line switches.
  150.  
  151. Lock calls  for memory    which is not "owned" by the provider
  152. of these  DMA services, memory allocated before the provider
  153. started running  including low    memory, EBIOS  data area and
  154. extended memory  allocated through  INT 15h or XMS, must not
  155. fail.    If auto-remapping  is supported,  then pages must be
  156. remapped to  force contiguous regions.    If auto-remapping is
  157. not supported, then it is necessary for the provider to keep
  158. these  memory  areas  contiguous.    Additionally,  in    some
  159. environments, device  drivers will  exist which attempt long
  160. term DMA  transfers.   In these environments it is necessary
  161. to allow  the user  to configure  the software    so that such
  162. transfers can  take place.   One  solution is  to force long
  163. term DMA  device drivers  to be  loaded after  the  provider
  164. software.   The other  solution is  to    keep  all  "unowned"
  165. memory mapped  at the  original location  so  linear  equals
  166. physical;  this   allows  transfers  started  prior  to  DMA
  167. services being provided to continue as normal.
  168.  
  169. Since other  hardware/software services  can be  provided on
  170. the INT  4Bh chain, it is necessary for provider software to
  171. determine if  they should  chain interrupts  when AH  is not
  172. 81h.   On  Micro  Channel  machines  this  can    be  done  by
  173. examining bit  three (3)  in the  byte at 0040:007Bh, if the
  174. bit is    set, then chaining is required, if it is clear, then
  175. it is  necessary to  examine the  vector contents.   If  the
  176. vector contents  are 0, or point to E000h or F000h ROM, then
  177. the interrupt  should not be chained, because it may go to a
  178. default IRQ  handler which  may EOI  an outstanding hardware
  179. interrupt.  Summary of bit 3 in 0040:007Bh:
  180.  
  181.  
  182.      Bit  3   Interrupt  4Bh  Intercepted  Indicator  (Micro
  183.       Channel Only)
  184.  
  185.      = 0  Interrupt vector  not intercepted.  check contents
  186.       of the  interrupt vector.   If contents are 0:0 or
  187.       segment values  of E000h or F000h, chaining is not
  188.       permitted.
  189.      = 1  Interrupt vector intercepted, chaining required.
  190.  
  191.  
  192. On  other  non-Micro  Channel  architectures  examining  the
  193. vector value  may be the only way to determine if interrupts
  194. should be chained.
  195.  
  196. If not    chaining, then    the interrupt should be ignored with
  197. an IRET without modifying registers or flags.
  198.  
  199.  
  200. Determining Which Error Codes to Return
  201.  
  202. The following  logic should  be used for the Lock DMA Region
  203. service (AX=8103h):
  204.  
  205.      IF region contiguous THEN
  206.     IF region does not cross alignment boundary THEN
  207.        Lock region, set buffer ID to zero, and return
  208.        with carry clear
  209.     ELSE
  210.        DO Buffer/Remap
  211.     ENDIF
  212.      ELSE
  213.     DO Buffer/Remap
  214.      ENDIF
  215.  
  216.  
  217.      BUFFER/REMAP:
  218.      IF buffer supported THEN
  219.     IF buffer disable flag clear THEN
  220.        DO Buffer
  221.     ELSE
  222.        Return with carry flag set and AL=1, 2, or 3
  223.     ENDIF
  224.      ELSE
  225.     IF remap supported THEN
  226.        IF remap disable flag clear THEN
  227.           DO Remap
  228.        ELSE
  229.           Return with carry flag set and AL=1, 2, or 3
  230.        ENDIF
  231.     ELSE
  232.        Return with carry flag set and AL=1, 2, or 3
  233.     ENDIF
  234.      ENDIF
  235.  
  236.  
  237.      BUFFER:
  238.      IF buffer available THEN
  239.     IF region size <= buffer size THEN
  240.        Allocate buffer
  241.        IF copy flag set THEN
  242.           Copy data from linear region to buffer
  243.        ENDIF
  244.        Set buffer ID (non-zero), set physical address
  245.        field to buffer physical address, and return
  246.        with carry clear
  247.     ELSE
  248.        Return with carry flag set and AL=05h
  249.     ENDIF
  250.      ELSE
  251.     Return with carry flag set and AL=06h
  252.      ENDIF
  253.  
  254.  
  255.  
  256.      REMAP:
  257.      IF region can be forced contiguous THEN
  258.     IF region will not cross specified boundary THEN
  259.        Force region contiguous, set physical address
  260.        field, set buffer ID to zero, and return with
  261.        carry clear
  262.     ELSE
  263.        Return with carry set and AL=02h
  264.     ENDIF
  265.      ELSE
  266.     Return with carry set and AL=01h
  267.      ENDIF
  268.  
  269.  
  270.               SERVICES
  271.  
  272.  
  273. Most services  take a  pointer to a DMA descriptor structure
  274. (DDS) as a parameter.  The structure is defined as follows:
  275.  
  276.  
  277.             DESCRIPTION        OFFSET
  278.  
  279.             Region Size         00h
  280.  
  281.                Offset            04h
  282.  
  283.         Buffer ID      Segment/Selector  08h
  284.  
  285.           Physical Address        0Ch
  286.  
  287.  
  288. Region Size  is a  dword at offset 0.  It specifies the size
  289.      of the DMA region in bytes.
  290.  
  291. Offset and Segment/Selector are an fword pair at offset 04h.
  292.      They  specify   a    48-bit    segment:offset    pointer  for
  293.      virtual 8086  mode, or  a selector:offset    pointer  for
  294.      protected mode  programs.     Note  that  if  the  linear
  295.      address has  already been    determined then  you may set
  296.      the segment/selector  field to  0 and  place the linear
  297.      address in  the linear offset field.  It is possible to
  298.      specify 32-bit  offsets, even  with real  mode  segment
  299.      values; this makes it much easier for device drivers to
  300.      split up  DMA transfers, by simply modifying the offset
  301.      without having to modify the segment/selector.
  302.  
  303. Buffer ID  is a word at offset 0Ah.  This field is filled in
  304.      by the Request DMA Buffer service and possibly the Lock
  305.      DMA Region service.
  306.  
  307. Physical Address  is a    dword at  offset 0Ch.  This field is
  308.      filled in by the Lock DMA Region and Request DMA Buffer
  309.      services.
  310.  
  311. ============================================================
  312.  
  313.  Reserved Subfunctions
  314.  
  315.  
  316. Functions 00h,    01h and  0Dh through  0FFh are reserved.  If
  317. called they will return with the Carry flag set and AL = 0Fh
  318. (Function not supported).
  319.  
  320. Programmer's Notes
  321.  
  322.       None
  323.  
  324. ============================================================
  325.  
  326.  Get Version
  327.  
  328.  
  329. This service  returns the version of DMA services as well as
  330. information about the hardware, size of buffers, and support
  331. of automatic memory remapping.
  332.  
  333. To Call
  334.  
  335.      AH = 81h
  336.      AL = 02h
  337.      DX = Flags
  338.       All bits reserved and must be zero
  339.  
  340. Returns
  341.  
  342.      If function was successful:
  343.      Carry clear
  344.      AH =  Major specification    version # (binary, currently
  345.       1)
  346.      AL =  Minor specification    version # (binary, currently
  347.       0)
  348.      BX = Product number
  349.      CX = Product revision number
  350.      SI:DI =  Maximum DMA  buffer size    in bytes that can be
  351.       requested.
  352.      DX = Flags
  353.       Bit 0  = 1 if PC/XT bus architecture (DMA in first
  354.            meg only)
  355.       Bit 1  = 1  if physical  buffer/remap region is in
  356.            first meg
  357.       Bit 2 = 1 if automatic remap supported
  358.       Bit 3 = 1 if all memory physically contiguous
  359.       Other flags reserved and must be zero
  360.      If function was not successful:
  361.      Carry flag set
  362.      AL = Error code
  363.       10h = Reserved flag bits set in DX
  364.  
  365. Programmer's Notes
  366.  
  367.      o      The version numbers returned in AH and AL are used
  368.       to determine    the level of functionality supported
  369.       by the current implementation.  The current driver
  370.       will return AX=0100h.
  371.      o      Bit 3  of the  flag  word  will  only  be  set  in
  372.       environments that run in protected mode but do not
  373.       use paging,  such as    286 DOS extenders.  In these
  374.       environments, the  DMA services  are only provided
  375.       to convert  selector:offset linear  address  pairs
  376.       into physical addresses.
  377.  
  378. ============================================================
  379.  
  380.  Lock DMA Region
  381.  
  382.  
  383. This service  is used to determine if a target DMA region is
  384. in contiguous  physical memory.   If  it is contiguous, then
  385. this service  returns the  physical address of the region so
  386. that the  software can    program for  the DMA.    A locked DMA
  387. region must always be unlocked once the DMA is complete.
  388.  
  389. If the    DMA controller    has  memory  placement    restrictions
  390. (i.e. below  1Mb), then it can compare the returned physical
  391. address; if  the address  is not  suitable, then the program
  392. must unlock the region and request a DMA buffer.
  393.  
  394. Some implementations  of the  DMA services  will attempt  to
  395. remap pages  to force  the region  to be contiguous physical
  396. memory.  The caller can disable this behavior by setting bit
  397. 3 in  DX.   Normally, it  is faster  for a  device to  split
  398. transfers or  use a  DMA buffer instead of going through the
  399. remap process.
  400.  
  401. It  is     often    convenient   to  use  the  automatic  buffer
  402. allocation option  of this  service.   If the DMA region can
  403. not be    locked for  any reason then the service will attempt
  404. to allocate  a DMA  buffer.   If desired,  the data  in  the
  405. region will be automatically copied into the buffer.
  406.  
  407. To Call
  408.  
  409.      AH = 81h
  410.      AL = 03h
  411.      DX = Flags
  412.       Bit 1  = 1  if data  should be  copied into buffer
  413.            (ignored if bit 2 = 1)
  414.       Bit 2  = 1  if buffer  should not  be allocated if
  415.            region  is   not  contiguous   or  crosses  a
  416.            physical alignment boundary specified by bits
  417.            4 and 5
  418.       Bit 3  =  1  if  automatic  remap  should  not  be
  419.            attempted
  420.       Bit 4  = 1 if region must not cross a 64K physical
  421.            alignment boundary
  422.       Bit 5 = 1 if region must not cross a 128K physical
  423.            alignment boundary
  424.       All other bits reserved and must be zero
  425.      ES:DI = Pointer to DMA Descriptor Structure
  426.       The caller  must fill  in the  region size, linear
  427.       offset, and selector/segment fields before calling
  428.       this service
  429.  
  430. Returns
  431.  
  432.      If function was successful:
  433.      Carry flag clear
  434.      Memory is locked
  435.      Physical address  field of  DDS contains  the  starting
  436.       physical address of the region.
  437.      The  buffer  ID  field  will  contain  the  ID  of  the
  438.       allocated buffer or 0 if no buffer was allocated.
  439.  
  440.      If function was not successful:
  441.      Carry flag set
  442.      Memory is not locked
  443.      Region  size   field  of    DDS  contains    the  maximum
  444.       contiguous length in bytes.
  445.      AL = Error code
  446.       01h = Region specified was not contiguous memory
  447.       02h = Region crossed a physical alignment boundary
  448.       03h = Unable to lock pages (virtual memory systems
  449.            only)
  450.       05h = Region too large for buffer
  451.       06h = Buffer currently in use
  452.       07h = Invalid memory region
  453.       10h = Reserved flag bits set in DX
  454.  
  455. Programmer's Notes
  456.  
  457.      o      Memory is  locked on    a page    granular basis.    A
  458.       single page  can be  locked more  than once,    thus
  459.       allowing two    DMA regions  to overlap  on a single
  460.       page.   Page locking    is maintained  as  a  count.
  461.       Some systems    need  not  maintain  a    count  since
  462.       memory will never be discarded or moved.  In these
  463.       systems, Unlock DMA Region will never fail.
  464.      o      If  the  automatic  buffer  allocation  option  is
  465.       selected by  clearing bit  2 of  the flags  in DX,
  466.       then a  buffer will  be automatically allocated if
  467.       the region could not be locked.  If data should be
  468.       copied into the buffer for a memory read operation
  469.       then bit  1 of  the flags in DX should be set.  If
  470.       lock is  going to  fail and bit 2 is clear, but no
  471.       buffer is  supported, then the actual cause of the
  472.       error is  reported as  the error  message,  rather
  473.       than returning a buffer not available error (4).
  474.      o      You may  want to  wait in  a loop if this function
  475.       returns a  "Buffer in  use" error to allow another
  476.       device time  to release  the    buffer.    For    more
  477.       details refer to the documentation for Request DMA
  478.       Buffer on page 14.
  479.      o      The buffer  alignment  mask  should  be  used  for
  480.       devices  that   have    physical   memory   boundary
  481.       constraints.     For example, on an AT architecture,
  482.       the standard DMA controllers will "wrap" at 64K or
  483.       128K physical  boundaries.   If the DMA controller
  484.       being programmed has an alignment constraint, then
  485.       the applicable bit in DX should be set.
  486.  
  487. ===========================================================
  488.  
  489.  Unlock DMA Region
  490.  
  491.  
  492. Service to unlock a previously locked DMA region.
  493.  
  494. To Call
  495.  
  496.      AH = 81h
  497.      AL = 04h
  498.      DX = Flags
  499.       Bit 1 = 1 if data should be copied out of buffer
  500.       All other bits reserved and must be zero
  501.      ES:DI = Pointer to DMA Descriptor Structure
  502.       The caller  must fill in the region size, physical
  503.       address, and    buffer ID fields before calling this
  504.       service (Usually the caller simply passes the same
  505.       structure which  was filled in by the call to Lock
  506.       DMA Region).
  507.  
  508. Returns
  509.  
  510.      If function was successful:
  511.      Carry flag clear
  512.      Memory is unlocked or no count maintained
  513.  
  514.      If function was not successful:
  515.      Carry flag set
  516.      All memory remains locked
  517.      AL = Error code
  518.       08h = Memory was not locked
  519.       0Ah = Invalid Buffer ID
  520.       10h = Reserved flag bits set in DX
  521.  
  522. Programmer's Notes
  523.  
  524.      o      This service    releases a  DMA buffer,  if one  was
  525.       allocated by    the Lock  DMA Region call (if Buffer
  526.       ID is non-zero in the DDS), so any data in it will
  527.       be lost.   If  the DMA transfer was a memory write
  528.       operation, then  setting bit    1 in  the  DX  flags
  529.       parameter will  copy the  data out  of the  buffer
  530.       before it is released.
  531.  
  532. ============================================================
  533.  
  534.  Scatter/Gather Lock Region
  535.  
  536.  
  537. This service  is provided  so  that  hardware  devices    that
  538. support automatic  scatter/gather can  determine the  actual
  539. physical regions  of and lock an entire linear address range
  540. in one    call.  Device drivers that break up DMA requests may
  541. also want  to use this service instead of repeatedly calling
  542. lock DMA region.
  543.  
  544. To Call
  545.  
  546.      AH = 81h
  547.      AL = 05h
  548.      DX = Flags
  549.       Bit 6  = 1  if EDDS  should be  returned with page
  550.            table entries
  551.       Bit 7  = 1 if only present pages should be locked,
  552.            not present  pages will    be identified  as  a
  553.            page table  entry of  0 (bit 7 is ignored, if
  554.            bit 6 = 0)
  555.       All other bits reserved and must be zero
  556.      ES:DI = Pointer to one of the following extended DDS:
  557.  
  558.      If option    bit 6  = 0  then return  Extended DDS (EDDS)
  559.       with table  of physical  regions (address and size
  560.       pairs):
  561.  
  562.  
  563.             DESCRIPTION         OFFSET
  564.  
  565.         Region Size in Bytes         00h
  566.  
  567.            Linear Offset         04h
  568.  
  569.           Reserved      Segment/Selector   08h
  570.  
  571.            # Used          # Avail         0Ch
  572.  
  573.          Region 0 Physical Address         10h
  574.  
  575.            Region 0 Size in Bytes         14h
  576.  
  577.          Region 1 Physical Address         18h
  578.  
  579.            Region 1 Size in Bytes         1Ch
  580.  
  581.                . . .            . . .
  582.  
  583.                . . .            . . .
  584.  
  585.          Region n Physical Address       10h+n*8
  586.  
  587.  
  588.  
  589.  
  590.    Region n Size in Bytes      14h+n*8
  591.  
  592.      If option bit 6 = 1 then return Extended DDS with table
  593.       of page table entries (1 entry per 4Kb page in the
  594.       same format as 80386 page table entries):
  595.  
  596.  
  597.             DESCRIPTION         OFFSET
  598.  
  599.         Region Size in Bytes         00h
  600.  
  601.            Linear Offset         04h
  602.  
  603.           Reserved      Segment/Selector   08h
  604.  
  605.            # Used          # Avail         0Ch
  606.  
  607.          Page table entry 0         10h
  608.  
  609.          Page table entry 1         14h
  610.  
  611.                . . .            . . .
  612.  
  613.                . . .            . . .
  614.  
  615.          Page table entry n       10h+n*4
  616.  
  617.  
  618.      Each page table entry contains the physical page number
  619.       in the  upper 20  bits; the lower 12 bits are flag
  620.       bits:
  621.  
  622.            Bit 0 = 1 if the page is present and locked
  623.            Bits 1..11 are reserved and will be zero
  624.  
  625.      If option    bit 7 = 1, then pages in the region which do
  626.       not have  a physical    page   assigned will  have a
  627.       page table  entry of    0, and will not be locked by
  628.       this call.
  629.  
  630.      The caller must fill in the region size, linear segment
  631.       and offset,  and number  available field.   The  #
  632.       Avail  field    specifies  the    number    of  physical
  633.       regions/page table entries in the data structure.
  634.  
  635. Returns
  636.  
  637.      If function was successful:
  638.      Carry flag is clear
  639.      The #  used field    will contain  the  number  of  table
  640.       entires   filled    in   with   physical   regions
  641.       information.
  642.      If bit  6 of  option flags was 1 (page table copy) then
  643.       low twelve  bits of  BX =  Offset in first page to
  644.       start of region (high 4 bits will be zero).
  645.  
  646.      If function was not successful:
  647.      Carry flag is set
  648.      Memory is not locked
  649.      Region size field of DDS contains the maximum length in
  650.       bytes that  can be locked and described in the DDS
  651.       table.
  652.      Table entries are undefined.
  653.      AL = Error code
  654.       03h = Unable to lock pages
  655.       07h = Invalid memory region
  656.       09h = Number of physical regions/pages was greater
  657.            than table  length (The    #  used  field    will
  658.            contain the number of table entries needed to
  659.            describe the DMA region.)
  660.       10h = Reserved flag bits set in DX
  661.  
  662. Programmer's Notes
  663.  
  664.      o      The maximum  number of  physical regions  required
  665.       can be computed as:
  666.  
  667.       (Linear Address AND 0FFFh) + Region Size + 0FFFh
  668.                 1000h
  669.  
  670. ============================================================
  671.  
  672.  Scatter/Gather Unlock Region
  673.  
  674.  
  675. This service  is used  to unlock a region that was locked by
  676. the Scatter/Gather Lock Region service.
  677.  
  678. To Call
  679.  
  680.      AH = 81h
  681.      AL = 06h
  682.      DX = Flags
  683.       Bit 6 = 1 if EDDS contains page table entries
  684.       Bit 7  = 1  if EDDS may contain not present pages,
  685.            not present  pages are  identified as  a page
  686.            table entry  of 0 (bit 7 is ignored, if bit 6
  687.            = 0)
  688.       All other bits reserved and must be zero
  689.      ES:DI =  Pointer to the extended DDS that was used when
  690.       calling the Scatter/Gather Lock Region service.
  691.  
  692. Returns
  693.  
  694.      If function was successful:
  695.      Carry flag is clear
  696.      Memory is unlocked
  697.  
  698.      If function was not successful:
  699.      Carry flag is set
  700.      AL = Error code
  701.       08h = Memory was not locked
  702.       10h = Reserved flag bits set in DX
  703.  
  704. Programmer's Notes
  705.  
  706.      o      Only    the   region   size,   linear    offset     and
  707.       segment/selector fields  are used.  Therefore, the
  708.       physical address/size or page table entries do not
  709.       need to  be maintained,  unless bits    6 and 7 were
  710.       set in  DX in  the  call  to    Scatter/Gather    Lock
  711.       Region.   If this  special form of page table lock
  712.       was used,  then the  table is required so that the
  713.       correct pages can be unlocked.
  714.  
  715. ============================================================
  716.  
  717.  Request DMA Buffer
  718.  
  719.  
  720. Buffered DMA  requires a  device driver  to  request  a  DMA
  721. buffer,  copy  data  into  the    buffer    (if  a    memory    read
  722. operation  is    required),  start   the  DMA  transfer    with
  723. programmed I/O, copy data from the buffer (if a memory write
  724. operation is  required), and  release the  DMA buffer.     The
  725. data must be copied to/from the DMA buffer before release is
  726. called and  the physical  address  of  the  buffer  must  be
  727. considered invalid as soon as release is called.
  728.  
  729. To Call
  730.  
  731.      AH = 81h
  732.      AL = 07h
  733.      DX = Flags
  734.       Bit 1 = 1 if data should be copied into buffer
  735.       All other bits reserved and must be zero
  736.      ES:DI = Pointer to DMA Descriptor Structure
  737.       The caller must fill in the region size field.  If
  738.       automatic copy  is selected  (bit 1  set) then the
  739.       caller must also fill in the linear region segment
  740.       and region offset fields.
  741.  
  742. Returns
  743.  
  744.      If function was successful:
  745.      Carry flag clear
  746.      The physical  address field  of the  DDS  contains  the
  747.       starting physical address of the buffer.
  748.      The region size field specifies the size of the buffer.
  749.      The buffer  ID field  contains the  ID of the allocated
  750.       buffer
  751.      If automatic  copy was  selected then  data was  copied
  752.       into the buffer.
  753.  
  754.      If function was not successful:
  755.      Carry flag set
  756.      AL = Error code
  757.       04h = No buffer available
  758.       05h = Region too large for buffer
  759.       06h = Buffer currently in use
  760.       07h = Invalid memory region
  761.       10h = Reserved flag bits set in DX
  762.  
  763. Programmer's Notes
  764.  
  765.      o      Under Windows/386 devices will often want to enter
  766.       a Windows/386  critical section to prevent running
  767.       other VMs while they are using a DMA buffer.
  768.      o      If the  buffer is in use you may want to spin in a
  769.       loop    with   interrupts  enabled   and  repeatedly
  770.       attempt to  allocate the  buffer to  allow another
  771.       device time to complete its DMA.
  772.      o      Your device driver must either spin in a wait loop
  773.       until  the   DMA  is    complete  and  then  release
  774.       ownership  of   the  buffer  or  it  must  release
  775.       ownership of the buffer from a hardware interrupt.
  776.       Releasing ownership  from hardware interrupts will
  777.       allow other  devices to  wait for the buffer to be
  778.       freed as described above.
  779.  
  780.  
  781. ============================================================
  782.  
  783.  Release DMA Buffer
  784.  
  785.  
  786. Releases a  DMA buffer    that was  previously requested.  The
  787. physical address should be considered invalid following this
  788. call.
  789.  
  790. To Call
  791.  
  792.      AH = 81h
  793.      AL = 08h
  794.      DX = Flags
  795.       Bit 1 = 1 if data should be copied out of buffer
  796.       All other bits reserved and must be zero
  797.      ES:DI = Pointer to DMA Descriptor Structure
  798.       The caller must fill in the buffer ID field of the
  799.       DDS before calling this service.
  800.  
  801. Returns
  802.  
  803.      If function was successful:
  804.      Carry flag clear
  805.  
  806.      If function was not successful:
  807.      Carry flag set
  808.      AL = Error code
  809.       0Ah = Invalid buffer ID
  810.       10h = Reserved flag bits set in DX
  811.  
  812. Programmer's Notes
  813.  
  814.      None
  815.  
  816. ============================================================
  817.  
  818.  Copy Into DMA Buffer
  819.  
  820.  
  821. Copy data  from the  user's buffer  into the  DMA buffer  to
  822. prepare for a memory read DMA transfer.
  823.  
  824. To Call
  825.  
  826.      AH = 81h
  827.      AL = 09h
  828.      DX = Flags
  829.       All bits reserved and must be zero
  830.      ES:DI = Pointer to DMA Descriptor Structure
  831.       The caller  must fill  in the buffer ID field, the
  832.       fword  segment/selector:linear  offset  fields  to
  833.       specify the  source address  for the copy, and the
  834.       region size.
  835.      BX:CX = Starting offset in DMA buffer to copy
  836.  
  837.      The size  field of  the DDS  determines the  number  of
  838.       bytes that will be copied
  839.  
  840. Returns
  841.  
  842.      If function was successful:
  843.      Carry flag clear
  844.  
  845.      If function was not successful:
  846.      Carry flag set
  847.      AL = Error code
  848.       0Ah = Invalid buffer ID
  849.       0Bh =  Copy count+offset  is greater    than  buffer
  850.            size
  851.       10h = Reserved flag bits set in DX
  852.  
  853. ============================================================
  854.  
  855.  Copy Out Of DMA Buffer
  856.  
  857.  
  858. Copy data from the DMA buffer into the user's buffer after a
  859. memory write DMA transfer.
  860.  
  861. To Call
  862.  
  863.      AH = 81h
  864.      AL = 0Ah
  865.      DX = Flags
  866.       All bits reserved and must be zero
  867.      ES:DI = Pointer to DMA Descriptor Structure
  868.       The caller  must fill  in the buffer ID field, the
  869.       fword  segment/selector:linear  offset  fields  to
  870.       specify the  destination address for the copy, and
  871.       the region size.
  872.      BX:CX = Starting offset in DMA buffer to copy
  873.  
  874.      The size  field of  the DDS  determines the  number  of
  875.       bytes that will be copied
  876.  
  877. Returns
  878.  
  879.      If function was successful:
  880.      Carry flag clear
  881.  
  882.      If function was not successful:
  883.      Carry flag set
  884.      AL = Error code
  885.       0Ah = Invalid buffer ID
  886.       0Bh =  Copy count+offset  is greater    than  buffer
  887.            size
  888.       10h = Reserved flag bits set in DX
  889.  
  890. ============================================================
  891.  
  892.  Disable DMA Translation
  893.  
  894. Environments that  support the    DMA services  will trap  the
  895. standard DMA  I/O ports  and attempt  to remap    the client's
  896. addresses, which  are assumed to be linear addresses, to the
  897. appropriate physical  address.     However, programs which use
  898. the DMA  services to determine the physical address of their
  899. DMA region  must disable the automatic remapping of standard
  900. DMA by calling this function.
  901.  
  902. A disable  count is  maintained so  you must call Enable DMA
  903. Translation for  every call to this service before automatic
  904. DMA translation will be enabled.
  905.  
  906. To Call
  907.  
  908.      AH = 81h
  909.      AL = 0Bh
  910.      BX = DMA channel number
  911.      DX = Flags
  912.       All bits reserved and must be zero
  913.  
  914. Returns
  915.  
  916.      If function was successful:
  917.      Carry flag clear
  918.  
  919.      If function was not successful:
  920.      Carry flag set
  921.      AL = Error code
  922.       0Ch = Invalid DMA channel number
  923.       0Dh = Disable count overflow
  924.       10h = Reserved flag bits set in DX
  925.  
  926. Programmer's Notes
  927.  
  928.      None
  929.  
  930. ============================================================
  931.  
  932.  Enable DMA Translation
  933.  
  934.  
  935. This service  must  be    called    after  calling    Disable  DMA
  936. Translation to re-enable automatic DMA remapping.
  937.  
  938. A disable  count is maintained so you must call this service
  939. for every  call to  Disable DMA Translation before automatic
  940. DMA translation will be enabled.
  941.  
  942. To Call
  943.  
  944.      AH = 81h
  945.      AL = 0Ch
  946.      BX = DMA channel number
  947.      DX = Flags
  948.       All bits reserved and must be zero
  949.  
  950. Returns
  951.  
  952.      If function was successful:
  953.      Carry flag clear
  954.      If disable count decremented to 0, then Zero flag set
  955.  
  956.      If function was not successful:
  957.      Carry flag set
  958.      AL = Error code
  959.       0Ch = Invalid DMA channel number
  960.       0Eh =  Disable count underflow (was not previously
  961.            disabled).  Count not changed.
  962.       10h = Reserved flag bits set in DX
  963.  
  964. Programmer's Notes
  965.  
  966.      None
  967.  
  968.  
  969.       SUMMARY OF ERROR CODES AND OPTION FLAGS
  970.  
  971.  
  972.  
  973. Error codes:
  974.  
  975.      01h = Region not in contiguous memory
  976.      02h = Region crossed a physical alignment boundary
  977.      03h = Unable to lock pages
  978.      04h = No buffer available
  979.      05h = Region too large for buffer
  980.      06h = Buffer currently in use
  981.      07h = Invalid memory region
  982.      08h = Region was not locked
  983.      09h =  Number of  physical pages was greater than table
  984.       length
  985.      0Ah = Invalid buffer ID
  986.      0Bh = Copy out of buffer range
  987.      0Ch = Invalid DMA channel number
  988.      0Dh = Disable count overflow
  989.      0Eh = Disable count underflow
  990.      0Fh = Function not supported
  991.      10h = Reserved flag bits set in DX
  992.  
  993.  
  994. Flags:
  995.  
  996.      Bit 1 = Automatically copy to/from buffer
  997.      Bit 2 = Disable automatic buffer allocation
  998.      Bit 3 = Disable automatic remap feature
  999.      Bit 4  = Region  must not    cross 64K physical alignment
  1000.       boundary
  1001.      Bit 5  = Region  must not cross 128K physical alignment
  1002.       boundary
  1003.      Bit 6 = Copy page table for scatter gather remap
  1004.