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.

423 lines
8.5 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_PowerDown),
  115. MAP(PPW_SendIrpDown),
  116. MAP(PPW_16BitConfigure),
  117. MAP(PPW_CardBusRefresh),
  118. MAP(PPW_CardBusDelay),
  119. END_STRING_MAP
  120. };
  121. PCMCIA_STRING_MAP PcmciaDbgFdoPowerWorkerStringMap[] = {
  122. MAP(FPW_Stopped),
  123. MAP(FPW_BeginPowerDown),
  124. MAP(FPW_PowerDown),
  125. MAP(FPW_PowerDownSocket),
  126. MAP(FPW_PowerDownComplete),
  127. MAP(FPW_BeginPowerUp),
  128. MAP(FPW_PowerUp),
  129. MAP(FPW_PowerUpSocket),
  130. MAP(FPW_PowerUpSocket2),
  131. MAP(FPW_PowerUpSocketVerify),
  132. MAP(FPW_PowerUpSocketComplete),
  133. MAP(FPW_PowerUpComplete),
  134. MAP(FPW_SendIrpDown),
  135. MAP(FPW_CompleteIrp),
  136. END_STRING_MAP
  137. };
  138. PCMCIA_STRING_MAP PcmciaDbgSocketPowerWorkerStringMap[] = {
  139. MAP(SPW_Stopped),
  140. MAP(SPW_Exit),
  141. MAP(SPW_RequestPower),
  142. MAP(SPW_ReleasePower),
  143. MAP(SPW_SetPowerOn),
  144. MAP(SPW_SetPowerOff),
  145. MAP(SPW_ResetCard),
  146. MAP(SPW_Deconfigure),
  147. END_STRING_MAP
  148. };
  149. PCMCIA_STRING_MAP PcmciaDbgConfigurationWorkerStringMap[] = {
  150. MAP(CW_Stopped),
  151. MAP(CW_InitialState),
  152. MAP(CW_ResetCard),
  153. MAP(CW_Phase1),
  154. MAP(CW_Phase2),
  155. MAP(CW_Phase3),
  156. MAP(CW_Exit),
  157. END_STRING_MAP
  158. };
  159. PCMCIA_STRING_MAP PcmciaDbgTupleStringMap[] = {
  160. MAP(CISTPL_NULL),
  161. MAP(CISTPL_DEVICE),
  162. MAP(CISTPL_INDIRECT),
  163. MAP(CISTPL_CONFIG_CB),
  164. MAP(CISTPL_CFTABLE_ENTRY_CB),
  165. MAP(CISTPL_LONGLINK_MFC),
  166. MAP(CISTPL_CHECKSUM),
  167. MAP(CISTPL_LONGLINK_A),
  168. MAP(CISTPL_LONGLINK_C),
  169. MAP(CISTPL_LINKTARGET),
  170. MAP(CISTPL_NO_LINK),
  171. MAP(CISTPL_VERS_1),
  172. MAP(CISTPL_ALTSTR),
  173. MAP(CISTPL_DEVICE_A),
  174. MAP(CISTPL_JEDEC_C),
  175. MAP(CISTPL_JEDEC_A),
  176. MAP(CISTPL_CONFIG),
  177. MAP(CISTPL_CFTABLE_ENTRY),
  178. MAP(CISTPL_DEVICE_OC),
  179. MAP(CISTPL_DEVICE_OA),
  180. MAP(CISTPL_GEODEVICE),
  181. MAP(CISTPL_GEODEVICE_A),
  182. MAP(CISTPL_MANFID),
  183. MAP(CISTPL_FUNCID),
  184. MAP(CISTPL_FUNCE),
  185. MAP(CISTPL_VERS_2),
  186. MAP(CISTPL_FORMAT),
  187. MAP(CISTPL_GEOMETRY),
  188. MAP(CISTPL_BYTEORDER),
  189. MAP(CISTPL_DATE),
  190. MAP(CISTPL_BATTERY),
  191. MAP(CISTPL_ORG),
  192. MAP(CISTPL_LONGLINK_CB),
  193. MAP(CISTPL_END),
  194. END_STRING_MAP
  195. };
  196. PCMCIA_STRING_MAP PcmciaDbgWakeStateStringMap[] = {
  197. MAP(WAKESTATE_DISARMED),
  198. MAP(WAKESTATE_WAITING),
  199. MAP(WAKESTATE_WAITING_CANCELLED),
  200. MAP(WAKESTATE_ARMED),
  201. MAP(WAKESTATE_ARMING_CANCELLED),
  202. MAP(WAKESTATE_COMPLETING),
  203. END_STRING_MAP
  204. };
  205. PCHAR
  206. PcmciaDbgLookupString(
  207. IN PPCMCIA_STRING_MAP Map,
  208. IN ULONG Id
  209. )
  210. /*++
  211. Routine Description:
  212. Looks up the string associated with Id in string map Map
  213. Arguments:
  214. Map - The string map
  215. Id - The id to lookup
  216. Return Value:
  217. The string
  218. --*/
  219. {
  220. PPCMCIA_STRING_MAP current = Map;
  221. while(current->Id != 0xFFFFFFFF) {
  222. if (current->Id == Id) {
  223. return current->String;
  224. }
  225. current++;
  226. }
  227. return "** UNKNOWN **";
  228. }
  229. VOID
  230. PcmciaDebugPrint(
  231. ULONG DebugMask,
  232. PCCHAR DebugMessage,
  233. ...
  234. )
  235. /*++
  236. Routine Description:
  237. Debug print for the PCMCIA enabler.
  238. Arguments:
  239. Check the mask value to see if the debug message is requested.
  240. Return Value:
  241. None
  242. --*/
  243. {
  244. va_list ap;
  245. char buffer[256];
  246. ULONG i = 0;
  247. va_start(ap, DebugMessage);
  248. strcpy(buffer, "Pcmcia ");
  249. for (i = 0; (MaskStrings[i].Mask != 0); i++) {
  250. if (DebugMask & MaskStrings[i].Mask) {
  251. strcat(buffer, MaskStrings[i].String);
  252. strcat(buffer, ": ");
  253. break;
  254. }
  255. }
  256. if (MaskStrings[i].Mask == 0) {
  257. strcat(buffer, "???: ");
  258. }
  259. if (DebugMask & PcmciaDebugMask) {
  260. vsprintf(&buffer[12], DebugMessage, ap);
  261. DbgPrint(buffer);
  262. }
  263. va_end(ap);
  264. } // end PcmciaDebugPrint()
  265. VOID
  266. PcmciaDumpSocket(
  267. IN PSOCKET Socket
  268. )
  269. {
  270. UCHAR index;
  271. #define MAX_SOCKET_INDEX 64
  272. UCHAR buffer[MAX_SOCKET_INDEX];
  273. for (index = 0; index < MAX_SOCKET_INDEX; index++) {
  274. buffer[index] = PcicReadSocket(Socket, index);
  275. }
  276. for (index = 0; index < 8; index++) {
  277. DebugPrint((PCMCIA_DEBUG_INFO,"%.02x: %.02x\n", index, buffer[index]));
  278. }
  279. for (index = 8; index < MAX_SOCKET_INDEX; index+=2) {
  280. USHORT data;
  281. data = buffer[index] | (buffer[index+1]<<8);
  282. DebugPrint((PCMCIA_DEBUG_INFO,"%.02x: %.04x\n", index, data));
  283. }
  284. }
  285. TRACE_ENTRY GlobalTraceEntry;
  286. VOID
  287. PcmciaWriteTraceEntry(
  288. IN PSOCKET Socket,
  289. IN ULONG Context
  290. )
  291. /*++
  292. Routine Description:
  293. Arguments:
  294. Return Value:
  295. None
  296. --*/
  297. {
  298. UCHAR i;
  299. PTRACE_ENTRY pEntry = &GlobalTraceEntry;
  300. pEntry->Context = Context;
  301. if (CardBusExtension(Socket->DeviceExtension)) {
  302. for (i = 0; i < 5; i++) {
  303. pEntry->CardBusReg[i] = CBReadSocketRegister(Socket, (UCHAR)(i*sizeof(ULONG)));
  304. }
  305. }
  306. for (i = 0; i < 70; i++) {
  307. pEntry->ExcaReg[i] = PcicReadSocket(Socket, i);
  308. }
  309. }
  310. #endif