Leaked source code of windows server 2003
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.

1052 lines
28 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. fdc_data.h
  5. Abstract:
  6. This file includes data and hardware declarations for the NEC PD765
  7. (aka AT, ISA, and ix86) and Intel 82077 (aka MIPS) floppy driver for
  8. NT.
  9. Author:
  10. Environment:
  11. Kernel mode only.
  12. Notes:
  13. --*/
  14. #if DBG
  15. //
  16. // For checked kernels, define a macro to print out informational
  17. // messages.
  18. //
  19. // FdcDebug is normally 0. At compile-time or at run-time, it can be
  20. // set to some bit pattern for increasingly detailed messages.
  21. //
  22. // Big, nasty errors are noted with DBGP. Errors that might be
  23. // recoverable are handled by the WARN bit. More information on
  24. // unusual but possibly normal happenings are handled by the INFO bit.
  25. // And finally, boring details such as routines entered and register
  26. // dumps are handled by the SHOW bit.
  27. //
  28. #define FDCDBGP ((ULONG)0x00000001)
  29. #define FDCWARN ((ULONG)0x00000002)
  30. #define FDCINFO ((ULONG)0x00000004)
  31. #define FDCSHOW ((ULONG)0x00000008)
  32. #define FDCIRPPATH ((ULONG)0x00000010)
  33. #define FDCFORMAT ((ULONG)0x00000020)
  34. #define FDCSTATUS ((ULONG)0x00000040)
  35. extern ULONG FdcDebugLevel;
  36. #define FdcDump(LEVEL,STRING) \
  37. do { \
  38. if (FdcDebugLevel & LEVEL) { \
  39. DbgPrint STRING; \
  40. } \
  41. } while (0)
  42. #else
  43. #define FdcDump(LEVEL,STRING) do {NOTHING;} while (0)
  44. #endif
  45. //
  46. // Macros to access the controller. Note that the *_PORT_UCHAR macros
  47. // work on all machines, whether the I/O ports are separate or in
  48. // memory space.
  49. //
  50. #define READ_CONTROLLER( Address ) \
  51. READ_PORT_UCHAR( ( PUCHAR )Address )
  52. #define WRITE_CONTROLLER( Address, Value ) \
  53. WRITE_PORT_UCHAR( ( PUCHAR )Address, ( UCHAR )Value )
  54. //
  55. // Retry counts -
  56. //
  57. // When moving a byte to/from the FIFO, we sit in a tight loop for a while
  58. // waiting for the controller to become ready. The number of times through
  59. // the loop is controlled by FIFO_TIGHTLOOP_RETRY_COUNT. When that count
  60. // expires, we'll wait in 10ms increments. FIFO_DELAY_RETRY_COUNT controls
  61. // how many times we wait.
  62. //
  63. // The ISR_SENSE_RETRY_COUNT is the maximum number of 1 microsecond
  64. // stalls that the ISR will do waiting for the controller to accept
  65. // a SENSE INTERRUPT command. We do this because there is a hardware
  66. // quirk in at least the NCR 8 processor machine where it can take
  67. // up to 50 microseconds to accept the command.
  68. //
  69. // When attempting I/O, we may run into many different errors. The
  70. // hardware retries things 8 times invisibly. If the hardware reports
  71. // any type of error, we will recalibrate and retry the operation
  72. // up to RECALIBRATE_RETRY_COUNT times. When this expires, we check to
  73. // see if there's an overrun - if so, the DMA is probably being hogged
  74. // by a higher priority device, so we repeat the earlier loop up to
  75. // OVERRUN_RETRY_COUNT times.
  76. //
  77. // Any packet that is about to be returned with an error caused by an
  78. // unexpected hardware error or state will be restarted from the very
  79. // beginning after resetting the hardware HARDWARE_RESET_RETRY_COUNT
  80. // times.
  81. //
  82. #define FIFO_TIGHTLOOP_RETRY_COUNT 500
  83. #define FIFO_ISR_TIGHTLOOP_RETRY_COUNT 25
  84. #define ISR_SENSE_RETRY_COUNT 50
  85. #define FIFO_DELAY_RETRY_COUNT 5
  86. #define RECALIBRATE_RETRY_COUNT 3
  87. #define OVERRUN_RETRY_COUNT 1
  88. #define HARDWARE_RESET_RETRY_COUNT 2
  89. #define FLOPPY_RESET_ISR_THRESHOLD 20
  90. #define RQM_READY_RETRY_COUNT 100
  91. #define ONE_SECOND (10 * 1000 * 1000) // 100ns increments
  92. #define CANCEL_TIMER -1
  93. #define START_TIMER (IsNEC_98 ? 15 : 9)
  94. #define EXPIRED_TIMER 0
  95. #define RESET_NOT_RESETTING 0
  96. #define RESET_DRIVE_RESETTING 1
  97. //
  98. // Need some maximum size values so that we can appropriately set up the DMA
  99. // channels
  100. //
  101. #define MAX_BYTES_PER_SECTOR (IsNEC_98 ? 1024 : 512)
  102. #define MAX_SECTORS_PER_TRACK 36
  103. //
  104. // Boot Configuration Information
  105. //
  106. //
  107. // Define the maximum number of controllers and floppies per controller
  108. // that this driver will support.
  109. //
  110. // The number of floppies per controller is fixed at 4, since the
  111. // controllers don't have enough bits to select more than that (and
  112. // actually, many controllers will only support 2). The number of
  113. // controllers per machine is arbitrary; 3 should be more than enough.
  114. //
  115. #define MAXIMUM_CONTROLLERS_PER_MACHINE 3
  116. #define MAXIMUM_DISKETTES_PER_CONTROLLER 4
  117. //
  118. // Floppy register structure. The base address of the controller is
  119. // passed in by configuration management. Note that this is the 82077
  120. // structure, which is a superset of the PD765 structure. Not all of
  121. // the registers are used.
  122. //
  123. typedef union _CONTROLLER {
  124. struct {
  125. PUCHAR StatusA;
  126. PUCHAR StatusB;
  127. PUCHAR DriveControl;
  128. PUCHAR Tape;
  129. PUCHAR Status;
  130. PUCHAR Fifo;
  131. PUCHAR Reserved;
  132. union {
  133. PUCHAR DataRate;
  134. PUCHAR DiskChange;
  135. } DRDC;
  136. PUCHAR ModeChange; // for NEC98 : 0xbe
  137. PUCHAR ModeChangeEx; // for NEC98 : 0x4be
  138. };
  139. PUCHAR Address[8];
  140. } CONTROLLER, *PCONTROLLER;
  141. //
  142. // Io Port address information structure. This structure is used to save
  143. // information about ioport addresses as it is collected from a resource
  144. // requirements list.
  145. //
  146. typedef struct _IO_PORT_INFO {
  147. LARGE_INTEGER BaseAddress;
  148. UCHAR Map;
  149. LIST_ENTRY ListEntry;
  150. } IO_PORT_INFO, *PIO_PORT_INFO;
  151. //
  152. // Parameter fields passed to the CONFIGURE command.
  153. //
  154. #define COMMND_CONFIGURE_IMPLIED_SEEKS 0x40
  155. #define COMMND_CONFIGURE_FIFO_THRESHOLD 0x0F
  156. #define COMMND_CONFIGURE_DISABLE_FIFO 0x20
  157. #define COMMND_CONFIGURE_DISABLE_POLLING 0x10
  158. //
  159. // Write Enable bit for PERPENDICULAR MODE command.
  160. //
  161. #define COMMND_PERPENDICULAR_MODE_OW 0x80
  162. //
  163. // The command table is used by FlIssueCommand() to determine how many
  164. // bytes to get and receive, and whether or not to wait for an interrupt.
  165. // Some commands have extra bits; COMMAND_MASK takes these off.
  166. // FirstResultByte indicates whether the command has a result stage
  167. // or not; if so, it's 1 because the ISR read the 1st byte, and
  168. // NumberOfResultBytes is 1 less than expected. If not, it's 0 and
  169. // NumberOfResultBytes is 2, since the ISR will have issued a SENSE
  170. // INTERRUPT STATUS command.
  171. //
  172. #define COMMAND_MASK 0x1f
  173. #define FDC_NO_DATA 0x00
  174. #define FDC_READ_DATA 0x01
  175. #define FDC_WRITE_DATA 0x02
  176. typedef struct _COMMAND_TABLE {
  177. UCHAR OpCode;
  178. UCHAR NumberOfParameters;
  179. UCHAR FirstResultByte;
  180. UCHAR NumberOfResultBytes;
  181. BOOLEAN InterruptExpected;
  182. BOOLEAN AlwaysImplemented;
  183. UCHAR DataTransfer;
  184. } COMMAND_TABLE;
  185. //
  186. // Bits in the DRIVE_CONTROL register.
  187. //
  188. #define DRVCTL_RESET 0x00
  189. #define DRVCTL_ENABLE_CONTROLLER (IsNEC_98 ? 0x80 : 0x04)
  190. #define DRVCTL_ENABLE_DMA_AND_INTERRUPTS (IsNEC_98 ? 0x10 : 0x08)
  191. #define DRVCTL_DRIVE_0 0x10
  192. #define DRVCTL_DRIVE_1 0x21
  193. #define DRVCTL_DRIVE_2 0x42
  194. #define DRVCTL_DRIVE_3 0x83
  195. #define DRVCTL_DRIVE_MASK 0x03
  196. #define DRVCTL_MOTOR_MASK (IsNEC_98 ? 0x08 : 0xf0)
  197. #define DRVCTL_HD_BIT 0x20 // for NEC98
  198. #define DRVCTL_AI_ENABLE 0x20 // for NEC98. Indicate AI enable bit.
  199. //
  200. // Bits in the STATUS register.
  201. //
  202. #define STATUS_DRIVE_0_BUSY 0x01
  203. #define STATUS_DRIVE_1_BUSY 0x02
  204. #define STATUS_DRIVE_2_BUSY 0x04
  205. #define STATUS_DRIVE_3_BUSY 0x08
  206. #define STATUS_CONTROLLER_BUSY 0x10
  207. #define STATUS_DMA_UNUSED 0x20
  208. #define STATUS_DIRECTION_READ 0x40
  209. #define STATUS_DATA_REQUEST 0x80
  210. #define STATUS_IO_READY_MASK 0xc0
  211. #define STATUS_READ_READY 0xc0
  212. #define STATUS_WRITE_READY 0x80
  213. #define STATUS_IO_READY_MASK1 0x80 // for NEC98.
  214. #define STATUS_RQM_READY 0x80 // for NEC98.
  215. //
  216. // Bits in the DATA_RATE register.
  217. //
  218. #define DATART_0125 0x03
  219. #define DATART_0250 0x02
  220. #define DATART_0300 0x01
  221. #define DATART_0500 0x00
  222. #define DATART_1000 0x03
  223. #define DATART_RESERVED 0xfc
  224. //
  225. // Bits in the DISK_CHANGE register.
  226. //
  227. #define DSKCHG_RESERVED 0x7f
  228. #define DSKCHG_DISKETTE_REMOVED 0x80
  229. //
  230. // Bits in status register 0.
  231. //
  232. #define STREG0_DRIVE_0 0x00
  233. #define STREG0_DRIVE_1 0x01
  234. #define STREG0_DRIVE_2 0x02
  235. #define STREG0_DRIVE_3 0x03
  236. #define STREG0_HEAD 0x04
  237. #define STREG0_DRIVE_NOT_READY 0x08
  238. #define STREG0_DRIVE_FAULT 0x10
  239. #define STREG0_SEEK_COMPLETE 0x20
  240. #define STREG0_END_NORMAL 0x00
  241. #define STREG0_END_ERROR 0x40
  242. #define STREG0_END_INVALID_COMMAND 0x80
  243. #define STREG0_END_DRIVE_NOT_READY 0xC0
  244. #define STREG0_END_MASK 0xC0
  245. //
  246. // Bits in status register 1.
  247. //
  248. #define STREG1_ID_NOT_FOUND 0x01
  249. #define STREG1_WRITE_PROTECTED 0x02
  250. #define STREG1_SECTOR_NOT_FOUND 0x04
  251. #define STREG1_RESERVED1 0x08
  252. #define STREG1_DATA_OVERRUN 0x10
  253. #define STREG1_CRC_ERROR 0x20
  254. #define STREG1_RESERVED2 0x40
  255. #define STREG1_END_OF_DISKETTE 0x80
  256. //
  257. // Bits in status register 2.
  258. //
  259. #define STREG2_SUCCESS 0x00
  260. #define STREG2_DATA_NOT_FOUND 0x01
  261. #define STREG2_BAD_CYLINDER 0x02
  262. #define STREG2_SCAN_FAIL 0x04
  263. #define STREG2_SCAN_EQUAL 0x08
  264. #define STREG2_WRONG_CYLINDER 0x10
  265. #define STREG2_CRC_ERROR 0x20
  266. #define STREG2_DELETED_DATA 0x40
  267. #define STREG2_RESERVED 0x80
  268. //
  269. // Bits in status register 3.
  270. //
  271. #define STREG3_DRIVE_0 0x00
  272. #define STREG3_DRIVE_1 0x01
  273. #define STREG3_DRIVE_2 0x02
  274. #define STREG3_DRIVE_3 0x03
  275. #define STREG3_HEAD 0x04
  276. #define STREG3_TWO_SIDED 0x08
  277. #define STREG3_TRACK_0 0x10
  278. #define STREG3_DRIVE_READY 0x20
  279. #define STREG3_WRITE_PROTECTED 0x40
  280. #define STREG3_DRIVE_FAULT 0x80
  281. #define VALID_NEC_FDC 0x90 // version number
  282. #define NSC_PRIMARY_VERSION 0x70 // National 8477 verion number
  283. #define NSC_MASK 0xF0 // mask for National version number
  284. #define INTEL_MASK 0xe0
  285. #define INTEL_44_PIN_VERSION 0x40
  286. #define INTEL_64_PIN_VERSION 0x00
  287. #define DMA_DIR_UNKNOWN 0xff /* The DMA direction is not currently known */
  288. #define DMA_WRITE 0 /* Program the DMA to write (FDC->DMA->RAM) */
  289. #define DMA_READ 1 /* Program the DMA to read (RAM->DMA->FDC) */
  290. //
  291. // Strings for PnP Identification.
  292. //
  293. #define FDC_FLOPPY_COMPATIBLE_IDS L"*PNP0700\0GenFloppyDisk\0\0"
  294. #define FDC_FLOPPY_COMPATIBLE_IDS_LENGTH 24 // NB wide characters.
  295. #define FDC_TAPE_COMPATIBLE_IDS L"QICPNP\0\0"
  296. #define FDC_TAPE_COMPATIBLE_IDS_LENGTH 8 // NB wide characters.
  297. #define FDC_CONTROLLER_COMPATIBLE_IDS L"*PNP0700\0\0"
  298. #define FDC_CONTROLLER_COMPATIBLE_IDS_LENGTH 10 // NB wide characters.
  299. //
  300. // Runtime device structures
  301. //
  302. //
  303. // There is one FDC_EXTENSION attached to the device object of each
  304. // floppy drive. Only data directly related to that drive (and the media
  305. // in it) is stored here; common data is in CONTROLLER_DATA. So the
  306. // FDC_EXTENSION has a pointer to the CONTROLLER_DATA.
  307. //
  308. typedef struct _FDC_EXTENSION_HEADER {
  309. //
  310. // A flag to indicate whether this is a FDO or a PDO
  311. //
  312. BOOLEAN IsFDO;
  313. //
  314. // A pointer to our own device object.
  315. //
  316. PDEVICE_OBJECT Self;
  317. } FDC_EXTENSION_HEADER, *PFDC_EXTENSION_HEADER;
  318. typedef enum _FDC_DEVICE_TYPE {
  319. FloppyControllerDevice,
  320. FloppyDiskDevice,
  321. FloppyTapeDevice
  322. } FDC_DEVICE_TYPE;
  323. typedef struct _FDC_PDO_EXTENSION {
  324. FDC_EXTENSION_HEADER;
  325. //
  326. // A pointer to the FDO that created us.
  327. //
  328. PDEVICE_OBJECT ParentFdo;
  329. //
  330. // The instance number for this PDO. Determined by the order of the
  331. // callbacks from IoQueryDeviceDescription.
  332. //
  333. USHORT Instance;
  334. //
  335. // The type of device this PDO supports. Currently disk or tape.
  336. //
  337. FDC_DEVICE_TYPE DeviceType;
  338. SHORT TapeVendorId;
  339. //
  340. // A flag that indicates whether this PDO is pending removal.
  341. //
  342. BOOLEAN Removed;
  343. //
  344. // This PDO's entry in its parent's list of related PDOs.
  345. //
  346. LIST_ENTRY PdoLink;
  347. //
  348. // The enumerated number of this specific device, as returned from
  349. // IoQueryDeviceDescription.
  350. //
  351. ULONG PeripheralNumber;
  352. PDEVICE_OBJECT TargetObject;
  353. } FDC_PDO_EXTENSION, *PFDC_PDO_EXTENSION;
  354. typedef struct _FDC_FDO_EXTENSION {
  355. FDC_EXTENSION_HEADER;
  356. //
  357. // A kernel resource for controlling access to the FDC.
  358. //
  359. ERESOURCE Resource;
  360. //
  361. // A pointer to the PDO to which this FDO is attached.
  362. //
  363. PDEVICE_OBJECT UnderlyingPDO;
  364. //
  365. // The top of the object stack to which this FDO is attached.
  366. //
  367. PDEVICE_OBJECT TargetObject;
  368. //
  369. // A list and count of PDOs that were created by this FDO.
  370. //
  371. LIST_ENTRY PDOs;
  372. ULONG NumPDOs;
  373. BOOLEAN Removed;
  374. ULONG OutstandingRequests;
  375. KEVENT RemoveEvent;
  376. BOOLEAN TapeEnumerationPending;
  377. KEVENT TapeEnumerationEvent;
  378. //
  379. // Some stuff for power management
  380. //
  381. LIST_ENTRY PowerQueue;
  382. KSPIN_LOCK PowerQueueSpinLock;
  383. KEVENT PowerEvent;
  384. SYSTEM_POWER_STATE CurrentPowerState;
  385. LARGE_INTEGER LastMotorSettleTime;
  386. BOOLEAN WakeUp;
  387. //
  388. // The bus number on which this physical device lives.
  389. //
  390. INTERFACE_TYPE BusType;
  391. ULONG BusNumber;
  392. ULONG ControllerNumber;
  393. BOOLEAN DeviceObjectInitialized;
  394. LARGE_INTEGER InterruptDelay;
  395. LARGE_INTEGER Minimum10msDelay;
  396. KEVENT InterruptEvent;
  397. LONG InterruptTimer;
  398. CCHAR ResettingController;
  399. KEVENT AllocateAdapterChannelEvent;
  400. LONG AdapterChannelRefCount;
  401. PKEVENT AcquireEvent;
  402. HANDLE AcquireEventHandle;
  403. KEVENT SynchEvent;
  404. KDPC LogErrorDpc;
  405. KDPC BufferTimerDpc;
  406. KTIMER BufferTimer;
  407. PKINTERRUPT InterruptObject;
  408. PVOID MapRegisterBase;
  409. PADAPTER_OBJECT AdapterObject;
  410. PDEVICE_OBJECT CurrentDeviceObject;
  411. PDRIVER_OBJECT DriverObject;
  412. CONTROLLER ControllerAddress;
  413. ULONG SpanOfControllerAddress;
  414. ULONG NumberOfMapRegisters;
  415. ULONG BuffersRequested;
  416. ULONG BufferCount;
  417. ULONG BufferSize;
  418. PTRANSFER_BUFFER TransferBuffers;
  419. ULONG IsrReentered;
  420. ULONG ControllerVector;
  421. KIRQL ControllerIrql;
  422. KINTERRUPT_MODE InterruptMode;
  423. KAFFINITY ProcessorMask;
  424. UCHAR FifoBuffer[10];
  425. BOOLEAN AllowInterruptProcessing;
  426. BOOLEAN SharableVector;
  427. BOOLEAN SaveFloatState;
  428. BOOLEAN HardwareFailed;
  429. BOOLEAN CommandHasResultPhase;
  430. BOOLEAN ControllerConfigurable;
  431. BOOLEAN MappedControllerAddress;
  432. BOOLEAN CurrentInterrupt;
  433. BOOLEAN Model30;
  434. UCHAR PerpendicularDrives;
  435. UCHAR NumberOfDrives;
  436. UCHAR DriveControlImage;
  437. UCHAR HardwareFailCount;
  438. BOOLEAN ControllerInUse;
  439. UCHAR FdcType;
  440. UCHAR FdcSpeeds;
  441. PIRP CurrentIrp;
  442. UCHAR DriveOnValue;
  443. PDEVICE_OBJECT LastDeviceObject;
  444. BOOLEAN Clock48MHz;
  445. BOOLEAN FdcEnablerSupported;
  446. PDEVICE_OBJECT FdcEnablerDeviceObject;
  447. PFILE_OBJECT FdcEnablerFileObject;
  448. BOOLEAN ResetFlag; // for NEC98
  449. BOOLEAN FloppyEquip; // for NEC98
  450. UCHAR MotorRunning; // for NEC98
  451. UCHAR ResultStatus0[4]; // for NEC98
  452. #ifdef TOSHIBAJ
  453. // For 3mode support
  454. BOOLEAN Available3Mode;
  455. // Feb.9.1998 KIADP010 Assign Toshiba special registers.
  456. PUCHAR ConfigBase;
  457. #endif
  458. } FDC_FDO_EXTENSION, *PFDC_FDO_EXTENSION;
  459. #ifdef TOSHIBAJ
  460. // Feb.9.1998 KIADP011 Get base address and identifier
  461. // Feb.9.1998 KIADP012 Identify controller
  462. // Feb.9.1998 KIADP013 Change Speed
  463. // Definitions for SMC 37C67X/777
  464. // Ports
  465. #define SMC_INDEX_PORT(port) (port)
  466. #define SMC_DATA_PORT(port) (port)+1
  467. // Key
  468. #define SMC_KEY_ENTER_CONFIG 0x55
  469. #define SMC_KEY_EXIT_CONFIG 0xaa
  470. #define SMC_CONFIG_PORT_LENGTH 2
  471. // Index
  472. #define SMC_INDEX_DEVICE 0x07
  473. #define SMC_INDEX_IDENTIFY 0x20
  474. #define SMC_INDEX_CONF_ADDR_0 0x26
  475. #define SMC_INDEX_CONF_ADDR_1 0x27
  476. #define SMC_INDEX_FDC_OPT 0xf1
  477. // Device
  478. #define SMC_DEVICE_FDC 0x00
  479. // Mask
  480. #define SMC_MASK_DENSEL 0x0c
  481. // Dencity select
  482. #define SMC_DELSEL_HIGH 0x08 // 300rpm
  483. #define SMC_DENSEL_LOW 0x0c // 360rpm
  484. #endif
  485. //
  486. // NEC98: Registory path of MultifunctionAdapter.
  487. //
  488. #define ISA_BUS_NODE \
  489. "\\Registry\\MACHINE\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter\\%d"
  490. //
  491. // Macro
  492. //
  493. //
  494. // Enable/Disable Controller
  495. //
  496. #define DISABLE_CONTROLLER_IMAGE(FdoExtension) \
  497. { \
  498. if (IsNEC_98) { \
  499. FdoExtension->DriveControlImage |= DRVCTL_ENABLE_DMA_AND_INTERRUPTS; \
  500. FdoExtension->DriveControlImage |= DRVCTL_ENABLE_CONTROLLER; \
  501. FdoExtension->ResetFlag = FALSE; \
  502. } else { \
  503. FdoExtension->DriveControlImage |= DRVCTL_ENABLE_DMA_AND_INTERRUPTS; \
  504. FdoExtension->DriveControlImage &= ~( DRVCTL_ENABLE_CONTROLLER ); \
  505. } \
  506. }
  507. #define ENABLE_CONTROLLER_IMAGE(FdoExtension) \
  508. { \
  509. if (IsNEC_98) { \
  510. FdoExtension->DriveControlImage &= ~( DRVCTL_ENABLE_CONTROLLER ); \
  511. FdoExtension->DriveControlImage |= DRVCTL_AI_ENABLE; \
  512. } else { \
  513. FdoExtension->DriveControlImage |= DRVCTL_ENABLE_CONTROLLER; \
  514. } \
  515. }
  516. //
  517. // Dma speed
  518. //
  519. #define DEFAULT_DMA_SPEED (IsNEC_98 ? Compatible : TypeA)
  520. //
  521. // Paging Driver with Mutex
  522. //
  523. #define FDC_PAGE_INITIALIZE_DRIVER_WITH_MUTEX \
  524. { \
  525. if (!IsNEC_98) { \
  526. PagingMutex = ExAllocatePool(NonPagedPool, sizeof(FAST_MUTEX)); \
  527. if (!PagingMutex) { \
  528. return STATUS_INSUFFICIENT_RESOURCES; \
  529. } \
  530. ExInitializeFastMutex(PagingMutex); \
  531. MmPageEntireDriver(DriverEntry); \
  532. } \
  533. }
  534. #define FDC_PAGE_RESET_DRIVER_WITH_MUTEX \
  535. { \
  536. if (!IsNEC_98) { \
  537. ExAcquireFastMutex( PagingMutex ); \
  538. if ( ++PagingReferenceCount == 1 ) { \
  539. MmResetDriverPaging( DriverEntry ); \
  540. } \
  541. ExReleaseFastMutex( PagingMutex ); \
  542. } \
  543. }
  544. #define FDC_PAGE_ENTIRE_DRIVER_WITH_MUTEX \
  545. { \
  546. if (!IsNEC_98) { \
  547. ExAcquireFastMutex(PagingMutex); \
  548. if (--PagingReferenceCount == 0) { \
  549. MmPageEntireDriver(DriverEntry); \
  550. } \
  551. ExReleaseFastMutex(PagingMutex); \
  552. } \
  553. }
  554. //
  555. // Prototypes of external routines.
  556. //
  557. /*
  558. LONG
  559. sprintf(
  560. CHAR *,
  561. const CHAR *,
  562. ...
  563. );
  564. */
  565. //
  566. // Prototypes of driver routines.
  567. //
  568. NTSTATUS
  569. DriverEntry(
  570. IN PDRIVER_OBJECT DriverObject,
  571. IN PUNICODE_STRING RegistryPath
  572. );
  573. NTSTATUS
  574. FcAllocateCommonBuffers(
  575. IN PFDC_FDO_EXTENSION FdoExtension
  576. );
  577. NTSTATUS
  578. FcInitializeControllerHardware(
  579. IN PFDC_FDO_EXTENSION FdoExtension,
  580. IN PDEVICE_OBJECT DeviceObject
  581. );
  582. NTSTATUS
  583. FdcCreateClose(
  584. IN PDEVICE_OBJECT DeviceObject,
  585. IN PIRP Irp
  586. );
  587. NTSTATUS
  588. FdcInternalDeviceControl(
  589. IN PDEVICE_OBJECT DeviceObject,
  590. IN PIRP Irp
  591. );
  592. NTSTATUS
  593. FdcPnp(
  594. IN PDEVICE_OBJECT DeviceObject,
  595. IN PIRP Irp
  596. );
  597. NTSTATUS
  598. FdcPower(
  599. IN PDEVICE_OBJECT DeviceObject,
  600. IN PIRP Irp
  601. );
  602. NTSTATUS
  603. FdcAddDevice(
  604. IN PDRIVER_OBJECT DriverObject,
  605. IN OUT PDEVICE_OBJECT PhysicalDeviceObject
  606. );
  607. BOOLEAN
  608. FdcInterruptService(
  609. IN PKINTERRUPT Interrupt,
  610. IN PVOID Context
  611. );
  612. VOID
  613. FdcDeferredProcedure(
  614. IN PKDPC Dpc,
  615. IN PVOID DeferredContext,
  616. IN PVOID SystemArgument1,
  617. IN PVOID SystemArgument2
  618. );
  619. NTSTATUS
  620. FcAcquireFdc(
  621. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  622. IN PLARGE_INTEGER TimeOut
  623. );
  624. NTSTATUS
  625. FcReleaseFdc(
  626. IN OUT PFDC_FDO_EXTENSION FdoExtension
  627. );
  628. VOID
  629. FcReportFdcInformation(
  630. IN PFDC_PDO_EXTENSION PdoExtension,
  631. IN PFDC_FDO_EXTENSION FdcExtension,
  632. IN OUT PIO_STACK_LOCATION IrpSp
  633. );
  634. NTSTATUS
  635. FcTurnOnMotor(
  636. IN PFDC_FDO_EXTENSION FdcExtension,
  637. IN OUT PIO_STACK_LOCATION irpSp
  638. );
  639. NTSTATUS
  640. FcTurnOffMotor(
  641. IN PFDC_FDO_EXTENSION FdoExtension
  642. );
  643. VOID
  644. FcAllocateAdapterChannel(
  645. IN OUT PFDC_FDO_EXTENSION FdoExtension
  646. );
  647. VOID
  648. FcFreeAdapterChannel(
  649. IN OUT PFDC_FDO_EXTENSION FdoExtension
  650. );
  651. IO_ALLOCATION_ACTION
  652. FdcAllocateAdapterChannel(
  653. IN PDEVICE_OBJECT DeviceObject,
  654. IN PIRP Irp,
  655. IN PVOID MapRegisterBase,
  656. IN PVOID Context
  657. );
  658. NTSTATUS
  659. FcSendByte(
  660. IN UCHAR ByteToSend,
  661. IN PFDC_FDO_EXTENSION FdoExtension,
  662. IN BOOLEAN AllowLongDelay
  663. );
  664. NTSTATUS
  665. FcGetByte(
  666. OUT PUCHAR ByteToGet,
  667. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  668. IN BOOLEAN AllowLongDelay
  669. );
  670. NTSTATUS
  671. FcIssueCommand(
  672. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  673. IN PUCHAR FifoInBuffer,
  674. OUT PUCHAR FifoOutBuffer,
  675. IN PVOID IoHandle,
  676. IN ULONG IoOffset,
  677. IN ULONG TransferBytes
  678. );
  679. VOID
  680. FcLogErrorDpc(
  681. IN PKDPC Dpc,
  682. IN PVOID DeferredContext,
  683. IN PVOID SystemContext1,
  684. IN PVOID SystemContext2
  685. );
  686. BOOLEAN
  687. FcClearIsrReentered(
  688. IN PVOID Context
  689. );
  690. NTSTATUS
  691. FcGetFdcInformation(
  692. IN OUT PFDC_FDO_EXTENSION FdoExtension
  693. );
  694. VOID
  695. FdcCheckTimer(
  696. IN PDEVICE_OBJECT DeviceObject,
  697. IN OUT PVOID Context
  698. );
  699. BOOLEAN
  700. FdcTimerSync(
  701. IN OUT PVOID Context
  702. );
  703. VOID
  704. FdcStartIo(
  705. IN PDEVICE_OBJECT DeviceObject,
  706. IN PIRP Irp
  707. );
  708. NTSTATUS
  709. FcStartCommand(
  710. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  711. IN PUCHAR FifoInBuffer,
  712. OUT PUCHAR FifoOutBuffer,
  713. IN PVOID IoHandle,
  714. IN ULONG IoOffset,
  715. IN ULONG TransferBytes,
  716. IN BOOLEAN AllowLongDelay
  717. );
  718. NTSTATUS
  719. FcFinishCommand(
  720. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  721. IN PUCHAR FifoInBuffer,
  722. OUT PUCHAR FifoOutBuffer,
  723. IN PVOID IoHandle,
  724. IN ULONG IoOffset,
  725. IN ULONG TransferBytes,
  726. IN BOOLEAN AllowLongDelay
  727. );
  728. NTSTATUS
  729. FcFinishReset(
  730. IN OUT PFDC_FDO_EXTENSION FdoExtension
  731. );
  732. VOID
  733. FdcBufferThread(
  734. IN PVOID Context
  735. );
  736. NTSTATUS
  737. FcFdcEnabler(
  738. IN PDEVICE_OBJECT DeviceObject,
  739. IN ULONG Ioctl,
  740. IN OUT PVOID Data
  741. );
  742. NTSTATUS
  743. FcSynchronizeQueue(
  744. IN OUT PFDC_FDO_EXTENSION FdoExtension,
  745. IN PIRP Irp
  746. );
  747. NTSTATUS
  748. FdcPnpComplete(
  749. PDEVICE_OBJECT DeviceObject,
  750. PIRP Irp,
  751. PVOID Context
  752. );
  753. NTSTATUS
  754. FdcStartDevice(
  755. IN PDEVICE_OBJECT DeviceObject,
  756. IN PIRP Irp
  757. );
  758. NTSTATUS
  759. FdcInitializeDeviceObject(
  760. IN PDEVICE_OBJECT DeviceObject
  761. );
  762. NTSTATUS
  763. FdcFdoPnp(
  764. IN PDEVICE_OBJECT DeviceObject,
  765. IN PIRP Irp
  766. );
  767. NTSTATUS
  768. FdcPdoPnp(
  769. IN PDEVICE_OBJECT DeviceObject,
  770. IN PIRP Irp
  771. );
  772. NTSTATUS
  773. FdcFilterResourceRequirements(
  774. IN PDEVICE_OBJECT DeviceObject,
  775. IN PIRP Irp
  776. );
  777. NTSTATUS
  778. FdcQueryDeviceRelations(
  779. IN PDEVICE_OBJECT DeviceObject,
  780. IN PIRP Irp
  781. );
  782. NTSTATUS
  783. FdcConfigCallBack(
  784. IN PVOID Context,
  785. IN PUNICODE_STRING PathName,
  786. IN INTERFACE_TYPE BusType,
  787. IN ULONG BusNumber,
  788. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  789. IN CONFIGURATION_TYPE ControllerType,
  790. IN ULONG ControllerNumber,
  791. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  792. IN CONFIGURATION_TYPE PeripheralType,
  793. IN ULONG PeripheralNumber,
  794. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  795. );
  796. NTSTATUS
  797. FdcFdoConfigCallBack(
  798. IN PVOID Context,
  799. IN PUNICODE_STRING PathName,
  800. IN INTERFACE_TYPE BusType,
  801. IN ULONG BusNumber,
  802. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  803. IN CONFIGURATION_TYPE ControllerType,
  804. IN ULONG ControllerNumber,
  805. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  806. IN CONFIGURATION_TYPE PeripheralType,
  807. IN ULONG PeripheralNumber,
  808. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  809. );
  810. NTSTATUS
  811. FdcEnumerateQ117(
  812. IN PFDC_FDO_EXTENSION FdoExtension
  813. );
  814. VOID
  815. FdcGetEnablerDevice(
  816. IN OUT PFDC_FDO_EXTENSION FdoExtension
  817. );
  818. NTSTATUS
  819. FdcPdoInternalDeviceControl(
  820. IN PDEVICE_OBJECT DeviceObject,
  821. IN PIRP Irp
  822. );
  823. NTSTATUS
  824. FdcFdoInternalDeviceControl(
  825. IN PDEVICE_OBJECT DeviceObject,
  826. IN PIRP Irp
  827. );
  828. PVOID
  829. FdcGetControllerBase(
  830. IN INTERFACE_TYPE BusType,
  831. IN ULONG BusNumber,
  832. PHYSICAL_ADDRESS IoAddress,
  833. ULONG NumberOfBytes,
  834. BOOLEAN InIoSpace
  835. );
  836. //
  837. // For NEC98
  838. //
  839. NTSTATUS
  840. FdcHdbit(
  841. IN PDEVICE_OBJECT DeviceObject,
  842. IN PFDC_FDO_EXTENSION FdoExtension,
  843. IN PSET_HD_BIT_PARMS SetHdBitParams
  844. );
  845. ULONG
  846. FdcGet0Seg(
  847. IN PUCHAR ConfigrationData1,
  848. IN ULONG Offset
  849. );
  850. ULONG
  851. FdcFindIsaBusNode(
  852. IN OUT VOID
  853. );
  854. UCHAR
  855. FdcRqmReadyWait(
  856. IN PFDC_FDO_EXTENSION FdoExtension,
  857. IN ULONG IssueSenseInterrupt
  858. );
  859. #ifdef TOSHIBAJ
  860. NTSTATUS FcFdcEnable3Mode(
  861. IN PFDC_FDO_EXTENSION FdoExtension,
  862. IN PIRP Irp
  863. );
  864. NTSTATUS FcFdcAvailable3Mode(
  865. IN PFDC_FDO_EXTENSION FdoExtension,
  866. IN PIRP Irp
  867. );
  868. BOOLEAN
  869. FcCheckConfigPort(
  870. IN PUCHAR ConfigPort
  871. );
  872. #endif