Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
6.8 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * SYS_DMA.C
  4. *
  5. * This module contains helper routines used by the FTK to initialise
  6. * DMA access to adapters.
  7. *
  8. * Copyright (c) Madge Networks Ltd 1991-1994
  9. *
  10. * COMPANY CONFIDENTIAL
  11. *
  12. * Created: MF
  13. * Major modifications: PBA 21/06/1994
  14. *
  15. ****************************************************************************/
  16. #include <ndis.h>
  17. #include "ftk_defs.h"
  18. #include "ftk_extr.h"
  19. #include "ndismod.h"
  20. /*---------------------------------------------------------------------------
  21. |
  22. | DMA General Note
  23. | ----------------
  24. |
  25. | On an IBM compatible PC/AT machine, DMA is controlled by Programmable
  26. | DMA Controller 8237 chips. On AT machines there are two 8237 DMA
  27. | controllers. The primary controller handles DMA channels 0-3, the
  28. | secondary controller handles channels 4-7.
  29. |
  30. | The FTK is interested in three registers on each controller. These are
  31. | the mode register for setting the DMA mode for a given channel, the
  32. | mask register used for enabling/disabling a DMA channel, and the status
  33. | register for seeing what DMA channel requests have been generated.
  34. |
  35. ---------------------------------------------------------------------------*/
  36. //
  37. // IO ports for status, mask and mode registers on primary DMA controller
  38. //
  39. #define DMA_STATUS_PRIMARY_8237 0x08
  40. #define DMA_MASK_PRIMARY_8237 0x0A
  41. #define DMA_MODE_PRIMARY_8237 0x0B
  42. //
  43. // IO ports for status, mask and mode registers on secondary DMA controller
  44. //
  45. #define DMA_STATUS_SECONDARY_8237 0x0D0
  46. #define DMA_MASK_SECONDARY_8237 0x0D4
  47. #define DMA_MODE_SECONDARY_8237 0x0D6
  48. //
  49. // Set cascade mode code (sent to mode register along with DMA channel)
  50. //
  51. #define DMA_CASCADE_MODE_8237 0x0C0
  52. //
  53. // Disable DMA channel code (sent to mask register along with DMA channel)
  54. //
  55. #define DMA_DISABLE_MASK_8237 0x04
  56. /****************************************************************************
  57. *
  58. * Function - sys_enable_dma_channel
  59. *
  60. * Parameters - adapter_handle -> FTK adapter handle.
  61. * dma_channel -> The DMA channel number.
  62. *
  63. * Purpose - Initialise a DMA channel.
  64. *
  65. * Returns - TRUE on success or FALSE on failure.
  66. *
  67. * Notes:
  68. *
  69. * With the NDIS3 driver the dma channel is enabled by the underlying
  70. * operating system. We pass information about our adapter in the
  71. * NDIS_ADAPTER_INFORMATION structure, including whether its a
  72. * BusMasterDma card --- by setting the AdapterInformation.Master flag
  73. * in MDGNT.c.
  74. *
  75. * So eventually this routine should be null and just return TRUE.
  76. *
  77. * Upto NT build 438, there is a problem with the AdapterInformation.Master
  78. * flag. Setting it does not enable the DMA channel on certain ISA/AT
  79. * platforms. Therefore the following code has been included such that we
  80. * explicitly enable the DMA channel.
  81. *
  82. * The DMA channel has been specified in the AdapterInformation structure
  83. * passed by the MAC driver to NdisRegisterAdapter()
  84. *
  85. ****************************************************************************/
  86. WBOOLEAN
  87. sys_enable_dma_channel(ADAPTER_HANDLE adapter_handle, WORD dma_channel);
  88. #pragma FTK_INIT_FUNCTION(sys_enable_dma_channel)
  89. WBOOLEAN
  90. sys_enable_dma_channel(ADAPTER_HANDLE adapter_handle, WORD dma_channel)
  91. {
  92. #ifdef _M_IX86
  93. if (dma_channel < 4)
  94. {
  95. //
  96. // Program up primary 8237. Write local DMA channel with cascade
  97. // mode to mode register. Write local DMA channel to mask register
  98. // to enable it.
  99. //
  100. //
  101. // (dma_channel + DMA_CASCADE_MODE_8237) -> DMA_MODE_PRIMARY_8237
  102. //
  103. sys_outsb(
  104. adapter_handle,
  105. (WORD) DMA_MODE_PRIMARY_8237,
  106. (BYTE) (dma_channel + DMA_CASCADE_MODE_8237)
  107. );
  108. //
  109. // (dma_channel) -> DMA_MASK_PRIMARY_8237
  110. //
  111. sys_outsb(
  112. adapter_handle,
  113. (WORD) DMA_MASK_PRIMARY_8237,
  114. (BYTE) dma_channel
  115. );
  116. }
  117. else
  118. {
  119. //
  120. // Program up secondary 8237. Get local DMA channel by DMA-4.
  121. // Write local DMA channel with cascade mode to mode register.
  122. // Write local DMA channel to mask register to enable it.
  123. //
  124. dma_channel = dma_channel - 4;
  125. //
  126. // (dma_channel + DMA_CASCADE_MODE_8237) -> DMA_MODE_SECONDARY_8237
  127. //
  128. sys_outsb(
  129. adapter_handle,
  130. (WORD) DMA_MODE_SECONDARY_8237,
  131. (BYTE)(dma_channel + DMA_CASCADE_MODE_8237)
  132. );
  133. //
  134. // (dma_channel) -> DMA_MASK_SECONDARY_8237
  135. //
  136. sys_outsb(
  137. adapter_handle,
  138. (WORD) DMA_MASK_SECONDARY_8237,
  139. (BYTE) dma_channel
  140. );
  141. }
  142. #endif
  143. return TRUE;
  144. }
  145. /****************************************************************************
  146. *
  147. * Function - sys_disable_dma_channel
  148. *
  149. * Parameters - adapter_handle -> FTK adapter handle.
  150. * dma_channel -> The DMA channel number.
  151. *
  152. * Purpose - De-initialise a DMA channel.
  153. *
  154. * Returns - Nothing.
  155. *
  156. * Notes:
  157. *
  158. * Upto NT build 438, there is a problem with the AdapterInformation.Master
  159. * flag. Setting it does not enable the DMA channel on certain ISA/AT
  160. * platforms. Therefore the code in sys_enable_dma_channel() above, has been
  161. * included such that we explicitly enable the DMA channel.
  162. *
  163. * Eventually, the Operating system will do this for us. And will also disable
  164. * the DMA channel when the driver is unloaded.
  165. *
  166. * Therefore, I have not added code to explicitly disable DMA channel.
  167. *
  168. *
  169. * However, if we do not disable the channel certain ISA platforms hang
  170. * on shutdown. (pba 25/5/1994)
  171. *
  172. ***************************************************************************/
  173. void
  174. sys_disable_dma_channel(ADAPTER_HANDLE adapter_handle, WORD dma_channel)
  175. {
  176. #ifdef _M_IX86
  177. if (dma_channel < 4)
  178. {
  179. sys_outsb(
  180. adapter_handle,
  181. (WORD) DMA_MASK_PRIMARY_8237,
  182. (BYTE) (DMA_DISABLE_MASK_8237 + dma_channel)
  183. );
  184. }
  185. else
  186. {
  187. sys_outsb(
  188. adapter_handle,
  189. (WORD)DMA_MASK_SECONDARY_8237,
  190. (BYTE)(DMA_DISABLE_MASK_8237 + (dma_channel - 4))
  191. );
  192. }
  193. #endif
  194. }
  195. /******** End of SYS_DMA.C *************************************************/