Source code of Windows XP (NT5)
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.

1766 lines
52 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_INSERTED_SOUND_PENDING 0x00000200
  433. #define SOCKET_REMOVED_SOUND_PENDING 0x00000400
  434. #define SOCKET_SUPPORT_MESSAGE_SENT 0x00000800
  435. #define SOCKET_MEMORY_WINDOW_ENABLED 0x00001000
  436. #define SOCKET_CARD_STATUS_CHANGE 0x00002000
  437. #define SOCKET_ENUMERATE_PENDING 0x00008000
  438. #define SOCKET_CLEANUP_PENDING 0x00010000
  439. #define SOCKET_CB_ROUTE_R2_TO_PCI 0x00020000
  440. #define SOCKET_POWER_PREFER_3V 0x00040000
  441. #define SOCKET_ENABLED_FOR_CARD_DETECT 0x00080000
  442. #define SOCKET_CLEANUP_MASK (SOCKET_CARD_CONFIGURED | SOCKET_CLEANUP_PENDING)
  443. //
  444. // Socket insertion states
  445. //
  446. #define SKT_Empty 0
  447. #define SKT_CardBusCard 1
  448. #define SKT_R2Card 2
  449. //
  450. // Worker states for socket power operations
  451. //
  452. typedef enum _SPW_STATE {
  453. SPW_Stopped = 0,
  454. SPW_Exit,
  455. SPW_RequestPower,
  456. SPW_ReleasePower,
  457. SPW_SetPowerOn,
  458. SPW_SetPowerOff,
  459. SPW_ResetCard,
  460. SPW_Deconfigure
  461. } SPW_STATE;
  462. //
  463. // Socket structure
  464. //
  465. typedef struct _SOCKET {
  466. struct _SOCKET *NextSocket;
  467. //
  468. // Pointer to the pdo for the pc-card in this socket. This is a linked
  469. // list running through "NextPdoInSocket" in the pdo extension. This list
  470. // represents the functions that are physically contained within a socket.
  471. //
  472. PDEVICE_OBJECT PdoList;
  473. //
  474. // Parent pcmcia controller's fdo extension of this socket
  475. //
  476. struct _FDO_EXTENSION *DeviceExtension;
  477. //
  478. // Pointer to the miniport-like
  479. //
  480. PPCMCIA_CTRL_BLOCK SocketFnPtr;
  481. //
  482. // Flags prefixed SOCKET_ defined above
  483. //
  484. ULONG Flags;
  485. //
  486. // For 16-bit cards we use the i/o address port to read/write
  487. // to the socket registers
  488. // For cardbus cards, we use the CardBus socket register base
  489. //
  490. PUCHAR AddressPort;
  491. KEVENT PCCardReadyEvent;
  492. BOOLEAN ReadyChanged;
  493. //
  494. // Voltage values requested
  495. //
  496. UCHAR Vcc;
  497. UCHAR Vpp1;
  498. UCHAR Vpp2;
  499. //
  500. // Socket states
  501. //
  502. UCHAR DeviceState;
  503. UCHAR Reserved0;
  504. //
  505. // For PCIC controllers: register offset of the socket
  506. //
  507. USHORT RegisterOffset;
  508. //
  509. // PCIC revision
  510. //
  511. UCHAR Revision;
  512. //
  513. // PCIC controllers: zero-based number of the socket
  514. //
  515. UCHAR SocketNumber;
  516. //
  517. // Indicates the number of functions this pc-card has
  518. // (this will be > 1 only for multifunction cards like modem/net combos)
  519. //
  520. UCHAR NumberOfFunctions;
  521. //
  522. // Current memory window used internally for reading attributes
  523. //
  524. UCHAR CurrentMemWindow;
  525. //
  526. // Timer and DPC objects to handle socket power and initialization
  527. //
  528. KTIMER PowerTimer;
  529. KDPC PowerDpc;
  530. //
  531. // Function and parameter to call at the end of power operation
  532. //
  533. PPCMCIA_COMPLETION_ROUTINE PowerCompletionRoutine;
  534. PVOID PowerCompletionContext;
  535. NTSTATUS CallerStatus;
  536. NTSTATUS DeferredStatus;
  537. LONG DeferredStatusLock;
  538. //
  539. // Phase variables control state machine for socket power
  540. //
  541. LONG WorkerBusy;
  542. SPW_STATE WorkerState;
  543. UCHAR PowerPhase;
  544. UCHAR CardResetPhase;
  545. UCHAR Reserved;
  546. //
  547. // PowerData is temporary storage for power "miniports"
  548. //
  549. ULONG PowerData;
  550. //
  551. // semaphore to count # of functions requesting power on this socket
  552. //
  553. LONG PowerRequests;
  554. //
  555. // Context buffers
  556. //
  557. PUCHAR CardbusContextBuffer;
  558. PUCHAR ExcaContextBuffer;
  559. //
  560. // Current IRQ routing settings on socket
  561. //
  562. ULONG IrqMask;
  563. ULONG FdoIrq;
  564. } SOCKET, *PSOCKET;
  565. //
  566. // Lock used for synhing access to device(pcmcia controller registers etc.)
  567. // If the definition for this changes, the following 3 defs for
  568. // acquiring/releasing the locks also may need to change
  569. //
  570. typedef struct _PCMCIA_DEVICE_LOCK {
  571. KSPIN_LOCK Lock;
  572. KIRQL Irql;
  573. } PCMCIA_DEVICE_LOCK, * PPCMCIA_DEVICE_LOCK;
  574. #define PCMCIA_INITIALIZE_DEVICE_LOCK(X) KeInitializeSpinLock(&(X)->DeviceLock.Lock)
  575. #define PCMCIA_ACQUIRE_DEVICE_LOCK(X) KeAcquireSpinLock(&(X)->DeviceLock.Lock, &(X)->DeviceLock.Irql)
  576. #define PCMCIA_ACQUIRE_DEVICE_LOCK_AT_DPC_LEVEL(X) KeAcquireSpinLockAtDpcLevel(&(X)->DeviceLock.Lock)
  577. #define PCMCIA_RELEASE_DEVICE_LOCK(X) KeReleaseSpinLock(&(X)->DeviceLock.Lock, (X)->DeviceLock.Irql)
  578. #define PCMCIA_RELEASE_DEVICE_LOCK_FROM_DPC_LEVEL(X) KeReleaseSpinLockFromDpcLevel(&(X)->DeviceLock.Lock)
  579. #define PCMCIA_TEST_AND_SET(X) (InterlockedCompareExchange(X, 1, 0) == 0)
  580. #define PCMCIA_TEST_AND_RESET(X) (InterlockedCompareExchange(X, 0, 1) == 1)
  581. //
  582. // Wait-Wake states
  583. //
  584. typedef enum {
  585. WAKESTATE_DISARMED,
  586. WAKESTATE_WAITING,
  587. WAKESTATE_WAITING_CANCELLED,
  588. WAKESTATE_ARMED,
  589. WAKESTATE_ARMING_CANCELLED,
  590. WAKESTATE_COMPLETING
  591. } WAKESTATE;
  592. //
  593. // Power Policy Flags
  594. //
  595. #define PCMCIA_PP_WAKE_FROM_D0 0x00000001
  596. #define PCMCIA_PP_D3_ON_IDLE 0x00000002
  597. //
  598. // Functional Device Object's device extension information
  599. //
  600. // There is one device object for each PCMCIA socket controller
  601. // located in the system. This contains the root pointers for
  602. // each of the lists of information on this controller.
  603. //
  604. //
  605. // Flags common to both fdoExtension and pdoExtension
  606. //
  607. #define PCMCIA_DEVICE_STARTED 0x00000001
  608. #define PCMCIA_DEVICE_LOGICALLY_REMOVED 0x00000002
  609. #define PCMCIA_DEVICE_PHYSICALLY_REMOVED 0x00000004
  610. #define PCMCIA_DEVICE_DELETED 0x00000040
  611. #define PCMCIA_DEVICE_CARDBUS 0x00000080
  612. //
  613. // Flags indicating controller state (fdoExtension)
  614. //
  615. #define PCMCIA_DEVICE_LEGACY_DETECTED 0x00000020
  616. #define PCMCIA_FILTER_ADDED_MEMORY 0x00000100
  617. #define PCMCIA_MEMORY_24BIT 0x00000200
  618. #define PCMCIA_CARDBUS_NOT_SUPPORTED 0x00000400
  619. #define PCMCIA_USE_POLLED_CSC 0x00000800
  620. #define PCMCIA_ATTRIBUTE_MEMORY_MAPPED 0x00001000
  621. #define PCMCIA_SOCKET_REGISTER_BASE_MAPPED 0x00002000
  622. #define PCMCIA_INTMODE_COMPAQ 0x00004000
  623. #define PCMCIA_INT_ROUTE_INTERFACE 0x00080000
  624. #define PCMCIA_FDO_CONTEXT_SAVED 0x00100000
  625. #define PCMCIA_FDO_OFFLINE 0x00800000
  626. #define PCMCIA_FDO_ON_DEBUG_PATH 0x01000000
  627. #define PCMCIA_FDO_DISABLE_AUTO_POWEROFF 0x02000000
  628. #define PCMCIA_FDO_PREFER_3V 0x04000000
  629. //
  630. // FDO Flags
  631. //
  632. #define PCMCIA_FDO_IRQ_DETECT_DEVICE_FOUND 0x00000001
  633. #define PCMCIA_FDO_IRQ_DETECT_COMPLETED 0x00000002
  634. #define PCMCIA_FDO_IN_ACPI_NAMESPACE 0x00000004
  635. #define PCMCIA_FDO_FORCE_PCI_ROUTING 0x00000010
  636. #define PCMCIA_FDO_PREFER_PCI_ROUTING 0x00000020
  637. #define PCMCIA_FDO_FORCE_ISA_ROUTING 0x00000040
  638. #define PCMCIA_FDO_PREFER_ISA_ROUTING 0x00000080
  639. #define PCMCIA_FDO_WAKE_BY_CD 0x00000100
  640. //
  641. // states for FdoPowerWorker
  642. //
  643. typedef enum _FDO_POWER_WORKER_STATE {
  644. FPW_Stopped = 0,
  645. FPW_BeginPowerDown,
  646. FPW_PowerDown,
  647. FPW_PowerDownSocket,
  648. FPW_PowerDownComplete,
  649. FPW_BeginPowerUp,
  650. FPW_PowerUp,
  651. FPW_PowerUpSocket,
  652. FPW_PowerUpSocket2,
  653. FPW_PowerUpSocketVerify,
  654. FPW_PowerUpSocketComplete,
  655. FPW_PowerUpComplete,
  656. FPW_SendIrpDown,
  657. FPW_CompleteIrp
  658. } FDO_POWER_WORKER_STATE;
  659. #define FPW_END_SEQUENCE 128
  660. //
  661. // Device extension for the functional device object for pcmcia controllers
  662. //
  663. typedef struct _FDO_EXTENSION {
  664. //
  665. // Pointer to the next pcmcia controller's FDO in the central list
  666. // of all pcmcia controller managed by this driver.
  667. // The head of the list is pointed to by the global variable FdoList
  668. //
  669. PDEVICE_OBJECT NextFdo;
  670. //
  671. // The PDO ejected by the parent bus driver for this pcmcia controller
  672. //
  673. //
  674. PDEVICE_OBJECT Pdo;
  675. //
  676. // The immediately lower device attached beneath the pcmcia controller's FDO.
  677. // This would be the same as the Pdo above, excepting in cases when there are
  678. // lower filter drivers for the pcmcia controller - like the ACPI driver
  679. //
  680. PDEVICE_OBJECT LowerDevice;
  681. //
  682. // Pointer to the list of sockets which hang off this pcmcia controller
  683. //
  684. PSOCKET SocketList;
  685. //
  686. // Various flags used to track the state of this
  687. // (flags prefixed by PCMCIA_ above)
  688. //
  689. ULONG Flags;
  690. //
  691. // FDO specific flags
  692. //
  693. ULONG FdoFlags;
  694. //
  695. // Bus numbering for PCI devices
  696. //
  697. UCHAR PciBusNumber;
  698. UCHAR PciDeviceNumber;
  699. UCHAR PciFunctionNumber;
  700. UCHAR reserved;
  701. //
  702. // Type of the controller. We need to know this since this is
  703. // a monolithic driver. We can do controller specific stuff
  704. // based on the type if needed.
  705. //
  706. PCMCIA_CONTROLLER_TYPE ControllerType;
  707. //
  708. // Index into the device dispatch table for vendor-specific
  709. // controller functions
  710. //
  711. ULONG DeviceDispatchIndex;
  712. PDEVICE_OBJECT DeviceObject;
  713. PDRIVER_OBJECT DriverObject;
  714. PUNICODE_STRING RegistryPath;
  715. //
  716. // Symbolic link name exported for this pcmcia controller
  717. //
  718. UNICODE_STRING LinkName;
  719. //
  720. // Head of the list of child pc-card PDO's hanging off this controller.
  721. // This is a linked list running through "NextPdoInFdoChain" in the pdo
  722. // extension. This list represents the devices that were enumerated by
  723. // the fdo.
  724. //
  725. PDEVICE_OBJECT PdoList;
  726. //
  727. // Keeps track of the number of PDOs which are actually
  728. // valid (not removed). This is primarily used in
  729. // enumeration of the pcmcia controller upon an IRP_MN_QUERY_DEVICE_RELATIONS
  730. //
  731. ULONG LivePdoCount;
  732. //
  733. // Lock for synching device access
  734. //
  735. PCMCIA_DEVICE_LOCK DeviceLock;
  736. //
  737. // Card status change poll related structures
  738. //
  739. //
  740. // Dpc which periodically polls to see if card has been inserted or removed
  741. //
  742. KDPC TimerDpc;
  743. //
  744. // The PollTimer object which is initialized and triggered if a Card Status change
  745. // interrupt is not used & we resort to polling..
  746. //
  747. KTIMER PollTimer;
  748. //
  749. // Kernel objects to defer power up initialization of controller
  750. //
  751. KTIMER PowerTimer;
  752. KDPC PowerDpc;
  753. //
  754. // Kernel objects to handle controller events
  755. //
  756. KTIMER EventTimer;
  757. KDPC EventDpc;
  758. //
  759. // IRQ Mask used in determining which IRQs are allowed for this
  760. // controller & it's child pc-cards.
  761. // 1's in the mask correspond to valid IRQs.
  762. // IRQs are numbered 0 - 15, lsb to msb
  763. // LegacyIrqMask is a fixed masked used if detection fails and PCI routing is disabled
  764. //
  765. USHORT DetectedIrqMask;
  766. USHORT LegacyIrqMask;
  767. //
  768. // Physical address of the attribute memory window used
  769. // read tuples off a pc-card.
  770. //
  771. PHYSICAL_ADDRESS PhysicalBase;
  772. //
  773. // Attribute memory resource requirement limits
  774. //
  775. ULONG AttributeMemoryLow;
  776. ULONG AttributeMemoryHigh;
  777. //
  778. // Size of the attribute memory window requested
  779. //
  780. ULONG AttributeMemorySize;
  781. //
  782. // Alignment of the attribute memory window
  783. //
  784. ULONG AttributeMemoryAlignment;
  785. //
  786. // Virtual address mapped to the attribute memory window (PhysicalBase)
  787. //
  788. PUCHAR AttributeMemoryBase;
  789. //
  790. // Io window limits requested on behalf of pc-cards who
  791. // have flexible i/o resource requirements.
  792. // (default is to request anything from 0 to ffff
  793. // but we could use registry overrides to hack around
  794. // problems
  795. //
  796. ULONG IoLow;
  797. ULONG IoHigh;
  798. //
  799. // Sequence number for event logging
  800. //
  801. ULONG SequenceNumber;
  802. //
  803. // Pointer to the interrupt object - if we use interrupt based
  804. // card status change detection
  805. //
  806. PKINTERRUPT PcmciaInterruptObject;
  807. //
  808. // Power management related stuff.
  809. //
  810. //
  811. // Incremented every time a socket is powered up & decremented
  812. // when it is powered down
  813. //
  814. ULONG NumberOfSocketsPoweredUp;
  815. //
  816. // Current system power state..
  817. //
  818. SYSTEM_POWER_STATE SystemPowerState;
  819. //
  820. // Device power state the pcmcia controller is currently in
  821. //
  822. DEVICE_POWER_STATE DevicePowerState;
  823. //
  824. // Indicates how many children (pc-cards) are pending on an
  825. // IRP_MN_WAIT_WAKE
  826. //
  827. ULONG ChildWaitWakeCount;
  828. //
  829. // Device capabilities as reported by our bus driver
  830. //
  831. DEVICE_CAPABILITIES DeviceCapabilities;
  832. //
  833. // Pending wait wake Irp
  834. //
  835. PIRP WaitWakeIrp;
  836. LONG WaitWakeState;
  837. //
  838. // PC-Card Ready stall parameters
  839. //
  840. ULONG ReadyDelayIter;
  841. ULONG ReadyStall;
  842. //
  843. // Pci config register state
  844. //
  845. PCMCIA_CONTEXT PciContext;
  846. //
  847. // Interface obtained from PCI driver, for cardbus controllers.
  848. // This contains interfaces to enumerate CardBus cards
  849. // (not this interface is private to PCI & PCMCIA.
  850. // No other driver is expected to use these interfaces
  851. //
  852. PCI_CARDBUS_INTERFACE_PRIVATE PciCardBusInterface;
  853. PVOID PciCardBusDeviceContext;
  854. //
  855. // PCI Bus interface standard
  856. // This contains interfaces to read/write from PCI config space
  857. // of the cardbus controller, among other stuff..
  858. //
  859. BUS_INTERFACE_STANDARD PciBusInterface;
  860. //
  861. // PCI Int Route interface standard
  862. // This contains the interface to update the raw interrupt line
  863. // of the cardbus card
  864. //
  865. INT_ROUTE_INTERFACE_STANDARD PciIntRouteInterface;
  866. //
  867. // Configuration resources for the PCMCIA controller
  868. //
  869. PCMCIA_CONFIGURATION_INFORMATION Configuration;
  870. //
  871. // Pending power irp
  872. //
  873. PIRP PendingPowerIrp;
  874. PSOCKET PendingPowerSocket;
  875. //
  876. // Power worker state machine context
  877. //
  878. FDO_POWER_WORKER_STATE *PowerWorkerSequence;
  879. FDO_POWER_WORKER_STATE PowerWorkerState;
  880. UCHAR PowerWorkerPhase;
  881. UCHAR PowerWorkerMaxPhase;
  882. //
  883. // Type of bus we are on
  884. //
  885. INTERFACE_TYPE InterfaceType;
  886. //
  887. // CardBus socket base
  888. //
  889. PUCHAR CardBusSocketRegisterBase;
  890. //
  891. // Size of the socket register base that has been mapped
  892. //
  893. ULONG CardBusSocketRegisterSize;
  894. //
  895. // configuration context
  896. //
  897. PCMCIA_CONTEXT CardbusContext;
  898. PCMCIA_CONTEXT ExcaContext;
  899. PUCHAR PciContextBuffer;
  900. //
  901. // Deferred pdo power irp handling
  902. //
  903. LIST_ENTRY PdoPowerRetryList;
  904. KDPC PdoPowerRetryDpc;
  905. //
  906. // Count to track cardbus PCI interface calls
  907. //
  908. ULONG PciAddCardBusCount;
  909. } FDO_EXTENSION, *PFDO_EXTENSION;
  910. //
  911. // Physical Device Object's device extension information
  912. //
  913. // There is one device object for each function of each
  914. // PC-card in a socket per PCMCIA controller
  915. // in the system. This is referred to as the 'PDO' (physical device
  916. // object)- handled by this bus driver.
  917. //
  918. //
  919. // Flags indicating card state
  920. //
  921. #define PCMCIA_DEVICE_MULTIFUNCTION 0x00000008
  922. #define PCMCIA_DEVICE_WAKE_PENDING 0x00000010
  923. #define PCMCIA_POWER_WORKER_POWERUP 0x00008000
  924. #define PCMCIA_CONFIG_STATUS_DEFERRED 0x00020000
  925. #define PCMCIA_POWER_STATUS_DEFERRED 0x00040000
  926. #define PCMCIA_PDO_ENABLE_AUDIO 0x00200000
  927. #define PCMCIA_PDO_EXCLUSIVE_IRQ 0x00400000
  928. #define PCMCIA_PDO_INDIRECT_CIS 0x00000001
  929. //
  930. // states for PdoPowerWorker
  931. //
  932. typedef enum _PDO_POWER_WORKER_STATE {
  933. PPW_Stopped = 0,
  934. PPW_Exit,
  935. PPW_InitialState,
  936. PPW_PowerUp,
  937. PPW_PowerUpComplete,
  938. PPW_PowerDown,
  939. PPW_PowerDownComplete,
  940. PPW_SendIrpDown,
  941. PPW_16BitConfigure,
  942. PPW_CardBusRefresh,
  943. PPW_CardBusDelay
  944. } PDO_POWER_WORKER_STATE;
  945. //
  946. // phases for ConfigurationWorker
  947. //
  948. typedef enum _CW_STATE {
  949. CW_Stopped = 0,
  950. CW_InitialState,
  951. CW_ResetCard,
  952. CW_Phase1,
  953. CW_Phase2,
  954. CW_Phase3,
  955. CW_Exit
  956. } CW_STATE;
  957. //
  958. // Flags for ConfigurationWorker
  959. //
  960. #define CONFIG_WORKER_APPLY_MODEM_HACK 0x01
  961. //
  962. // Device extension for the physical device object for pcmcia cards
  963. //
  964. typedef struct _PDO_EXTENSION {
  965. PDEVICE_OBJECT DeviceObject;
  966. //
  967. // Link to next pdo in the Fdo's pdo chain
  968. //
  969. PDEVICE_OBJECT NextPdoInFdoChain;
  970. //
  971. // Link to next pdo in the Socket's pdo chain
  972. //
  973. PDEVICE_OBJECT NextPdoInSocket;
  974. //
  975. // Following two declarations valid only for cardbus cards
  976. //
  977. // Device attached just below us
  978. //
  979. PDEVICE_OBJECT LowerDevice;
  980. //
  981. // Actual PDO (owned by PCI) that was enumerated for this
  982. // cardbus card
  983. //
  984. PDEVICE_OBJECT PciPdo;
  985. //
  986. // Cached copy of device id
  987. //
  988. PUCHAR DeviceId;
  989. //
  990. // Pointer to the appropriate socket struc in the parent FDO
  991. //
  992. PSOCKET Socket;
  993. //
  994. // Pointer to the structure assembled by gleaning off tuple data
  995. // from a 16-bit pc-card
  996. //
  997. PSOCKET_DATA SocketData;
  998. //
  999. // Resource configuration assigned to this socket
  1000. //
  1001. PSOCKET_CONFIGURATION SocketConfiguration;
  1002. //
  1003. // Flags prefixed PCMCIA_ above
  1004. //
  1005. ULONG Flags;
  1006. //
  1007. // PDO Flags
  1008. //
  1009. ULONG PdoFlags;
  1010. //
  1011. // Power declarations
  1012. //
  1013. DEVICE_POWER_STATE DevicePowerState;
  1014. SYSTEM_POWER_STATE SystemPowerState;
  1015. //
  1016. // Device Capabilities
  1017. //
  1018. DEVICE_CAPABILITIES DeviceCapabilities;
  1019. //
  1020. // Pending wait wake irp
  1021. //
  1022. PIRP WaitWakeIrp;
  1023. //
  1024. // Other pending power irps
  1025. //
  1026. PIRP PendingPowerIrp;
  1027. //
  1028. // power worker state machine variables
  1029. //
  1030. KTIMER PowerWorkerTimer;
  1031. KDPC PowerWorkerDpc;
  1032. NTSTATUS PowerWorkerDpcStatus;
  1033. PUCHAR PowerWorkerSequence;
  1034. UCHAR PowerWorkerPhase;
  1035. PDO_POWER_WORKER_STATE PowerWorkerState;
  1036. //
  1037. // Timer and DPC objects to handle card enables
  1038. //
  1039. CW_STATE ConfigurationPhase;
  1040. UCHAR ConfigurationFlags;
  1041. KTIMER ConfigurationTimer;
  1042. KDPC ConfigurationDpc;
  1043. NTSTATUS ConfigurationStatus;
  1044. NTSTATUS DeferredConfigurationStatus;
  1045. USHORT ConfigureDelay1;
  1046. USHORT ConfigureDelay2;
  1047. USHORT ConfigureDelay3;
  1048. USHORT Reserved2;
  1049. PPCMCIA_COMPLETION_ROUTINE ConfigCompletionRoutine;
  1050. //
  1051. // PCI Bus interface standard
  1052. // This contains interfaces to read/write from PCI config space
  1053. // of the cardbus card, among other stuff..
  1054. //
  1055. BUS_INTERFACE_STANDARD PciBusInterface; // size 0x20 (32)
  1056. //
  1057. // ID used to check for card changes while powered off
  1058. //
  1059. ULONG CardBusId;
  1060. //
  1061. // CIS cache for reading tuple data
  1062. //
  1063. PUCHAR CisCache;
  1064. MEMORY_SPACE CisCacheSpace;
  1065. ULONG CisCacheBase;
  1066. //
  1067. // Lock for power requests
  1068. //
  1069. LONG SocketPowerRequested;
  1070. //
  1071. // Deletion Mutex
  1072. //
  1073. ULONG DeletionLock;
  1074. } PDO_EXTENSION, *PPDO_EXTENSION;
  1075. //
  1076. // Struct for Database of card bus controller information
  1077. // which maps the vendor id/device id to a CONTROLLER_TYPE
  1078. //
  1079. typedef struct _PCI_CONTROLLER_INFORMATION {
  1080. USHORT VendorID;
  1081. USHORT DeviceID;
  1082. PCMCIA_CONTROLLER_TYPE ControllerType;
  1083. } PCI_CONTROLLER_INFORMATION, *PPCI_CONTROLLER_INFORMATION;
  1084. //
  1085. // Struct for database of generic vendor class based on vendor ID
  1086. //
  1087. typedef struct _PCI_VENDOR_INFORMATION {
  1088. USHORT VendorID;
  1089. PCMCIA_CONTROLLER_CLASS ControllerClass;
  1090. } PCI_VENDOR_INFORMATION, *PPCI_VENDOR_INFORMATION;
  1091. //
  1092. // Tuple packet used to access tuples
  1093. //
  1094. typedef struct _TUPLE_PACKET {
  1095. PSOCKET Socket;
  1096. PSOCKET_DATA SocketData;
  1097. UCHAR TupleCode;
  1098. UCHAR TupleLink;
  1099. UCHAR TupleOffset;
  1100. UCHAR DesiredTuple;
  1101. USHORT Attributes;
  1102. USHORT TupleDataMaxLength;
  1103. USHORT TupleDataIndex;
  1104. PUCHAR TupleData;
  1105. ULONG LinkOffset;
  1106. ULONG CISOffset;
  1107. USHORT TupleDataLength;
  1108. USHORT Flags;
  1109. UCHAR Function;
  1110. } TUPLE_PACKET, * PTUPLE_PACKET;
  1111. //
  1112. // Memory space definitions for accessing CardBus CIS data
  1113. //
  1114. #define PCCARD_CARDBUS_BAR0 0x6e627301
  1115. #define PCCARD_CARDBUS_BAR1 0x6e627302
  1116. #define PCCARD_CARDBUS_BAR2 0x6e627303
  1117. #define PCCARD_CARDBUS_BAR3 0x6e627304
  1118. #define PCCARD_CARDBUS_BAR4 0x6e627305
  1119. #define PCCARD_CARDBUS_BAR5 0x6e627306
  1120. #define PCCARD_CARDBUS_ROM 0x6e627307
  1121. //
  1122. // Chain of resource lists built by PcmciaConfigEntriesToResourceList
  1123. //
  1124. typedef struct _PCMCIA_RESOURCE_CHAIN {
  1125. struct _PCMCIA_RESOURCE_CHAIN *NextList;
  1126. PIO_RESOURCE_LIST IoResList;
  1127. } PCMCIA_RESOURCE_CHAIN, *PPCMCIA_RESOURCE_CHAIN;
  1128. //
  1129. // Linked list of CM_PCCARD_DEVICE_DATA's pulled from the registry
  1130. //
  1131. typedef struct _PCMCIA_NTDETECT_DATA {
  1132. struct _PCMCIA_NTDETECT_DATA *Next;
  1133. CM_PCCARD_DEVICE_DATA PcCardData;
  1134. } PCMCIA_NTDETECT_DATA, *PPCMCIA_NTDETECT_DATA;
  1135. //
  1136. // Poll interval for card status change (in case interrupt not available)
  1137. // Expressed in milliseconds
  1138. //
  1139. #define PCMCIA_CSC_POLL_INTERVAL 1000 // 1 Second
  1140. // Maximum no. of fucntions in a multi-function pc-card supported
  1141. #define PCMCIA_MAX_MFC 3
  1142. // The pccard device id prefix
  1143. #define PCMCIA_ID_STRING "PCMCIA"
  1144. // String to be substituted if manufacturer name is not known
  1145. #define PCMCIA_UNKNOWN_MANUFACTURER_STRING "UNKNOWN_MANUFACTURER"
  1146. // Max length of device id
  1147. #define PCMCIA_MAXIMUM_DEVICE_ID_LENGTH 128
  1148. // Pcmcia controller device name
  1149. #define PCMCIA_DEVICE_NAME "\\Device\\Pcmcia"
  1150. // Pcmcia controller device symbolic link name
  1151. #define PCMCIA_LINK_NAME "\\DosDevices\\Pcmcia"
  1152. // PcCard's device name (PDO name)
  1153. #define PCMCIA_PCCARD_NAME "\\Device\\PcCard"
  1154. // Jedec prefix for memory cards
  1155. #define PCMCIA_MEMORY_ID_STRING "MTD"
  1156. //
  1157. // Max no. of pccard instances of a particular device id allowed
  1158. // at a time
  1159. #define PCMCIA_MAX_INSTANCE 100 //arbitrary
  1160. #define PCMCIA_ENABLE_DELAY 10000
  1161. //
  1162. // Number of times we attempt to configure the card before
  1163. // we give up (could be the card has been removed)
  1164. //
  1165. #define PCMCIA_MAX_CONFIG_TRIES 2
  1166. //
  1167. // problems observed on tecra 750 and satellite 300, with dec-chipset cb nic
  1168. //
  1169. #define PCMCIA_DEFAULT_CONTROLLER_POWERUP_DELAY 250000 // 250 msec
  1170. //
  1171. // Amount of time to wait after an event interrupt was asserted on the controller
  1172. //
  1173. #define PCMCIA_DEFAULT_EVENT_DPC_DELAY 400000 // 400 msec
  1174. //
  1175. // Global Flags
  1176. //
  1177. #define PCMCIA_GLOBAL_SOUNDS_ENABLED 0x00000001 // beep on card insertion/removal
  1178. #define PCMCIA_GLOBAL_FORCE_POLL_MODE 0x00000002 // use polled mode for detecting card insert/remove
  1179. #define PCMCIA_DISABLE_ACPI_NAMESPACE_CHECK 0x00000004 // irq routing test
  1180. #define PCMCIA_DEFAULT_ROUTE_R2_TO_ISA 0x00000008
  1181. //
  1182. // Flags for PcmciaSetSocketPower
  1183. //
  1184. #define PCMCIA_POWERON TRUE
  1185. #define PCMCIA_POWEROFF FALSE
  1186. //
  1187. // This accepts device extension as paramter: need to keep adding to this macro
  1188. // as more PciPcmciaBridges are supported
  1189. //
  1190. #define PciPcmciaBridgeExtension(DeviceExtension) (((DeviceExtension)->ControllerType==PcmciaPciPcmciaBridge) || \
  1191. ((DeviceExtension)->ControllerType==PcmciaCLPD6729))
  1192. // These accept the socket as parameter
  1193. //
  1194. // Cirrus Logic PD6729 PCI-PCMCIA Bridge
  1195. //
  1196. #define CLPD6729(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaCLPD6729))
  1197. //
  1198. // Databook TCIC 16-bit pcmcia controller
  1199. //
  1200. #define Databook(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaDatabook))
  1201. //
  1202. // Compaq Elite controller
  1203. //
  1204. #define Elc(s) (((s)->DeviceExtension) && ((s)->DeviceExtension->ControllerType==PcmciaElcController))
  1205. //
  1206. // Generic cardbus controller
  1207. //
  1208. #define CardBus(s) (((s)->DeviceExtension) && CardBusExtension((s)->DeviceExtension))
  1209. //
  1210. // Generic PCI-PCMCIA Bridge
  1211. //
  1212. #define PciPcmciaBridge(s) (((s)->DeviceExtension) && PciPcmciaBridgeExtension((s)->DeviceExtension))
  1213. //
  1214. // Macros for manipulating PDO's flags
  1215. //
  1216. #define IsDeviceFlagSet(deviceExtension, Flag) (((deviceExtension)->Flags & (Flag))?TRUE:FALSE)
  1217. #define SetDeviceFlag(deviceExtension, Flag) ((deviceExtension)->Flags |= (Flag))
  1218. #define ResetDeviceFlag(deviceExtension,Flag) ((deviceExtension)->Flags &= ~(Flag))
  1219. #define IsFdoFlagSet(fdoExtension, Flag) (((fdoExtension)->FdoFlags & (Flag))?TRUE:FALSE)
  1220. #define SetFdoFlag(fdoExtension, Flag) ((fdoExtension)->FdoFlags |= (Flag))
  1221. #define ResetFdoFlag(fdoExtension,Flag) ((fdoExtension)->FdoFlags &= ~(Flag))
  1222. #define IsPdoFlagSet(pdoExtension, Flag) (((pdoExtension)->PdoFlags & (Flag))?TRUE:FALSE)
  1223. #define SetPdoFlag(pdoExtension, Flag) ((pdoExtension)->PdoFlags |= (Flag))
  1224. #define ResetPdoFlag(pdoExtension,Flag) ((pdoExtension)->PdoFlags &= ~(Flag))
  1225. #define MarkDeviceStarted(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_STARTED)
  1226. #define MarkDeviceNotStarted(deviceExtension) ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_STARTED)
  1227. #define MarkDeviceDeleted(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_DELETED);
  1228. #define MarkDevicePhysicallyRemoved(deviceExtension) \
  1229. ((deviceExtension)->Flags |= PCMCIA_DEVICE_PHYSICALLY_REMOVED)
  1230. #define MarkDevicePhysicallyInserted(deviceExtension) \
  1231. ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_PHYSICALLY_REMOVED)
  1232. #define MarkDeviceLogicallyRemoved(deviceExtension) \
  1233. ((deviceExtension)->Flags |= PCMCIA_DEVICE_LOGICALLY_REMOVED)
  1234. #define MarkDeviceLogicallyInserted(deviceExtension) \
  1235. ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_LOGICALLY_REMOVED)
  1236. #define MarkDeviceCardBus(deviceExtension) ((deviceExtension)->Flags |= PCMCIA_DEVICE_CARDBUS)
  1237. #define MarkDevice16Bit(deviceExtension) ((deviceExtension)->Flags &= ~PCMCIA_DEVICE_CARDBUS)
  1238. #define MarkDeviceMultifunction(deviceExtension) \
  1239. ((deviceExtension)->Flags |= PCMCIA_DEVICE_MULTIFUNCTION)
  1240. #define IsDeviceStarted(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_STARTED)?TRUE:FALSE)
  1241. #define IsDevicePhysicallyRemoved(deviceExtension) \
  1242. (((deviceExtension)->Flags & PCMCIA_DEVICE_PHYSICALLY_REMOVED)?TRUE:FALSE)
  1243. #define IsDeviceLogicallyRemoved(deviceExtension) \
  1244. (((deviceExtension)->Flags & PCMCIA_DEVICE_LOGICALLY_REMOVED)?TRUE:FALSE)
  1245. #define IsDeviceDeleted(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_DELETED)?TRUE:FALSE)
  1246. #define IsDeviceMultifunction(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_MULTIFUNCTION)?TRUE:FALSE)
  1247. #define IsCardBusCard(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?TRUE:FALSE)
  1248. #define Is16BitCard(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?FALSE:TRUE)
  1249. #define CardBusExtension(deviceExtension) (((deviceExtension)->Flags & PCMCIA_DEVICE_CARDBUS)?TRUE:FALSE)
  1250. //
  1251. // Macros for checking & setting type of PC-CARD in a socket
  1252. //
  1253. #define IsCardBusCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_CardBusCard)?TRUE:FALSE)
  1254. #define Is16BitCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_R2Card)?TRUE:FALSE)
  1255. #define IsCardInSocket(SocketPtr) (((SocketPtr)->DeviceState == SKT_Empty)?FALSE:TRUE)
  1256. #define SetCardBusCardInSocket(SocketPtr) ((SocketPtr)->DeviceState = SKT_CardBusCard)
  1257. #define Set16BitCardInSocket(SocketPtr) ((SocketPtr)->DeviceState = SKT_R2Card)
  1258. #define SetSocketEmpty(SocketPtr) ((SocketPtr)->DeviceState = SKT_Empty)
  1259. //
  1260. // NT definitions
  1261. //
  1262. #ifdef POOL_TAGGING
  1263. #undef ExAllocatePool
  1264. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'cmcP')
  1265. #endif
  1266. #define IO_RESOURCE_LIST_VERSION 0x1
  1267. #define IO_RESOURCE_LIST_REVISION 0x1
  1268. #define IRP_MN_PNP_MAXIMUM_FUNCTION IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  1269. //
  1270. // Some useful macros
  1271. //
  1272. #define MIN(x,y) ((x) > (y) ? (y) : (x)) // return minimum among x & y
  1273. #define MAX(x,y) ((x) > (y) ? (x) : (y)) // return maximum among x & y
  1274. //
  1275. // BOOLEAN
  1276. // IS_PDO (IN PDEVICE_OBJECT DeviceObject);
  1277. //
  1278. #define IS_PDO(DeviceObject) (((DeviceObject)->Flags & DO_BUS_ENUMERATED_DEVICE)?TRUE:FALSE)
  1279. //
  1280. // VOID
  1281. // MARK_AS_PDO (IN PDEVICE_OBJECT DeviceObject);
  1282. //
  1283. #define MARK_AS_PDO(DeviceObject) ((DeviceObject)->Flags |= DO_BUS_ENUMERATED_DEVICE)
  1284. //
  1285. // Checks if Ptr is aligned on a boundary of 2^Size
  1286. //
  1287. // BOOLEAN
  1288. // IS_ALIGNED (IN PVOID Ptr,
  1289. // IN ULONG Size);
  1290. //
  1291. #define IS_ALIGNED(Ptr,Size) \
  1292. (((((ULONG)(Ptr)) & (((ULONG) (1<<(Size)) - 1)) ) == 0) ? TRUE : FALSE )
  1293. //
  1294. // BOOLEAN
  1295. // PcmciaSetWindowPage(IN FDO_EXTENSION fdoExtension,
  1296. // IN PSOCKET Socket,
  1297. // IN USHORT Index,
  1298. // IN UCHAR Page);
  1299. //
  1300. #define PcmciaSetWindowPage(fdoExtension, Socket, Index, Page) \
  1301. ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage) ? \
  1302. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage)(Socket, Index, Page) : \
  1303. FALSE)
  1304. #define HasWindowPageRegister(fdoExtension) \
  1305. ((BOOLEAN)(DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetWindowPage))
  1306. //
  1307. // VOID
  1308. // PcmciaSetAudio(
  1309. // IN PSOCKET Socket,
  1310. // IN BOOLEAN enable
  1311. // );
  1312. //
  1313. #define PcmciaSetAudio(fdoExtension, socket, enable) \
  1314. if ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetAudio)) { \
  1315. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetAudio)(socket, enable); \
  1316. }
  1317. //
  1318. // BOOLEAN
  1319. // PcmciaSetZV(
  1320. // IN PSOCKET Socket,
  1321. // IN BOOLEAN enable
  1322. // );
  1323. //
  1324. #define PcmciaSetZV(fdoExtension, socket, enable) \
  1325. ((DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetZV) ? \
  1326. (*DeviceDispatchTable[fdoExtension->DeviceDispatchIndex].SetZV)(socket, enable) : \
  1327. FALSE)
  1328. //
  1329. // Io extension macro to just pass on the Irp to a lower driver
  1330. //
  1331. //
  1332. // VOID
  1333. // PcmciaSkipCallLowerDriver(OUT NTSTATUS Status,
  1334. // IN PDEVICE_OBJECT DeviceObject,
  1335. // IN PIRP Irp);
  1336. //
  1337. #define PcmciaSkipCallLowerDriver(Status, DeviceObject, Irp) { \
  1338. IoSkipCurrentIrpStackLocation(Irp); \
  1339. Status = IoCallDriver(DeviceObject,Irp);}
  1340. //
  1341. // VOID
  1342. // PcmciaCopyCallLowerDriver(OUT NTSTATUS Status,
  1343. // IN PDEVICE_OBJECT DeviceObject,
  1344. // IN PIRP Irp);
  1345. //
  1346. #define PcmciaCopyCallLowerDriver(Status, DeviceObject, Irp) { \
  1347. IoCopyCurrentIrpStackLocationToNext(Irp); \
  1348. Status = IoCallDriver(DeviceObject,Irp); }
  1349. // BOOLEAN
  1350. // CompareGuid(
  1351. // IN LPGUID guid1,
  1352. // IN LPGUID guid2
  1353. // );
  1354. #define CompareGuid(g1, g2) ((g1) == (g2) ?TRUE: \
  1355. RtlCompareMemory((g1), \
  1356. (g2), \
  1357. sizeof(GUID)) \
  1358. == sizeof(GUID) \
  1359. )
  1360. //
  1361. // VOID
  1362. // PcmciaDoStartSound(
  1363. // IN PSOCKET Socket,
  1364. // IN NTSTATUS Status);
  1365. //
  1366. #define PcmciaDoStartSound(Socket, Status) { \
  1367. if (NT_SUCCESS(Status)) { \
  1368. if (IsSocketFlagSet(Socket, SOCKET_INSERTED_SOUND_PENDING)) { \
  1369. ResetSocketFlag(Socket, SOCKET_INSERTED_SOUND_PENDING); \
  1370. PcmciaPlaySound(CARD_INSERTED_SOUND); \
  1371. } \
  1372. SetSocketFlag(Socket, SOCKET_REMOVED_SOUND_PENDING); \
  1373. } else { \
  1374. PcmciaPlaySound(ERROR_SOUND); \
  1375. } \
  1376. }
  1377. //
  1378. // BOOLEAN
  1379. // ValidateController(IN FDO_EXTENSION fdoExtension)
  1380. //
  1381. // Bit of paranoia code. Make sure that the cardbus controller's registers
  1382. // are still visible.
  1383. //
  1384. #define ValidateController(fdoExtension) \
  1385. (CardBusExtension(fdoExtension) ? \
  1386. ((CBReadSocketRegister(fdoExtension->SocketList, CBREG_SKTMASK) & 0xfffffff0) == 0) \
  1387. : TRUE)
  1388. //
  1389. // These are the types of tones used on card pnp events
  1390. //
  1391. typedef enum _PCMCIA_SOUND_TYPE {
  1392. CARD_INSERTED_SOUND,
  1393. CARD_REMOVED_SOUND,
  1394. ERROR_SOUND
  1395. } PCMCIA_SOUND_TYPE, *PPCMCIA_SOUND_TYPE;
  1396. typedef struct _PCMCIA_SOUND_EVENT {
  1397. struct _PCMCIA_SOUND_EVENT *NextEvent;
  1398. ULONG Frequency;
  1399. ULONG Duration;
  1400. } PCMCIA_SOUND_EVENT, *PPCMCIA_SOUND_EVENT;
  1401. //
  1402. // CARDBUS Bridge specific header portion in PCI Config space
  1403. //
  1404. #define CARDBUS_SPECIFIC_HDR_OFFSET 0x40
  1405. typedef struct _CARDBUS_SPECIFIC_HDR {
  1406. USHORT SubSystemVendorID;
  1407. USHORT SubSystemID;
  1408. ULONG LegacyBaseAddress;
  1409. UCHAR Reserved1[56];
  1410. ULONG SystemCtrlReg;
  1411. UCHAR MultimediaControl;
  1412. UCHAR Reserved2[3];
  1413. UCHAR GPIO0;
  1414. UCHAR GPIO1;
  1415. UCHAR GPIO2;
  1416. UCHAR GPIO3;
  1417. ULONG IRQMux;
  1418. UCHAR RetryStatus;
  1419. UCHAR CardCtrl;
  1420. UCHAR DeviceCtrl;
  1421. UCHAR Diagnostic;
  1422. ULONG SocketDMAReg0;
  1423. ULONG SocketDMAReg1;
  1424. } CARDBUS_SPECIFIC_HDR, *PCARDBUS_SPECIFIC_HDR;
  1425. //
  1426. // Registers for accessing indirect access space
  1427. //
  1428. #define IAR_CONTROL_LOW 2
  1429. #define IAR_ADDRESS 4
  1430. #define IAR_DATA 8
  1431. // Flags defined in "Control"
  1432. #define IARF_COMMON 1
  1433. #define IARF_AUTO_INC 2
  1434. #define IARF_BYTE_GRAN 4
  1435. //
  1436. // Vendor specific dispatches for various controllers
  1437. //
  1438. typedef struct _DEVICE_DISPATCH_TABLE {
  1439. //
  1440. // Type of controller for which the dispatches apply
  1441. //
  1442. PCMCIA_CONTROLLER_CLASS ControllerClass;
  1443. //
  1444. // Function to vendor-specific initialize controller
  1445. //
  1446. VOID (*InitController) (IN PFDO_EXTENSION FdoExtension);
  1447. //
  1448. // Vendor specific function to set power for a pc-card
  1449. //
  1450. NTSTATUS
  1451. (*SetPower) (
  1452. IN PSOCKET SocketPtr,
  1453. IN BOOLEAN Enable,
  1454. OUT PULONG pDelayTime
  1455. );
  1456. //
  1457. // Vendor specific function to set/reset Audio
  1458. //
  1459. VOID
  1460. (*SetAudio) (
  1461. IN PSOCKET Socket,
  1462. IN BOOLEAN Enable
  1463. );
  1464. //
  1465. // Vendor specific function to set/reset Zoom Video mode
  1466. //
  1467. BOOLEAN
  1468. (*SetZV) (
  1469. IN PSOCKET Socket,
  1470. IN BOOLEAN Enable
  1471. );
  1472. //
  1473. // Vendor specific function to set page register for memory windows
  1474. //
  1475. BOOLEAN (*SetWindowPage) (IN PSOCKET SocketPtr,
  1476. IN USHORT Index,
  1477. IN UCHAR Page);
  1478. } DEVICE_DISPATCH_TABLE, *PDEVICE_DISPATCH_TABLE;
  1479. //
  1480. // Controller types to hardware/device/compatible id mapping
  1481. //
  1482. typedef struct _PCMCIA_ID_ENTRY {
  1483. PCMCIA_CONTROLLER_TYPE ControllerType;
  1484. PUCHAR Id;
  1485. } PCMCIA_ID_ENTRY, *PPCMCIA_ID_ENTRY;
  1486. //
  1487. // Exca & cardbus register init structure used to
  1488. // initialize the registers on start up
  1489. //
  1490. typedef struct _PCMCIA_REGISTER_INIT {
  1491. //
  1492. // Register offset
  1493. //
  1494. ULONG Register;
  1495. //
  1496. // value: EXCA regs need only a byte,
  1497. // so only the LSB of this field is used for
  1498. // initializing them. Cardbus regs need the
  1499. // entire DWORD
  1500. //
  1501. ULONG Value;
  1502. } PCMCIA_REGISTER_INIT, *PPCMCIA_REGISTER_INIT;
  1503. //
  1504. // Structure which defines special per-device configuration parameters
  1505. //
  1506. typedef struct _PCMCIA_DEVICE_CONFIG_PARAMS {
  1507. UCHAR ValidEntry;
  1508. UCHAR DeviceType;
  1509. USHORT ManufacturerCode;
  1510. USHORT ManufacturerInfo;
  1511. USHORT CisCrc;
  1512. USHORT ConfigDelay1;
  1513. USHORT ConfigDelay2;
  1514. USHORT ConfigDelay3;
  1515. UCHAR ConfigFlags;
  1516. } PCMCIA_DEVICE_CONFIG_PARAMS, *PPCMCIA_DEVICE_CONFIG_PARAMS;
  1517. //
  1518. // Structure which defines what global parameters are read from the registry
  1519. //
  1520. typedef struct _GLOBAL_REGISTRY_INFORMATION {
  1521. PWSTR Name;
  1522. PULONG pValue;
  1523. ULONG Default;
  1524. } GLOBAL_REGISTRY_INFORMATION, *PGLOBAL_REGISTRY_INFORMATION;
  1525. //
  1526. // Defines used both by data.c and registry.c
  1527. //
  1528. #define PCMCIA_REGISTRY_ISA_IRQ_RESCAN_COMPLETE L"IsaIrqRescanComplete"
  1529. #endif //_PCMCIAPRT_