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.

1700 lines
53 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. pcmcia.h
  5. Abstract:
  6. Revision History
  7. 27-Apr-95
  8. Databook support added.
  9. 1-Nov-96
  10. Complete overhaul to make this a bus enumerator +
  11. CardBus support
  12. - Ravisankar Pudipeddi (ravisp)
  13. --*/
  14. #ifndef _PCMCIAPRT_
  15. #define _PCMCIAPRT_
  16. #define MAX_NUMBER_OF_IO_RANGES 2
  17. #define MAX_NUMBER_OF_MEMORY_RANGES 4
  18. #define MAX_MANFID_LENGTH 64
  19. #define MAX_IDENT_LENGTH 64
  20. //
  21. // Function number for a multi-function pc-card
  22. //
  23. #define PCMCIA_MULTIFUNCTION_PARENT 0xFFFFFFFF
  24. typedef enum _DEVICE_OBJECT_TYPE {
  25. FDO = 0,
  26. PDO
  27. } DEVICE_OBJECT_TYPE;
  28. //
  29. // Type of the controller
  30. //
  31. typedef ULONG PCMCIA_CONTROLLER_TYPE, *PPCMCIA_CONTROLLER_TYPE;
  32. struct _SOCKET; //forward references
  33. struct _FDO_EXTENSION;
  34. struct _PDO_EXTENSION;
  35. //
  36. // Define SynchronizeExecution routine.
  37. //
  38. typedef
  39. BOOLEAN
  40. (*PSYNCHRONIZATION_ROUTINE) (
  41. IN PKINTERRUPT Interrupt,
  42. IN PKSYNCHRONIZE_ROUTINE Routine,
  43. IN PVOID SynchronizeContext
  44. );
  45. //
  46. // Define the Pcmcia controller detection routine
  47. //
  48. typedef
  49. NTSTATUS
  50. (*PPCMCIA_DETECT_ROUTINE) (
  51. struct _FDO_EXTENSION *DeviceExtension
  52. );
  53. //
  54. // Completion routine called by various timed routines
  55. //
  56. typedef
  57. VOID
  58. (*PPCMCIA_COMPLETION_ROUTINE) (
  59. IN PVOID Context,
  60. IN NTSTATUS status
  61. );
  62. //
  63. // Register context structure used to save register contents
  64. // when cardbus controllers are powered down..
  65. //
  66. typedef struct _PCMCIA_CONTEXT_RANGE {
  67. USHORT wOffset;
  68. USHORT wLen;
  69. } PCMCIA_CONTEXT_RANGE, *PPCMCIA_CONTEXT_RANGE;
  70. typedef struct _PCMCIA_CONTEXT {
  71. PPCMCIA_CONTEXT_RANGE Range;
  72. ULONG RangeCount;
  73. ULONG BufferLength;
  74. ULONG MaxLen;
  75. } PCMCIA_CONTEXT, *PPCMCIA_CONTEXT;
  76. //
  77. // Configuration entry parsed from CISTPL_CFTABLE_ENTRY
  78. // on a pc-card. Indicates what kind of resource configurations
  79. // the pc-card supports
  80. //
  81. typedef struct _CONFIG_ENTRY {
  82. struct _CONFIG_ENTRY *NextEntry;
  83. USHORT NumberOfIoPortRanges;
  84. USHORT NumberOfMemoryRanges;
  85. USHORT IoPortBase[MAX_NUMBER_OF_IO_RANGES];
  86. USHORT IoPortLength[MAX_NUMBER_OF_IO_RANGES];
  87. USHORT IoPortAlignment[MAX_NUMBER_OF_IO_RANGES];
  88. ULONG MemoryHostBase[MAX_NUMBER_OF_MEMORY_RANGES];
  89. ULONG MemoryCardBase[MAX_NUMBER_OF_MEMORY_RANGES];
  90. ULONG MemoryLength[MAX_NUMBER_OF_MEMORY_RANGES];
  91. USHORT IrqMask;
  92. //
  93. // Only one flag used now. Expect to have more in future..
  94. //
  95. #define PCMCIA_INVALID_CONFIGURATION 0x00000001
  96. USHORT Flags;
  97. //
  98. // Level or Edge triggered IRQ
  99. //
  100. UCHAR LevelIrq;
  101. //
  102. // Share disp.for the IRQ
  103. //
  104. UCHAR ShareDisposition;
  105. UCHAR IndexForThisConfiguration;
  106. //
  107. // Indicates if the i/o requirement supports 16-bit access
  108. //
  109. BOOLEAN Io16BitAccess;
  110. //
  111. // Indicates if the i/o requirement supports 8-bit access
  112. // At least one of Io8BitAccess and Io16BitAccess must always
  113. // be true for a valid configuration
  114. //
  115. BOOLEAN Io8BitAccess;
  116. } CONFIG_ENTRY, *PCONFIG_ENTRY;
  117. //
  118. // Function configuration holds the data that goes in each functions's
  119. // configuration registers
  120. //
  121. typedef struct _FUNCTION_CONFIGURATION {
  122. struct _FUNCTION_CONFIGURATION *Next;
  123. ULONG ConfigRegisterBase;
  124. UCHAR ConfigOptions;
  125. UCHAR ConfigFlags;
  126. UCHAR IoLimit;
  127. UCHAR Reserved;
  128. ULONG IoBase;
  129. } FUNCTION_CONFIGURATION, *PFUNCTION_CONFIGURATION;
  130. //
  131. // Socket configuration is the holder of the actual controller setup
  132. //
  133. typedef struct _SOCKET_CONFIGURATION {
  134. //
  135. // Device irq assigned
  136. //
  137. ULONG Irq;
  138. //
  139. // Optional Irq to indicate when card is ready
  140. //
  141. ULONG ReadyIrq;
  142. ULONG ConfigRegisterBase;
  143. ULONG NumberOfIoPortRanges;
  144. struct _SOCKET_CONFIG_IO_ENTRY {
  145. ULONG Base;
  146. USHORT Length;
  147. BOOLEAN Width16;
  148. BOOLEAN WaitState16;
  149. BOOLEAN Source16;
  150. BOOLEAN ZeroWait8;
  151. } Io[MAX_NUMBER_OF_IO_RANGES];
  152. ULONG NumberOfMemoryRanges;
  153. struct _SOCKET_CONFIG_MEM_ENTRY {
  154. ULONG HostBase;
  155. ULONG CardBase;
  156. ULONG Length;
  157. UCHAR IsAttribute;
  158. UCHAR WaitState;
  159. BOOLEAN Width16;
  160. } Memory[MAX_NUMBER_OF_MEMORY_RANGES];
  161. PFUNCTION_CONFIGURATION FunctionConfiguration;
  162. UCHAR IndexForCurrentConfiguration;
  163. } SOCKET_CONFIGURATION, *PSOCKET_CONFIGURATION;
  164. //
  165. // Each function on a PCCARD present gets socket data. Socket data
  166. // contains information concerning the function and its configuration.
  167. //
  168. typedef struct _SOCKET_DATA {
  169. //
  170. // Multi function pcards: links to
  171. // other socket-datas' off the same PC-Card
  172. //
  173. struct _SOCKET_DATA *Next;
  174. struct _SOCKET_DATA *Prev;
  175. struct _SOCKET *Socket;
  176. //
  177. // Pointer to the pdo's extension corresponding
  178. // to this socket
  179. //
  180. struct _PDO_EXTENSION *PdoExtension;
  181. UCHAR Mfg[MAX_MANFID_LENGTH];
  182. UCHAR Ident[MAX_IDENT_LENGTH];
  183. USHORT ManufacturerCode;
  184. USHORT ManufacturerInfo;
  185. ULONG ConfigRegisterBase; // Base address from config tuple.
  186. //
  187. // Number of configurations possible
  188. //
  189. ULONG NumberOfConfigEntries;
  190. //
  191. // Pointer to head of list of configurations
  192. //
  193. PCONFIG_ENTRY ConfigEntryChain; // Offset 0x114
  194. //
  195. // CRC calculated from the relevant tuples, used in
  196. // constructing hardware ids
  197. //
  198. USHORT CisCrc;
  199. //
  200. // Device Type: PCCARD_TYPE_xxxx
  201. //
  202. UCHAR DeviceType;
  203. UCHAR LastEntryInCardConfig;
  204. //
  205. // Voltage values requested
  206. //
  207. UCHAR Vcc;
  208. UCHAR Vpp1;
  209. UCHAR Vpp2;
  210. UCHAR Audio;
  211. UCHAR RegistersPresentMask[16];
  212. //
  213. // Configuration entry number used when actually
  214. // starting the pc-card
  215. //
  216. UCHAR ConfigIndexUsed;
  217. //
  218. // Number of function in a multifunction card - zero-based
  219. //
  220. UCHAR Function;
  221. UCHAR Flags;
  222. //
  223. // Pointer to the default configuration among the list of config entries
  224. // which will be used when the default bit is zero in a tuple (and
  225. // set when the default bit is one)
  226. //
  227. PCONFIG_ENTRY DefaultConfiguration;
  228. ULONG Instance;
  229. USHORT JedecId;
  230. //
  231. // Resource map indices for the requested resources in the
  232. // merged multifunction resource requirements list
  233. //
  234. UCHAR MfIrqResourceMapIndex;
  235. UCHAR MfIoPortResourceMapIndex;
  236. UCHAR MfMemoryResourceMapIndex;
  237. BOOLEAN MfNeedsIrq;
  238. USHORT MfIoPortCount;
  239. USHORT MfMemoryCount;
  240. } SOCKET_DATA, *PSOCKET_DATA;
  241. //
  242. // Bits defined in Flags field
  243. //
  244. #define SDF_ZV 1 // Zoom video custom interface
  245. #define SDF_JEDEC_ID 2
  246. #define IsConfigRegisterPresent(xSocketData, reg) ((((xSocketData)->RegistersPresentMask[reg / 8] & \
  247. (1 << (reg % 8)) )) ? \
  248. TRUE:FALSE)
  249. //
  250. // Config list is an array used in translating CONFIG_ENTRY data to
  251. // IO_RESOURCE_LISTs
  252. //
  253. typedef struct _CONFIG_LIST {
  254. PSOCKET_DATA SocketData;
  255. PCONFIG_ENTRY ConfigEntry;
  256. } CONFIG_LIST, * PCONFIG_LIST;
  257. //
  258. // PCMCIA configuration information structure contains information
  259. // about the PCMCIA controller attached and its configuration.
  260. //
  261. typedef struct _PCMCIA_CONFIGURATION_INFORMATION {
  262. INTERFACE_TYPE InterfaceType;
  263. ULONG BusNumber;
  264. ULONG SlotNumber;
  265. PHYSICAL_ADDRESS PortAddress;
  266. USHORT PortSize;
  267. USHORT UntranslatedPortAddress;
  268. //
  269. // Card status change interrupt: these fields are used only
  270. // for cardbus controllers.
  271. //
  272. CM_PARTIAL_RESOURCE_DESCRIPTOR Interrupt;
  273. CM_PARTIAL_RESOURCE_DESCRIPTOR TranslatedInterrupt;
  274. //
  275. // For PCI-based controllers, indicates the pin number which we need
  276. // for programming the controller interrupt.
  277. // NOTE: This is no longer needed (this was to handle CSC interrupts
  278. // for PCI-PCMCIA bridges (like CL PD6729). We no longer support interrupt
  279. // based card status change for these cntrollers. Get rid of it
  280. // whenever possible.
  281. //
  282. UCHAR InterruptPin;
  283. //
  284. // Another dead field. Legacy.
  285. //
  286. BOOLEAN FloatingSave;
  287. USHORT Reserved; // Alignment
  288. } PCMCIA_CONFIGURATION_INFORMATION, *PPCMCIA_CONFIGURATION_INFORMATION;
  289. //
  290. // PCMCIA_CTRL_BLOCK allows for a level of indirection, thereby allowing
  291. // the top-level PCMCIA code to do it's work without worrying about who's
  292. // particular brand of PCMCIA controller it's addressing.
  293. //
  294. // Note that this only implements TWO architectures, pcic and tcic. For
  295. // more indirection, see DEVICE_DISPATCH_TABLE
  296. typedef struct _PCMCIA_CTRL_BLOCK {
  297. //
  298. // Function to initialize the socket
  299. //
  300. BOOLEAN (*PCBInitializePcmciaSocket)(
  301. IN struct _SOCKET *Socket
  302. );
  303. //
  304. // Function to initialize the card in the socket.
  305. //
  306. NTSTATUS
  307. (*PCBResetCard)(
  308. IN struct _SOCKET *Socket,
  309. OUT PULONG pDelayTime
  310. );
  311. //
  312. // Function to determine if a card is in the socket
  313. //
  314. BOOLEAN (*PCBDetectCardInSocket)(
  315. IN struct _SOCKET *Socket
  316. );
  317. //
  318. // Function to determine if insertion status has changed.
  319. //
  320. BOOLEAN (*PCBDetectCardChanged)(
  321. IN struct _SOCKET *Socket
  322. );
  323. //
  324. // Function to determine if card status has been asserted.
  325. //
  326. BOOLEAN (*PCBDetectCardStatus)(
  327. IN struct _SOCKET *Socket
  328. );
  329. //
  330. // Function to determine if "card ready" status has changed
  331. //
  332. BOOLEAN (*PCBDetectReadyChanged)(
  333. IN struct _SOCKET *Socket
  334. );
  335. //
  336. // Function which requests that the controller be examined to
  337. // determine what power settings the current device in the socket
  338. // requires.
  339. //
  340. NTSTATUS
  341. (*PCBGetPowerRequirements)(
  342. IN struct _SOCKET *Socket
  343. );
  344. //
  345. // Function to configure cards.
  346. //
  347. BOOLEAN (*PCBProcessConfigureRequest)(
  348. IN struct _SOCKET *Socket,
  349. IN struct _CARD_REQUEST *ConfigRequest,
  350. IN PUCHAR Base
  351. );
  352. //
  353. // Function to enable/disable status change interrupts
  354. //
  355. BOOLEAN (*PCBEnableDisableCardDetectEvent)(
  356. IN struct _SOCKET *Socket,
  357. IN BOOLEAN Enable
  358. );
  359. //
  360. // Function to set/reset the ring enable bit for the given
  361. // socket. Setting Ring Enable would cause the CSC to be used
  362. // as a wakeup event for pc-card modems/netcards etc.
  363. //
  364. VOID (*PCBEnableDisableWakeupEvent) (
  365. IN struct _SOCKET *SocketPtr,
  366. IN struct _PDO_EXTENSION *PdoExtension,
  367. IN BOOLEAN Enable
  368. );
  369. //
  370. // Function to return the set of IRQs supported
  371. // by the controller
  372. //
  373. ULONG (*PCBGetIrqMask) (
  374. IN struct _FDO_EXTENSION *DeviceExtension
  375. );
  376. //
  377. // Function to read the memory contents (attribute/common)
  378. // on the given PC-Card
  379. //
  380. ULONG (*PCBReadCardMemory) (
  381. IN struct _PDO_EXTENSION *PdoExtension,
  382. IN MEMORY_SPACE MemorySpace,
  383. IN ULONG Offset,
  384. IN PUCHAR Buffer,
  385. IN ULONG Length
  386. );
  387. //
  388. // Function to write to the attribute/common memory of
  389. // the given PC-Card
  390. //
  391. ULONG (*PCBWriteCardMemory) (
  392. IN struct _PDO_EXTENSION *PdoExtension,
  393. IN MEMORY_SPACE MemorySpace,
  394. IN ULONG Offset,
  395. IN PUCHAR Buffer,
  396. IN ULONG Length
  397. );
  398. //
  399. // Flash memory card interfaces:
  400. //
  401. //
  402. // Function to slide the host memory window on a pc-card
  403. //
  404. PPCMCIA_MODIFY_MEMORY_WINDOW PCBModifyMemoryWindow;
  405. //
  406. // Function to set the Vpp to the supplied value
  407. //
  408. PPCMCIA_SET_VPP PCBSetVpp;
  409. //
  410. // Function to test if the given card is write protected
  411. //
  412. PPCMCIA_IS_WRITE_PROTECTED PCBIsWriteProtected;
  413. }PCMCIA_CTRL_BLOCK, *PPCMCIA_CTRL_BLOCK;
  414. //
  415. // Each socket on the PCMCIA controller has a socket structure
  416. // to contain current information on the state of the socket and
  417. // and PCCARD inserted.
  418. //
  419. #define IsSocketFlagSet(Socket, Flag) (((Socket)->Flags & (Flag))?TRUE:FALSE)
  420. #define SetSocketFlag(Socket, Flag) ((Socket)->Flags |= (Flag))
  421. #define ResetSocketFlag(Socket,Flag) ((Socket)->Flags &= ~(Flag))
  422. //
  423. // Socket flags
  424. //
  425. #define SOCKET_CARD_INITIALIZED 0x00000002
  426. #define SOCKET_CARD_POWERED_UP 0x00000004
  427. #define SOCKET_CARD_CONFIGURED 0x00000008
  428. #define SOCKET_CARD_MULTIFUNCTION 0x00000010
  429. #define SOCKET_CARD_MEMORY 0x00000040
  430. #define SOCKET_CHANGE_INTERRUPT 0x00000080
  431. #define SOCKET_CUSTOM_INTERFACE 0x00000100
  432. #define SOCKET_SUPPORT_MESSAGE_SENT 0x00000800
  433. #define SOCKET_MEMORY_WINDOW_ENABLED 0x00001000
  434. #define SOCKET_CARD_STATUS_CHANGE 0x00002000
  435. #define SOCKET_ENUMERATE_PENDING 0x00008000
  436. #define SOCKET_CLEANUP_PENDING 0x00010000
  437. #define SOCKET_CB_ROUTE_R2_TO_PCI 0x00020000
  438. #define SOCKET_POWER_PREFER_3V 0x00040000
  439. #define SOCKET_ENABLED_FOR_CARD_DETECT 0x00080000
  440. #define SOCKET_DEVICE_HIDDEN 0x00100000
  441. #define SOCKET_CLEANUP_MASK (SOCKET_CARD_CONFIGURED | SOCKET_CLEANUP_PENDING)
  442. //
  443. // Socket insertion states
  444. //
  445. #define SKT_Empty 0
  446. #define SKT_CardBusCard 1
  447. #define SKT_R2Card 2
  448. //
  449. // Worker states for socket power operations
  450. //
  451. typedef enum _SPW_STATE {
  452. SPW_Stopped = 0,
  453. SPW_Exit,
  454. SPW_RequestPower,
  455. SPW_ReleasePower,
  456. SPW_SetPowerOn,
  457. SPW_SetPowerOff,
  458. SPW_ResetCard,
  459. SPW_Deconfigure
  460. } SPW_STATE;
  461. #define PCMCIA_SOCKET_SIGNATURE 'SmcP'
  462. //
  463. // Socket structure
  464. //
  465. typedef struct _SOCKET {
  466. ULONG Signature;
  467. struct _SOCKET *NextSocket;
  468. //
  469. // Pointer to the pdo for the pc-card in this socket. This is a linked
  470. // list running through "NextPdoInSocket" in the pdo extension. This list
  471. // represents the functions that are physically contained within a socket.
  472. //
  473. PDEVICE_OBJECT PdoList;
  474. //
  475. // Parent pcmcia controller's fdo extension of this socket
  476. //
  477. struct _FDO_EXTENSION *DeviceExtension;
  478. //
  479. // Pointer to the miniport-like
  480. //
  481. PPCMCIA_CTRL_BLOCK SocketFnPtr;
  482. //
  483. // Flags prefixed SOCKET_ defined above
  484. //
  485. ULONG Flags;
  486. //
  487. // For 16-bit cards we use the i/o address port to read/write
  488. // to the socket registers
  489. // For cardbus cards, we use the CardBus socket register base
  490. //
  491. PUCHAR AddressPort;
  492. KEVENT PCCardReadyEvent;
  493. BOOLEAN ReadyChanged;
  494. //
  495. // Voltage values requested
  496. //
  497. UCHAR Vcc;
  498. UCHAR Vpp1;
  499. UCHAR Vpp2;
  500. //
  501. // Socket states
  502. //
  503. UCHAR DeviceState;
  504. UCHAR Reserved0;
  505. //
  506. // For PCIC controllers: register offset of the socket
  507. //
  508. USHORT RegisterOffset;
  509. //
  510. // PCIC revision
  511. //
  512. UCHAR Revision;
  513. //
  514. // PCIC controllers: zero-based number of the socket
  515. //
  516. UCHAR SocketNumber;
  517. //
  518. // Indicates the number of functions this pc-card has
  519. // (this will be > 1 only for multifunction cards like modem/net combos)
  520. //
  521. UCHAR NumberOfFunctions;
  522. //
  523. // Current memory window used internally for reading attributes
  524. //
  525. UCHAR CurrentMemWindow;
  526. //
  527. // Timer and DPC objects to handle socket power and initialization
  528. //
  529. KTIMER PowerTimer;
  530. KDPC PowerDpc;
  531. //
  532. // Function and parameter to call at the end of power operation
  533. //
  534. PPCMCIA_COMPLETION_ROUTINE PowerCompletionRoutine;
  535. PVOID PowerCompletionContext;
  536. NTSTATUS CallerStatus;
  537. NTSTATUS DeferredStatus;
  538. LONG DeferredStatusLock;
  539. //
  540. // Phase variables control state machine for socket power
  541. //
  542. LONG WorkerBusy;
  543. SPW_STATE WorkerState;
  544. UCHAR PowerPhase;
  545. UCHAR CardResetPhase;
  546. UCHAR Reserved;
  547. //
  548. // PowerData is temporary storage for power "miniports"
  549. //
  550. ULONG PowerData;
  551. //
  552. // semaphore to count # of functions requesting power on this socket
  553. //
  554. LONG PowerRequests;
  555. //
  556. // Context buffers
  557. //
  558. PUCHAR CardbusContextBuffer;
  559. PUCHAR ExcaContextBuffer;
  560. //
  561. // Current IRQ routing settings on socket
  562. //
  563. ULONG IrqMask;
  564. ULONG FdoIrq;
  565. } SOCKET, *PSOCKET;
  566. //
  567. // Lock used for synhing access to device(pcmcia controller registers etc.)
  568. // If the definition for this changes, the following 3 defs for
  569. // acquiring/releasing the locks also may need to change
  570. //
  571. typedef struct _PCMCIA_DEVICE_LOCK {
  572. KSPIN_LOCK Lock;
  573. KIRQL Irql;
  574. } PCMCIA_DEVICE_LOCK, * PPCMCIA_DEVICE_LOCK;
  575. #define PCMCIA_INITIALIZE_DEVICE_LOCK(X) KeInitializeSpinLock(&(X)->DeviceLock.Lock)
  576. #define PCMCIA_ACQUIRE_DEVICE_LOCK(X) KeAcquireSpinLock(&(X)->DeviceLock.Lock, &(X)->DeviceLock.Irql)
  577. #define PCMCIA_ACQUIRE_DEVICE_LOCK_AT_DPC_LEVEL(X) KeAcquireSpinLockAtDpcLevel(&(X)->DeviceLock.Lock)
  578. #define PCMCIA_RELEASE_DEVICE_LOCK(X) KeReleaseSpinLock(&(X)->DeviceLock.Lock, (X)->DeviceLock.Irql)
  579. #define PCMCIA_RELEASE_DEVICE_LOCK_FROM_DPC_LEVEL(X) KeReleaseSpinLockFromDpcLevel(&(X)->DeviceLock.Lock)
  580. #define PCMCIA_TEST_AND_SET(X) (InterlockedCompareExchange(X, 1, 0) == 0)
  581. #define PCMCIA_TEST_AND_RESET(X) (InterlockedCompareExchange(X, 0, 1) == 1)
  582. //
  583. // Wait-Wake states
  584. //
  585. typedef enum {
  586. WAKESTATE_DISARMED,
  587. WAKESTATE_WAITING,
  588. WAKESTATE_WAITING_CANCELLED,
  589. WAKESTATE_ARMED,
  590. WAKESTATE_ARMING_CANCELLED,
  591. WAKESTATE_COMPLETING
  592. } WAKESTATE;
  593. //
  594. // Power Policy Flags
  595. //
  596. #define PCMCIA_PP_WAKE_FROM_D0 0x00000001
  597. #define PCMCIA_PP_D3_ON_IDLE 0x00000002
  598. //
  599. // Functional Device Object's device extension information
  600. //
  601. // There is one device object for each PCMCIA socket controller
  602. // located in the system. This contains the root pointers for
  603. // each of the lists of information on this controller.
  604. //
  605. //
  606. // Flags common to both fdoExtension and pdoExtension
  607. //
  608. #define PCMCIA_DEVICE_STARTED 0x00000001
  609. #define PCMCIA_DEVICE_LOGICALLY_REMOVED 0x00000002
  610. #define PCMCIA_DEVICE_PHYSICALLY_REMOVED 0x00000004
  611. #define PCMCIA_DEVICE_DELETED 0x00000040
  612. #define PCMCIA_DEVICE_CARDBUS 0x00000080
  613. //
  614. // Flags indicating controller state (fdoExtension)
  615. //
  616. #define PCMCIA_DEVICE_LEGACY_DETECTED 0x00000020
  617. #define PCMCIA_FILTER_ADDED_MEMORY 0x00000100
  618. #define PCMCIA_MEMORY_24BIT 0x00000200
  619. #define PCMCIA_CARDBUS_NOT_SUPPORTED 0x00000400
  620. #define PCMCIA_USE_POLLED_CSC 0x00000800
  621. #define PCMCIA_ATTRIBUTE_MEMORY_MAPPED 0x00001000
  622. #define PCMCIA_SOCKET_REGISTER_BASE_MAPPED 0x00002000
  623. #define PCMCIA_INTMODE_COMPAQ 0x00004000
  624. #define PCMCIA_INT_ROUTE_INTERFACE 0x00080000
  625. #define PCMCIA_FDO_CONTEXT_SAVED 0x00100000
  626. #define PCMCIA_FDO_OFFLINE 0x00800000
  627. #define PCMCIA_FDO_ON_DEBUG_PATH 0x01000000
  628. #define PCMCIA_FDO_DISABLE_AUTO_POWEROFF 0x02000000
  629. #define PCMCIA_FDO_PREFER_3V 0x04000000
  630. #define PCMCIA_FDO_IOCTL_INTERFACE_ENABLED 0x08000000
  631. //
  632. // FDO Flags
  633. //
  634. #define PCMCIA_FDO_IRQ_DETECT_DEVICE_FOUND 0x00000001
  635. #define PCMCIA_FDO_IRQ_DETECT_COMPLETED 0x00000002
  636. #define PCMCIA_FDO_IN_ACPI_NAMESPACE 0x00000004
  637. #define PCMCIA_FDO_FORCE_PCI_ROUTING 0x00000010
  638. #define PCMCIA_FDO_PREFER_PCI_ROUTING 0x00000020
  639. #define PCMCIA_FDO_FORCE_ISA_ROUTING 0x00000040
  640. #define PCMCIA_FDO_PREFER_ISA_ROUTING 0x00000080
  641. #define PCMCIA_FDO_WAKE_BY_CD 0x00000100
  642. //
  643. // states for FdoPowerWorker
  644. //
  645. typedef enum _FDO_POWER_WORKER_STATE {
  646. FPW_Stopped = 0,
  647. FPW_BeginPowerDown,
  648. FPW_PowerDown,
  649. FPW_PowerDownSocket,
  650. FPW_PowerDownComplete,
  651. FPW_BeginPowerUp,
  652. FPW_PowerUp,
  653. FPW_PowerUpSocket,
  654. FPW_PowerUpSocket2,
  655. FPW_PowerUpSocketVerify,
  656. FPW_PowerUpSocketComplete,
  657. FPW_PowerUpComplete,
  658. FPW_SendIrpDown,
  659. FPW_CompleteIrp
  660. } FDO_POWER_WORKER_STATE;
  661. #define FPW_END_SEQUENCE 128
  662. #define PCMCIA_FDO_EXTENSION_SIGNATURE 'FmcP'
  663. //
  664. // Device extension for the functional device object for pcmcia controllers
  665. //
  666. typedef struct _FDO_EXTENSION {
  667. ULONG Signature;
  668. //
  669. // Pointer to the next pcmcia controller's FDO in the central list
  670. // of all pcmcia controller managed by this driver.
  671. // The head of the list is pointed to by the global variable FdoList
  672. //
  673. PDEVICE_OBJECT NextFdo;
  674. //
  675. // The PDO ejected by the parent bus driver for this pcmcia controller
  676. //
  677. //
  678. PDEVICE_OBJECT Pdo;
  679. //
  680. // The immediately lower device attached beneath the pcmcia controller's FDO.
  681. // This would be the same as the Pdo above, excepting in cases when there are
  682. // lower filter drivers for the pcmcia controller - like the ACPI driver
  683. //
  684. PDEVICE_OBJECT LowerDevice;
  685. //
  686. // Pointer to the list of sockets which hang off this pcmcia controller
  687. //
  688. PSOCKET SocketList;
  689. //
  690. // Various flags used to track the state of this
  691. // (flags prefixed by PCMCIA_ above)
  692. //
  693. ULONG Flags;
  694. //
  695. // FDO specific flags
  696. //
  697. ULONG FdoFlags;
  698. //
  699. // Bus numbering for PCI devices
  700. //
  701. UCHAR PciBusNumber;
  702. UCHAR PciDeviceNumber;
  703. UCHAR PciFunctionNumber;
  704. UCHAR reserved;
  705. //
  706. // Type of the controller. We need to know this since this is
  707. // a monolithic driver. We can do controller specific stuff
  708. // based on the type if needed.
  709. //
  710. PCMCIA_CONTROLLER_TYPE ControllerType;
  711. //
  712. // Index into the device dispatch table for vendor-specific
  713. // controller functions
  714. //
  715. ULONG DeviceDispatchIndex;
  716. PDEVICE_OBJECT DeviceObject;
  717. PDRIVER_OBJECT DriverObject;
  718. PUNICODE_STRING RegistryPath;
  719. //
  720. // Symbolic link name exported for this pcmcia controller
  721. //
  722. UNICODE_STRING LinkName;
  723. //
  724. // Head of the list of child pc-card PDO's hanging off this controller.
  725. // This is a linked list running through "NextPdoInFdoChain" in the pdo
  726. // extension. This list represents the devices that were enumerated by
  727. // the fdo.
  728. //
  729. PDEVICE_OBJECT PdoList;
  730. //
  731. // Keeps track of the number of PDOs which are actually
  732. // valid (not removed). This is primarily used in
  733. // enumeration of the pcmcia controller upon an IRP_MN_QUERY_DEVICE_RELATIONS
  734. //
  735. ULONG LivePdoCount;
  736. //
  737. // Lock for synching device access
  738. //
  739. PCMCIA_DEVICE_LOCK DeviceLock;
  740. //
  741. // Card status change poll related structures
  742. //
  743. //
  744. // Dpc which periodically polls to see if card has been inserted or removed
  745. //
  746. KDPC TimerDpc;
  747. //
  748. // The PollTimer object which is initialized and triggered if a Card Status change
  749. // interrupt is not used & we resort to polling..
  750. //
  751. KTIMER PollTimer;
  752. //
  753. // Kernel objects to defer power up initialization of controller
  754. //
  755. KTIMER PowerTimer;
  756. KDPC PowerDpc;
  757. //
  758. // Kernel objects to handle controller events
  759. //
  760. KTIMER EventTimer;
  761. KDPC EventDpc;
  762. //
  763. // IRQ Mask used in determining which IRQs are allowed for this
  764. // controller & it's child pc-cards.
  765. // 1's in the mask correspond to valid IRQs.
  766. // IRQs are numbered 0 - 15, lsb to msb
  767. // LegacyIrqMask is a fixed masked used if detection fails and PCI routing is disabled
  768. //
  769. USHORT DetectedIrqMask;
  770. USHORT LegacyIrqMask;
  771. //
  772. // Physical address of the attribute memory window used
  773. // read tuples off a pc-card.
  774. //
  775. PHYSICAL_ADDRESS PhysicalBase;
  776. //
  777. // Attribute memory resource requirement limits
  778. //
  779. ULONG AttributeMemoryLow;
  780. ULONG AttributeMemoryHigh;
  781. //
  782. // Size of the attribute memory window requested
  783. //
  784. ULONG AttributeMemorySize;
  785. //
  786. // Alignment of the attribute memory window
  787. //
  788. ULONG AttributeMemoryAlignment;
  789. //
  790. // Virtual address mapped to the attribute memory window (PhysicalBase)
  791. //
  792. PUCHAR AttributeMemoryBase;
  793. //
  794. // Sequence number for event logging
  795. //
  796. ULONG SequenceNumber;
  797. //
  798. // Pointer to the interrupt object - if we use interrupt based
  799. // card status change detection
  800. //
  801. PKINTERRUPT PcmciaInterruptObject;
  802. //
  803. // Power management related stuff.
  804. //
  805. //
  806. // Current system power state..
  807. //
  808. SYSTEM_POWER_STATE SystemPowerState;
  809. //
  810. // Device power state the pcmcia controller is currently in
  811. //
  812. DEVICE_POWER_STATE DevicePowerState;
  813. //
  814. // Indicates how many children (pc-cards) are pending on an
  815. // IRP_MN_WAIT_WAKE
  816. //
  817. ULONG ChildWaitWakeCount;
  818. //
  819. // Device capabilities as reported by our bus driver
  820. //
  821. DEVICE_CAPABILITIES DeviceCapabilities;
  822. //
  823. // Pending wait wake Irp
  824. //
  825. PIRP WaitWakeIrp;
  826. LONG WaitWakeState;
  827. //
  828. // Pci config register state
  829. //
  830. PCMCIA_CONTEXT PciContext;
  831. //
  832. // Interface obtained from PCI driver, for cardbus controllers.
  833. // This contains interfaces to enumerate CardBus cards
  834. // (not this interface is private to PCI & PCMCIA.
  835. // No other driver is expected to use these interfaces
  836. //
  837. PCI_CARDBUS_INTERFACE_PRIVATE PciCardBusInterface;
  838. PVOID PciCardBusDeviceContext;
  839. //
  840. // PCI Bus interface standard
  841. // This contains interfaces to read/write from PCI config space
  842. // of the cardbus controller, among other stuff..
  843. //
  844. BUS_INTERFACE_STANDARD PciBusInterface;
  845. //
  846. // PCI Int Route interface standard
  847. // This contains the interface to update the raw interrupt line
  848. // of the cardbus card
  849. //
  850. INT_ROUTE_INTERFACE_STANDARD PciIntRouteInterface;
  851. //
  852. // Configuration resources for the PCMCIA controller
  853. //
  854. PCMCIA_CONFIGURATION_INFORMATION Configuration;
  855. //
  856. // Pending power irp
  857. //
  858. PIRP PendingPowerIrp;
  859. PSOCKET PendingPowerSocket;
  860. //
  861. // Power worker state machine context
  862. //
  863. FDO_POWER_WORKER_STATE *PowerWorkerSequence;
  864. FDO_POWER_WORKER_STATE PowerWorkerState;
  865. UCHAR PowerWorkerPhase;
  866. UCHAR PowerWorkerMaxPhase;
  867. //
  868. // Type of bus we are on
  869. //
  870. INTERFACE_TYPE InterfaceType;
  871. //
  872. // CardBus socket base
  873. //
  874. PUCHAR CardBusSocketRegisterBase;
  875. //
  876. // Size of the socket register base that has been mapped
  877. //
  878. ULONG CardBusSocketRegisterSize;
  879. //
  880. // configuration context
  881. //
  882. PCMCIA_CONTEXT CardbusContext;
  883. PCMCIA_CONTEXT ExcaContext;
  884. PUCHAR PciContextBuffer;
  885. //
  886. // Deferred pdo power irp handling
  887. //
  888. LIST_ENTRY PdoPowerRetryList;
  889. KDPC PdoPowerRetryDpc;
  890. //
  891. // Count to track cardbus PCI interface calls
  892. //
  893. ULONG PciAddCardBusCount;
  894. //
  895. // Deletion Mutex
  896. //
  897. ULONG DeletionLock;
  898. } FDO_EXTENSION, *PFDO_EXTENSION;
  899. //
  900. // Physical Device Object's device extension information
  901. //
  902. // There is one device object for each function of each
  903. // PC-card in a socket per PCMCIA controller
  904. // in the system. This is referred to as the 'PDO' (physical device
  905. // object)- handled by this bus driver.
  906. //
  907. //
  908. // Flags indicating card state
  909. //
  910. #define PCMCIA_DEVICE_MULTIFUNCTION 0x00000008
  911. #define PCMCIA_DEVICE_WAKE_PENDING 0x00000010
  912. #define PCMCIA_POWER_WORKER_POWERUP 0x00008000
  913. #define PCMCIA_CONFIG_STATUS_DEFERRED 0x00020000
  914. #define PCMCIA_POWER_STATUS_DEFERRED 0x00040000
  915. #define PCMCIA_PDO_ENABLE_AUDIO 0x00200000
  916. #define PCMCIA_PDO_EXCLUSIVE_IRQ 0x00400000
  917. #define PCMCIA_PDO_INDIRECT_CIS 0x00000001
  918. #define PCMCIA_PDO_SUPPORTS_WAKE 0x00000002
  919. //
  920. // states for PdoPowerWorker
  921. //
  922. typedef enum _PDO_POWER_WORKER_STATE {
  923. PPW_Stopped = 0,
  924. PPW_Exit,
  925. PPW_InitialState,
  926. PPW_PowerUp,
  927. PPW_PowerDown,
  928. PPW_SendIrpDown,
  929. PPW_16BitConfigure,
  930. PPW_CardBusRefresh,
  931. PPW_CardBusDelay
  932. } PDO_POWER_WORKER_STATE;
  933. //
  934. // phases for ConfigurationWorker
  935. //
  936. typedef enum _CW_STATE {
  937. CW_Stopped = 0,
  938. CW_InitialState,
  939. CW_ResetCard,
  940. CW_Phase1,
  941. CW_Phase2,
  942. CW_Phase3,
  943. CW_Exit
  944. } CW_STATE;
  945. //
  946. // Flags for ConfigurationWorker
  947. //
  948. #define CONFIG_WORKER_APPLY_MODEM_HACK 0x01
  949. #define PCMCIA_PDO_EXTENSION_SIGNATURE 'PmcP'
  950. //
  951. // Device extension for the physical device object for pcmcia cards
  952. //
  953. typedef struct _PDO_EXTENSION {
  954. ULONG Signature;
  955. PDEVICE_OBJECT DeviceObject;
  956. //
  957. // Link to next pdo in the Fdo's pdo chain
  958. //
  959. PDEVICE_OBJECT NextPdoInFdoChain;
  960. //
  961. // Link to next pdo in the Socket's pdo chain
  962. //
  963. PDEVICE_OBJECT NextPdoInSocket;
  964. //
  965. // Following two declarations valid only for cardbus cards
  966. //
  967. // Device attached just below us
  968. //
  969. PDEVICE_OBJECT LowerDevice;
  970. //
  971. // Actual PDO (owned by PCI) that was enumerated for this
  972. // cardbus card
  973. //
  974. PDEVICE_OBJECT PciPdo;
  975. //
  976. // Cached copy of device id
  977. //
  978. PUCHAR DeviceId;
  979. //
  980. // Pointer to the appropriate socket struc in the parent FDO
  981. //
  982. PSOCKET Socket;
  983. //
  984. // Pointer to the structure assembled by gleaning off tuple data
  985. // from a 16-bit pc-card
  986. //
  987. PSOCKET_DATA SocketData;
  988. //
  989. // Resource configuration assigned to this socket
  990. //
  991. PSOCKET_CONFIGURATION SocketConfiguration;
  992. //
  993. // Flags prefixed PCMCIA_ above
  994. //
  995. ULONG Flags;
  996. //
  997. // PDO Flags
  998. //
  999. ULONG PdoFlags;
  1000. //
  1001. // Power declarations
  1002. //
  1003. DEVICE_POWER_STATE DevicePowerState;
  1004. SYSTEM_POWER_STATE SystemPowerState;
  1005. //
  1006. // Device Capabilities
  1007. //
  1008. DEVICE_CAPABILITIES DeviceCapabilities;
  1009. //
  1010. // Pending wait wake irp
  1011. //
  1012. PIRP WaitWakeIrp;
  1013. //
  1014. // Other pending power irps
  1015. //
  1016. PIRP PendingPowerIrp;
  1017. //
  1018. // power worker state machine variables
  1019. //
  1020. KTIMER PowerWorkerTimer;
  1021. KDPC PowerWorkerDpc;
  1022. NTSTATUS PowerWorkerDpcStatus;
  1023. PUCHAR PowerWorkerSequence;
  1024. UCHAR PowerWorkerPhase;
  1025. PDO_POWER_WORKER_STATE PowerWorkerState;
  1026. //
  1027. // Type of card based on an INF override
  1028. //
  1029. UCHAR SpecifiedDeviceType;
  1030. //
  1031. // Timer and DPC objects to handle card enables
  1032. //
  1033. CW_STATE ConfigurationPhase;
  1034. UCHAR ConfigurationFlags;
  1035. KTIMER ConfigurationTimer;
  1036. KDPC ConfigurationDpc;
  1037. NTSTATUS ConfigurationStatus;
  1038. NTSTATUS DeferredConfigurationStatus;
  1039. USHORT ConfigureDelay1;
  1040. USHORT ConfigureDelay2;
  1041. USHORT ConfigureDelay3;
  1042. USHORT Reserved2;
  1043. PPCMCIA_COMPLETION_ROUTINE ConfigCompletionRoutine;
  1044. //
  1045. // PCI Bus interface standard
  1046. // This contains interfaces to read/write from PCI config space
  1047. // of the cardbus card, among other stuff..
  1048. //
  1049. BUS_INTERFACE_STANDARD PciBusInterface; // size 0x20 (32)
  1050. //
  1051. // ID used to check for card changes while powered off
  1052. //
  1053. ULONG CardBusId;
  1054. //
  1055. // CIS cache for reading tuple data
  1056. //
  1057. PUCHAR CisCache;
  1058. MEMORY_SPACE CisCacheSpace;
  1059. ULONG CisCacheBase;
  1060. //
  1061. // Lock for power requests
  1062. //
  1063. LONG SocketPowerRequested;
  1064. //
  1065. // Deletion Mutex
  1066. //
  1067. ULONG DeletionLock;
  1068. } PDO_EXTENSION, *PPDO_EXTENSION;
  1069. //
  1070. // Struct for Database of card bus controller information
  1071. // which maps the vendor id/device id to a CONTROLLER_TYPE
  1072. //
  1073. typedef struct _PCI_CONTROLLER_INFORMATION {
  1074. USHORT VendorID;
  1075. USHORT DeviceID;
  1076. PCMCIA_CONTROLLER_TYPE ControllerType;
  1077. } PCI_CONTROLLER_INFORMATION, *PPCI_CONTROLLER_INFORMATION;
  1078. //
  1079. // Struct for database of generic vendor class based on vendor ID
  1080. //
  1081. typedef struct _PCI_VENDOR_INFORMATION {
  1082. USHORT VendorID;
  1083. PCMCIA_CONTROLLER_CLASS ControllerClass;
  1084. } PCI_VENDOR_INFORMATION, *PPCI_VENDOR_INFORMATION;
  1085. //
  1086. // Tuple packet used to access tuples
  1087. //
  1088. typedef struct _TUPLE_PACKET {
  1089. PSOCKET Socket;
  1090. PSOCKET_DATA SocketData;
  1091. UCHAR TupleCode;
  1092. UCHAR TupleLink;
  1093. UCHAR TupleOffset;
  1094. UCHAR DesiredTuple;
  1095. USHORT Attributes;
  1096. USHORT TupleDataMaxLength;
  1097. USHORT TupleDataIndex;
  1098. PUCHAR TupleData;
  1099. ULONG LinkOffset;
  1100. ULONG CISOffset;
  1101. USHORT TupleDataLength;
  1102. USHORT Flags;
  1103. UCHAR Function;
  1104. } TUPLE_PACKET, * PTUPLE_PACKET;
  1105. //
  1106. // Memory space definitions for accessing CardBus CIS data
  1107. //
  1108. #define PCCARD_CARDBUS_BAR0 0x6e627301
  1109. #define PCCARD_CARDBUS_BAR1 0x6e627302
  1110. #define PCCARD_CARDBUS_BAR2 0x6e627303
  1111. #define PCCARD_CARDBUS_BAR3 0x6e627304
  1112. #define PCCARD_CARDBUS_BAR4 0x6e627305
  1113. #define PCCARD_CARDBUS_BAR5 0x6e627306
  1114. #define PCCARD_CARDBUS_ROM 0x6e627307
  1115. //
  1116. // Chain of resource lists built by PcmciaConfigEntriesToResourceList
  1117. //
  1118. typedef struct _PCMCIA_RESOURCE_CHAIN {
  1119. struct _PCMCIA_RESOURCE_CHAIN *NextList;
  1120. PIO_RESOURCE_LIST IoResList;
  1121. } PCMCIA_RESOURCE_CHAIN, *PPCMCIA_RESOURCE_CHAIN;
  1122. //
  1123. // Linked list of CM_PCCARD_DEVICE_DATA's pulled from the registry
  1124. //
  1125. typedef struct _PCMCIA_NTDETECT_DATA {
  1126. struct _PCMCIA_NTDETECT_DATA *Next;
  1127. CM_PCCARD_DEVICE_DATA PcCardData;
  1128. } PCMCIA_NTDETECT_DATA, *PPCMCIA_NTDETECT_DATA;
  1129. //
  1130. // Poll interval for card status change (in case interrupt not available)
  1131. // Expressed in milliseconds
  1132. //
  1133. #define PCMCIA_CSC_POLL_INTERVAL 1000 // 1 Second
  1134. // The pccard device id prefix
  1135. #define PCMCIA_ID_STRING "PCMCIA"
  1136. // String to be substituted if manufacturer name is not known
  1137. #define PCMCIA_UNKNOWN_MANUFACTURER_STRING "UNKNOWN_MANUFACTURER"
  1138. // Max length of device id
  1139. #define PCMCIA_MAXIMUM_DEVICE_ID_LENGTH 128
  1140. // Pcmcia controller device name
  1141. #define PCMCIA_DEVICE_NAME "\\Device\\Pcmcia"
  1142. // Pcmcia controller device symbolic link name
  1143. #define PCMCIA_LINK_NAME "\\DosDevices\\Pcmcia"
  1144. // PcCard's device name (PDO name)
  1145. #define PCMCIA_PCCARD_NAME "\\Device\\PcCard"
  1146. // Jedec prefix for memory cards
  1147. #define PCMCIA_MEMORY_ID_STRING "MTD"
  1148. //
  1149. // Max no. of pccard instances of a particular device id allowed
  1150. // at a time
  1151. #define PCMCIA_MAX_INSTANCE 100 //arbitrary
  1152. #define PCMCIA_ENABLE_DELAY 10000
  1153. //
  1154. // Number of times we attempt to configure the card before
  1155. // we give up (could be the card has been removed)
  1156. //
  1157. #define PCMCIA_MAX_CONFIG_TRIES 2
  1158. //
  1159. // problems observed on tecra 750 and satellite 300, with dec-chipset cb nic
  1160. //
  1161. #define PCMCIA_CONTROLLER_POWERUP_DELAY 250000 // 250 msec
  1162. //
  1163. // Amount of time to wait after an event interrupt was asserted on the controller
  1164. //
  1165. #define PCMCIA_DEFAULT_EVENT_DPC_DELAY 400000 // 400 msec
  1166. #define PCMCIA_MAX_EVENT_DPC_DELAY 2000000
  1167. //
  1168. // Timeout for deletion locks (secs)
  1169. //
  1170. #define PCMCIA_DELETION_TIMEOUT 20
  1171. //
  1172. // Global Flags
  1173. //
  1174. #define PCMCIA_GLOBAL_FORCE_POLL_MODE 0x00000002 // use polled mode for detecting card insert/remove
  1175. #define PCMCIA_DISABLE_ACPI_NAMESPACE_CHECK 0x00000004 // irq routing test
  1176. #define PCMCIA_DEFAULT_ROUTE_R2_TO_ISA 0x00000008
  1177. //
  1178. // Flags for PcmciaSetSocketPower
  1179. //
  1180. #define PCMCIA_POWERON TRUE
  1181. #define PCMCIA_POWEROFF FALSE
  1182. //
  1183. // This accepts device extension as paramter: need to keep adding to this macro
  1184. // as more PciPcmciaBridges are supported
  1185. //
  1186. #define PciPcmciaBridgeExtension(DeviceExtension) (((DeviceExtension)->ControllerType==PcmciaPciPcmciaBridge) || \
  1187. ((DeviceExtension)->ControllerType==PcmciaCLPD6729))
  1188. // These accept the socket as parameter
  1189. //
  1190. // Cirrus Logic PD6729 PCI-PCMCIA Bridge
  1191. //
  1192. #define CLPD6729(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaCLPD6729))
  1193. //
  1194. // Databook TCIC 16-bit pcmcia controller
  1195. //
  1196. #define Databook(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaDatabook))
  1197. //
  1198. // Compaq Elite controller
  1199. //
  1200. #define Elc(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaElcController))
  1201. //
  1202. // Generic cardbus controller
  1203. //
  1204. #define CardBus(s) (((s)->DeviceExtension) && CardBusExtension((s)->DeviceExtension))
  1205. //
  1206. // Generic PCI-PCMCIA Bridge
  1207. //
  1208. #define PciPcmciaBridge(s) (((s)->DeviceExtension) && PciPcmciaBridgeExtension((s)->DeviceExtension))
  1209. //
  1210. // Macros for manipulating PDO's flags
  1211. //
  1212. #define IsDeviceFlagSet(deviceExtension, Flag) (((deviceExtension)->Flags & (Flag))?TRUE:FALSE)
  1213. #define SetDeviceFlag(deviceExtension, Flag) ((deviceExtension)->Flags |= (Flag))
  1214. #define ResetDeviceFlag(deviceExtension,Flag) ((deviceExtension)->Flags &= ~(Flag))
  1215. #define IsFdoFlagSet(fdoExtension, Flag) (((fdoExtension)->FdoFlags & (Flag))?TRUE:FALSE)
  1216. #define SetFdoFlag(fdoExtension, Flag) ((fdoExtension)->FdoFlags |= (Flag))
  1217. #define ResetFdoFlag(fdoExtension,Flag) ((fdoExtension)->FdoFlags &= ~(Flag))
  1218. #define IsPdoFlagSet(pdoExtension, Flag) (((pdoExtension)->PdoFlags & (Flag))?TRUE:FALSE)
  1219. #define SetPdoFlag(pdoExtension, Flag) ((pdoExtension)->PdoFlags |= (Flag))
  1220. #define ResetPdoFlag(pdoExtension,Flag) ((pdoExtension)->PdoFlags &= ~(Flag))
  1221. #define IsFdoExtension(fdoExtension) (fdoExtension->Signature == PCMCIA_FDO_EXTENSION_SIGNATURE)
  1222. #define IsPdoExtension(pdoExtension) (pdoExtension->Signature == PCMCIA_PDO_EXTENSION_SIGNATURE)
  1223. #define IsSocket(socket) (socket->Signature == PCMCIA_SOCKET_SIGNATURE)
  1224. #define MarkDeviceStarted(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_STARTED)
  1225. #define MarkDeviceNotStarted(deviceExtension) ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_STARTED)
  1226. #define MarkDeviceDeleted(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_DELETED);
  1227. #define MarkDevicePhysicallyRemoved(deviceExtension) \
  1228. ((deviceExtension)->Flags |= PCMCIA_DEVICE_PHYSICALLY_REMOVED)
  1229. #define MarkDevicePhysicallyInserted(deviceExtension) \
  1230. ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_PHYSICALLY_REMOVED)
  1231. #define MarkDeviceLogicallyRemoved(deviceExtension) \
  1232. ((deviceExtension)->Flags |= PCMCIA_DEVICE_LOGICALLY_REMOVED)
  1233. #define MarkDeviceLogicallyInserted(deviceExtension) \
  1234. ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_LOGICALLY_REMOVED)
  1235. #define MarkDeviceCardBus(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_CARDBUS)
  1236. #define MarkDevice16Bit(deviceExtension) ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_CARDBUS)
  1237. #define MarkDeviceMultifunction(deviceExtension) \
  1238. ((deviceExtension)->Flags |= PCMCIA_DEVICE_MULTIFUNCTION)
  1239. #define IsDeviceStarted(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_STARTED)?TRUE:FALSE)
  1240. #define IsDevicePhysicallyRemoved(deviceExtension) \
  1241. (((deviceExtension)->Flags & PCMCIA_DEVICE_PHYSICALLY_REMOVED)?TRUE:FALSE)
  1242. #define IsDeviceLogicallyRemoved(deviceExtension) \
  1243. (((deviceExtension)->Flags & PCMCIA_DEVICE_LOGICALLY_REMOVED)?TRUE:FALSE)
  1244. #define IsDeviceDeleted(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_DELETED)?TRUE:FALSE)
  1245. #define IsDeviceMultifunction(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_MULTIFUNCTION)?TRUE:FALSE)
  1246. #define IsCardBusCard(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?TRUE:FALSE)
  1247. #define Is16BitCard(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?FALSE:TRUE)
  1248. #define CardBusExtension(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?TRUE:FALSE)
  1249. //
  1250. // Macros for checking & setting type of PC-CARD in a socket
  1251. //
  1252. #define IsCardBusCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_CardBusCard)?TRUE:FALSE)
  1253. #define Is16BitCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_R2Card)?TRUE:FALSE)
  1254. #define IsCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_Empty)?FALSE:TRUE)
  1255. #define SetCardBusCardInSocket(SocketPtr) ((SocketPtr)->DeviceState = SKT_CardBusCard)
  1256. #define Set16BitCardInSocket(SocketPtr) ((SocketPtr)->DeviceState = SKT_R2Card)
  1257. #define SetSocketEmpty(SocketPtr) ((SocketPtr)->DeviceState = SKT_Empty)
  1258. //
  1259. // NT definitions
  1260. //
  1261. #ifdef POOL_TAGGING
  1262. #undef ExAllocatePool
  1263. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'cmcP')
  1264. #endif
  1265. #define IO_RESOURCE_LIST_VERSION 0x1
  1266. #define IO_RESOURCE_LIST_REVISION 0x1
  1267. #define IRP_MN_PNP_MAXIMUM_FUNCTION IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  1268. //
  1269. // Some useful macros
  1270. //
  1271. #define MIN(x,y) ((x) > (y) ? (y) : (x)) // return minimum among x & y
  1272. #define MAX(x,y) ((x) > (y) ? (x) : (y)) // return maximum among x & y
  1273. //
  1274. // BOOLEAN
  1275. // IS_PDO (IN PDEVICE_OBJECT DeviceObject);
  1276. //
  1277. #define IS_PDO(DeviceObject) (((DeviceObject)->Flags & DO_BUS_ENUMERATED_DEVICE)?TRUE:FALSE)
  1278. //
  1279. // VOID
  1280. // MARK_AS_PDO (IN PDEVICE_OBJECT DeviceObject);
  1281. //
  1282. #define MARK_AS_PDO(DeviceObject) ((DeviceObject)->Flags |= DO_BUS_ENUMERATED_DEVICE)
  1283. //
  1284. // BOOLEAN
  1285. // PcmciaSetWindowPage(IN FDO_EXTENSION fdoExtension,
  1286. // IN PSOCKET Socket,
  1287. // IN USHORT Index,
  1288. // IN UCHAR Page);
  1289. //
  1290. #define PcmciaSetWindowPage(fdoExtension, Socket, Index, Page) \
  1291. ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage) ? \
  1292. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage)(Socket, Index, Page) : \
  1293. FALSE)
  1294. #define HasWindowPageRegister(fdoExtension) \
  1295. ((BOOLEAN)(DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage))
  1296. //
  1297. // VOID
  1298. // PcmciaSetAudio(
  1299. // IN PSOCKET Socket,
  1300. // IN BOOLEAN enable
  1301. // );
  1302. //
  1303. #define PcmciaSetAudio(fdoExtension, socket, enable) \
  1304. if ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetAudio)) { \
  1305. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetAudio)(socket, enable); \
  1306. }
  1307. //
  1308. // BOOLEAN
  1309. // PcmciaSetZV(
  1310. // IN PSOCKET Socket,
  1311. // IN BOOLEAN enable
  1312. // );
  1313. //
  1314. #define PcmciaSetZV(fdoExtension, socket, enable) \
  1315. ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetZV) ? \
  1316. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetZV)(socket, enable) : \
  1317. FALSE)
  1318. //
  1319. // Io extension macro to just pass on the Irp to a lower driver
  1320. //
  1321. //
  1322. // VOID
  1323. // PcmciaSkipCallLowerDriver(OUT NTSTATUS Status,
  1324. // IN PDEVICE_OBJECT DeviceObject,
  1325. // IN PIRP Irp);
  1326. //
  1327. #define PcmciaSkipCallLowerDriver(Status, DeviceObject, Irp) { \
  1328. IoSkipCurrentIrpStackLocation(Irp); \
  1329. Status = IoCallDriver(DeviceObject,Irp);}
  1330. //
  1331. // VOID
  1332. // PcmciaCopyCallLowerDriver(OUT NTSTATUS Status,
  1333. // IN PDEVICE_OBJECT DeviceObject,
  1334. // IN PIRP Irp);
  1335. //
  1336. #define PcmciaCopyCallLowerDriver(Status, DeviceObject, Irp) { \
  1337. IoCopyCurrentIrpStackLocationToNext(Irp); \
  1338. Status = IoCallDriver(DeviceObject,Irp); }
  1339. // BOOLEAN
  1340. // CompareGuid(
  1341. // IN LPGUID guid1,
  1342. // IN LPGUID guid2
  1343. // );
  1344. #define CompareGuid(g1, g2) ((g1) == (g2) ?TRUE: \
  1345. RtlCompareMemory((g1), \
  1346. (g2), \
  1347. sizeof(GUID)) \
  1348. == sizeof(GUID) \
  1349. )
  1350. //
  1351. // BOOLEAN
  1352. // ValidateController(IN FDO_EXTENSION fdoExtension)
  1353. //
  1354. // Bit of paranoia code. Make sure that the cardbus controller's registers
  1355. // are still visible.
  1356. //
  1357. #define ValidateController(fdoExtension) \
  1358. (CardBusExtension(fdoExtension) ? \
  1359. ((CBReadSocketRegister(fdoExtension->SocketList, CBREG_SKTMASK) & 0xfffffff0) == 0) \
  1360. : TRUE)
  1361. //
  1362. // Registers for accessing indirect access space
  1363. //
  1364. #define IAR_CONTROL_LOW 2
  1365. #define IAR_ADDRESS 4
  1366. #define IAR_DATA 8
  1367. // Flags defined in "Control"
  1368. #define IARF_COMMON 1
  1369. #define IARF_AUTO_INC 2
  1370. #define IARF_BYTE_GRAN 4
  1371. //
  1372. // Vendor specific dispatches for various controllers
  1373. //
  1374. typedef struct _DEVICE_DISPATCH_TABLE {
  1375. //
  1376. // Type of controller for which the dispatches apply
  1377. //
  1378. PCMCIA_CONTROLLER_CLASS ControllerClass;
  1379. //
  1380. // Function to vendor-specific initialize controller
  1381. //
  1382. VOID (*InitController) (IN PFDO_EXTENSION FdoExtension);
  1383. //
  1384. // Vendor specific function to set power for a pc-card
  1385. //
  1386. NTSTATUS
  1387. (*SetPower) (
  1388. IN PSOCKET SocketPtr,
  1389. IN BOOLEAN Enable,
  1390. OUT PULONG pDelayTime
  1391. );
  1392. //
  1393. // Vendor specific function to set/reset Audio
  1394. //
  1395. VOID
  1396. (*SetAudio) (
  1397. IN PSOCKET Socket,
  1398. IN BOOLEAN Enable
  1399. );
  1400. //
  1401. // Vendor specific function to set/reset Zoom Video mode
  1402. //
  1403. BOOLEAN
  1404. (*SetZV) (
  1405. IN PSOCKET Socket,
  1406. IN BOOLEAN Enable
  1407. );
  1408. //
  1409. // Vendor specific function to set page register for memory windows
  1410. //
  1411. BOOLEAN (*SetWindowPage) (IN PSOCKET SocketPtr,
  1412. IN USHORT Index,
  1413. IN UCHAR Page);
  1414. } DEVICE_DISPATCH_TABLE, *PDEVICE_DISPATCH_TABLE;
  1415. //
  1416. // Controller types to hardware/device/compatible id mapping
  1417. //
  1418. typedef struct _PCMCIA_ID_ENTRY {
  1419. PCMCIA_CONTROLLER_TYPE ControllerType;
  1420. PUCHAR Id;
  1421. } PCMCIA_ID_ENTRY, *PPCMCIA_ID_ENTRY;
  1422. //
  1423. // Exca & cardbus register init structure used to
  1424. // initialize the registers on start up
  1425. //
  1426. typedef struct _PCMCIA_REGISTER_INIT {
  1427. //
  1428. // Register offset
  1429. //
  1430. ULONG Register;
  1431. //
  1432. // value: EXCA regs need only a byte,
  1433. // so only the LSB of this field is used for
  1434. // initializing them. Cardbus regs need the
  1435. // entire DWORD
  1436. //
  1437. ULONG Value;
  1438. } PCMCIA_REGISTER_INIT, *PPCMCIA_REGISTER_INIT;
  1439. //
  1440. // Structure which defines special per-device configuration parameters
  1441. //
  1442. typedef struct _PCMCIA_DEVICE_CONFIG_PARAMS {
  1443. UCHAR ValidEntry;
  1444. UCHAR DeviceType;
  1445. USHORT ManufacturerCode;
  1446. USHORT ManufacturerInfo;
  1447. USHORT CisCrc;
  1448. USHORT ConfigDelay1;
  1449. USHORT ConfigDelay2;
  1450. USHORT ConfigDelay3;
  1451. UCHAR ConfigFlags;
  1452. } PCMCIA_DEVICE_CONFIG_PARAMS, *PPCMCIA_DEVICE_CONFIG_PARAMS;
  1453. //
  1454. // Structure which defines what global parameters are read from the registry
  1455. //
  1456. typedef struct _GLOBAL_REGISTRY_INFORMATION {
  1457. PWSTR Name;
  1458. PULONG pValue;
  1459. ULONG Default;
  1460. } GLOBAL_REGISTRY_INFORMATION, *PGLOBAL_REGISTRY_INFORMATION;
  1461. //
  1462. // Defines used both by data.c and registry.c
  1463. //
  1464. #define PCMCIA_REGISTRY_ISA_IRQ_RESCAN_COMPLETE L"IsaIrqRescanComplete"
  1465. #endif //_PCMCIAPRT_