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.

425 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This module provides debugging support.
  7. Author:
  8. Neil Sandlin (neilsa) 10-Aug-98
  9. - code merged from mf.sys and pcmcia.sys
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. //
  14. // Get mappings from status codes to strings
  15. //
  16. #include <ntstatus.dbg>
  17. #undef MAP
  18. #define MAP(_Value) { (_Value), #_Value }
  19. #define END_STRING_MAP { 0xFFFFFFFF, NULL }
  20. #if DBG
  21. typedef struct _DBG_MASK_STRING {
  22. ULONG Mask;
  23. PUCHAR String;
  24. } DBG_MASK_STRING, *PDBG_MASK_STRING;
  25. DBG_MASK_STRING MaskStrings[] = {
  26. PCMCIA_DEBUG_FAIL, "ERR",
  27. PCMCIA_DEBUG_INFO, "INF",
  28. PCMCIA_DEBUG_PNP, "PNP",
  29. PCMCIA_DEBUG_POWER, "PWR",
  30. PCMCIA_DEBUG_SOCKET, "SKT",
  31. PCMCIA_DEBUG_CONFIG, "CFG",
  32. PCMCIA_DEBUG_TUPLES, "TPL",
  33. PCMCIA_DEBUG_RESOURCES, "RES",
  34. PCMCIA_DEBUG_ENUM, "ENU",
  35. PCMCIA_DEBUG_INTERFACE, "IFC",
  36. PCMCIA_DEBUG_IOCTL, "IOC",
  37. PCMCIA_DEBUG_DPC, "DPC",
  38. PCMCIA_DEBUG_ISR, "ISR",
  39. PCMCIA_PCCARD_READY, "PCR",
  40. PCMCIA_DEBUG_DETECT, "DET",
  41. PCMCIA_COUNTERS, "CNT",
  42. PCMCIA_DEBUG_IRQMASK, "MSK",
  43. PCMCIA_DUMP_SOCKET, "DSK",
  44. 0, NULL
  45. };
  46. PPCMCIA_STRING_MAP PcmciaDbgStatusStringMap = (PPCMCIA_STRING_MAP) ntstatusSymbolicNames;
  47. PCMCIA_STRING_MAP PcmciaDbgPnpIrpStringMap[] = {
  48. MAP(IRP_MN_START_DEVICE),
  49. MAP(IRP_MN_QUERY_REMOVE_DEVICE),
  50. MAP(IRP_MN_REMOVE_DEVICE),
  51. MAP(IRP_MN_CANCEL_REMOVE_DEVICE),
  52. MAP(IRP_MN_STOP_DEVICE),
  53. MAP(IRP_MN_QUERY_STOP_DEVICE),
  54. MAP(IRP_MN_CANCEL_STOP_DEVICE),
  55. MAP(IRP_MN_QUERY_DEVICE_RELATIONS),
  56. MAP(IRP_MN_QUERY_INTERFACE),
  57. MAP(IRP_MN_QUERY_CAPABILITIES),
  58. MAP(IRP_MN_QUERY_RESOURCES),
  59. MAP(IRP_MN_QUERY_RESOURCE_REQUIREMENTS),
  60. MAP(IRP_MN_QUERY_DEVICE_TEXT),
  61. MAP(IRP_MN_FILTER_RESOURCE_REQUIREMENTS),
  62. MAP(IRP_MN_READ_CONFIG),
  63. MAP(IRP_MN_WRITE_CONFIG),
  64. MAP(IRP_MN_EJECT),
  65. MAP(IRP_MN_SET_LOCK),
  66. MAP(IRP_MN_QUERY_ID),
  67. MAP(IRP_MN_QUERY_PNP_DEVICE_STATE),
  68. MAP(IRP_MN_QUERY_BUS_INFORMATION),
  69. MAP(IRP_MN_DEVICE_USAGE_NOTIFICATION),
  70. MAP(IRP_MN_SURPRISE_REMOVAL),
  71. MAP(IRP_MN_QUERY_LEGACY_BUS_INFORMATION),
  72. END_STRING_MAP
  73. };
  74. PCMCIA_STRING_MAP PcmciaDbgPoIrpStringMap[] = {
  75. MAP(IRP_MN_WAIT_WAKE),
  76. MAP(IRP_MN_POWER_SEQUENCE),
  77. MAP(IRP_MN_SET_POWER),
  78. MAP(IRP_MN_QUERY_POWER),
  79. END_STRING_MAP
  80. };
  81. PCMCIA_STRING_MAP PcmciaDbgDeviceRelationStringMap[] = {
  82. MAP(BusRelations),
  83. MAP(EjectionRelations),
  84. MAP(PowerRelations),
  85. MAP(RemovalRelations),
  86. MAP(TargetDeviceRelation),
  87. END_STRING_MAP
  88. };
  89. PCMCIA_STRING_MAP PcmciaDbgSystemPowerStringMap[] = {
  90. MAP(PowerSystemUnspecified),
  91. MAP(PowerSystemWorking),
  92. MAP(PowerSystemSleeping1),
  93. MAP(PowerSystemSleeping2),
  94. MAP(PowerSystemSleeping3),
  95. MAP(PowerSystemHibernate),
  96. MAP(PowerSystemShutdown),
  97. MAP(PowerSystemMaximum),
  98. END_STRING_MAP
  99. };
  100. PCMCIA_STRING_MAP PcmciaDbgDevicePowerStringMap[] = {
  101. MAP(PowerDeviceUnspecified),
  102. MAP(PowerDeviceD0),
  103. MAP(PowerDeviceD1),
  104. MAP(PowerDeviceD2),
  105. MAP(PowerDeviceD3),
  106. MAP(PowerDeviceMaximum),
  107. END_STRING_MAP
  108. };
  109. PCMCIA_STRING_MAP PcmciaDbgPdoPowerWorkerStringMap[] = {
  110. MAP(PPW_Stopped),
  111. MAP(PPW_Exit),
  112. MAP(PPW_InitialState),
  113. MAP(PPW_PowerUp),
  114. MAP(PPW_PowerUpComplete),
  115. MAP(PPW_PowerDown),
  116. MAP(PPW_PowerDownComplete),
  117. MAP(PPW_SendIrpDown),
  118. MAP(PPW_16BitConfigure),
  119. MAP(PPW_CardBusRefresh),
  120. MAP(PPW_CardBusDelay),
  121. END_STRING_MAP
  122. };
  123. PCMCIA_STRING_MAP PcmciaDbgFdoPowerWorkerStringMap[] = {
  124. MAP(FPW_Stopped),
  125. MAP(FPW_BeginPowerDown),
  126. MAP(FPW_PowerDown),
  127. MAP(FPW_PowerDownSocket),
  128. MAP(FPW_PowerDownComplete),
  129. MAP(FPW_BeginPowerUp),
  130. MAP(FPW_PowerUp),
  131. MAP(FPW_PowerUpSocket),
  132. MAP(FPW_PowerUpSocket2),
  133. MAP(FPW_PowerUpSocketVerify),
  134. MAP(FPW_PowerUpSocketComplete),
  135. MAP(FPW_PowerUpComplete),
  136. MAP(FPW_SendIrpDown),
  137. MAP(FPW_CompleteIrp),
  138. END_STRING_MAP
  139. };
  140. PCMCIA_STRING_MAP PcmciaDbgSocketPowerWorkerStringMap[] = {
  141. MAP(SPW_Stopped),
  142. MAP(SPW_Exit),
  143. MAP(SPW_RequestPower),
  144. MAP(SPW_ReleasePower),
  145. MAP(SPW_SetPowerOn),
  146. MAP(SPW_SetPowerOff),
  147. MAP(SPW_ResetCard),
  148. MAP(SPW_Deconfigure),
  149. END_STRING_MAP
  150. };
  151. PCMCIA_STRING_MAP PcmciaDbgConfigurationWorkerStringMap[] = {
  152. MAP(CW_Stopped),
  153. MAP(CW_InitialState),
  154. MAP(CW_ResetCard),
  155. MAP(CW_Phase1),
  156. MAP(CW_Phase2),
  157. MAP(CW_Phase3),
  158. MAP(CW_Exit),
  159. END_STRING_MAP
  160. };
  161. PCMCIA_STRING_MAP PcmciaDbgTupleStringMap[] = {
  162. MAP(CISTPL_NULL),
  163. MAP(CISTPL_DEVICE),
  164. MAP(CISTPL_INDIRECT),
  165. MAP(CISTPL_CONFIG_CB),
  166. MAP(CISTPL_CFTABLE_ENTRY_CB),
  167. MAP(CISTPL_LONGLINK_MFC),
  168. MAP(CISTPL_CHECKSUM),
  169. MAP(CISTPL_LONGLINK_A),
  170. MAP(CISTPL_LONGLINK_C),
  171. MAP(CISTPL_LINKTARGET),
  172. MAP(CISTPL_NO_LINK),
  173. MAP(CISTPL_VERS_1),
  174. MAP(CISTPL_ALTSTR),
  175. MAP(CISTPL_DEVICE_A),
  176. MAP(CISTPL_JEDEC_C),
  177. MAP(CISTPL_JEDEC_A),
  178. MAP(CISTPL_CONFIG),
  179. MAP(CISTPL_CFTABLE_ENTRY),
  180. MAP(CISTPL_DEVICE_OC),
  181. MAP(CISTPL_DEVICE_OA),
  182. MAP(CISTPL_GEODEVICE),
  183. MAP(CISTPL_GEODEVICE_A),
  184. MAP(CISTPL_MANFID),
  185. MAP(CISTPL_FUNCID),
  186. MAP(CISTPL_FUNCE),
  187. MAP(CISTPL_VERS_2),
  188. MAP(CISTPL_FORMAT),
  189. MAP(CISTPL_GEOMETRY),
  190. MAP(CISTPL_BYTEORDER),
  191. MAP(CISTPL_DATE),
  192. MAP(CISTPL_BATTERY),
  193. MAP(CISTPL_ORG),
  194. MAP(CISTPL_LONGLINK_CB),
  195. MAP(CISTPL_END),
  196. END_STRING_MAP
  197. };
  198. PCMCIA_STRING_MAP PcmciaDbgWakeStateStringMap[] = {
  199. MAP(WAKESTATE_DISARMED),
  200. MAP(WAKESTATE_WAITING),
  201. MAP(WAKESTATE_WAITING_CANCELLED),
  202. MAP(WAKESTATE_ARMED),
  203. MAP(WAKESTATE_ARMING_CANCELLED),
  204. MAP(WAKESTATE_COMPLETING),
  205. END_STRING_MAP
  206. };
  207. PCHAR
  208. PcmciaDbgLookupString(
  209. IN PPCMCIA_STRING_MAP Map,
  210. IN ULONG Id
  211. )
  212. /*++
  213. Routine Description:
  214. Looks up the string associated with Id in string map Map
  215. Arguments:
  216. Map - The string map
  217. Id - The id to lookup
  218. Return Value:
  219. The string
  220. --*/
  221. {
  222. PPCMCIA_STRING_MAP current = Map;
  223. while(current->Id != 0xFFFFFFFF) {
  224. if (current->Id == Id) {
  225. return current->String;
  226. }
  227. current++;
  228. }
  229. return "** UNKNOWN **";
  230. }
  231. VOID
  232. PcmciaDebugPrint(
  233. ULONG DebugMask,
  234. PCCHAR DebugMessage,
  235. ...
  236. )
  237. /*++
  238. Routine Description:
  239. Debug print for the PCMCIA enabler.
  240. Arguments:
  241. Check the mask value to see if the debug message is requested.
  242. Return Value:
  243. None
  244. --*/
  245. {
  246. va_list ap;
  247. char buffer[256];
  248. ULONG i = 0;
  249. va_start(ap, DebugMessage);
  250. strcpy(buffer, "Pcmcia ");
  251. for (i = 0; (MaskStrings[i].Mask != 0); i++) {
  252. if (DebugMask & MaskStrings[i].Mask) {
  253. strcat(buffer, MaskStrings[i].String);
  254. strcat(buffer, ": ");
  255. break;
  256. }
  257. }
  258. if (MaskStrings[i].Mask == 0) {
  259. strcat(buffer, "???: ");
  260. }
  261. if (DebugMask & PcmciaDebugMask) {
  262. vsprintf(&buffer[12], DebugMessage, ap);
  263. DbgPrint(buffer);
  264. }
  265. va_end(ap);
  266. } // end PcmciaDebugPrint()
  267. VOID
  268. PcmciaDumpSocket(
  269. IN PSOCKET Socket
  270. )
  271. {
  272. UCHAR index;
  273. #define MAX_SOCKET_INDEX 64
  274. UCHAR buffer[MAX_SOCKET_INDEX];
  275. for (index = 0; index < MAX_SOCKET_INDEX; index++) {
  276. buffer[index] = PcicReadSocket(Socket, index);
  277. }
  278. for (index = 0; index < 8; index++) {
  279. DebugPrint((PCMCIA_DEBUG_INFO,"%.02x: %.02x\n", index, buffer[index]));
  280. }
  281. for (index = 8; index < MAX_SOCKET_INDEX; index+=2) {
  282. USHORT data;
  283. data = buffer[index] | (buffer[index+1]<<8);
  284. DebugPrint((PCMCIA_DEBUG_INFO,"%.02x: %.04x\n", index, data));
  285. }
  286. }
  287. TRACE_ENTRY GlobalTraceEntry;
  288. VOID
  289. PcmciaWriteTraceEntry(
  290. IN PSOCKET Socket,
  291. IN ULONG Context
  292. )
  293. /*++
  294. Routine Description:
  295. Arguments:
  296. Return Value:
  297. None
  298. --*/
  299. {
  300. UCHAR i;
  301. PTRACE_ENTRY pEntry = &GlobalTraceEntry;
  302. pEntry->Context = Context;
  303. if (CardBusExtension(Socket->DeviceExtension)) {
  304. for (i = 0; i < 5; i++) {
  305. pEntry->CardBusReg[i] = CBReadSocketRegister(Socket, (UCHAR)(i*sizeof(ULONG)));
  306. }
  307. }
  308. for (i = 0; i < 70; i++) {
  309. pEntry->ExcaReg[i] = PcicReadSocket(Socket, i);
  310. }
  311. }
  312. #endif