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.

436 lines
11 KiB

  1. #include "pch.h"
  2. typedef VOID (*PSOFTPCI_TABCTRLUPDATE)(VOID);
  3. VOID
  4. SoftPCI_AddTabCtrlWindow(
  5. IN PWCHAR TabText,
  6. IN PSOFTPCI_TABCTRLUPDATE UpdateTab
  7. );
  8. HWND
  9. SoftPCI_CreateTabCtrlEditWindow(
  10. IN HWND Wnd
  11. );
  12. SoftPCI_ChangeTabSelection(
  13. BOOL IncrementCurrent
  14. );
  15. VOID
  16. SoftPCI_UpdateGeneralTab(
  17. VOID
  18. );
  19. VOID
  20. SoftPCI_UpdateConfigSpaceTab(
  21. VOID
  22. );
  23. VOID
  24. SoftPCI_UpdateResourceTab(
  25. VOID
  26. );
  27. #define MAX_TABS 5
  28. #define EDITWND_BUFFERSIZE 0x8000 //32k
  29. typedef struct _SOFTPCI_TABCTRL{
  30. PSOFTPCI_TABCTRLUPDATE UpdateTab;
  31. } SOFTPCI_TABCTRL, *PSOFTPCI_TABCTRL;
  32. SOFTPCI_TABCTRL g_TabCtrl[MAX_TABS];
  33. HWND g_TabCtrlWnd;
  34. HWND g_EditWnd;
  35. PPCI_DN g_PdnToDisplay;
  36. PWCHAR g_EditWndBuffer;
  37. LONG_PTR g_TabCtrlWndProc;
  38. ULONG g_CurrentTabCount = 0;
  39. ULONG g_CurrentTabSelection = 0;
  40. BOOL g_CtrlKeyDown = FALSE;
  41. BOOL g_ShiftKeyDown = FALSE;
  42. VOID
  43. SoftPCI_AddTabCtrlWindow(
  44. IN PWCHAR TabText,
  45. IN PSOFTPCI_TABCTRLUPDATE UpdateTab
  46. )
  47. {
  48. HWND wndNew;
  49. TC_ITEM tciNew;
  50. tciNew.mask = TCIF_TEXT;
  51. tciNew.iImage = -1;
  52. tciNew.pszText = TabText;
  53. if (g_CurrentTabCount > MAX_TABS) {
  54. SOFTPCI_ASSERT(FALSE);
  55. return;
  56. }
  57. g_TabCtrl[g_CurrentTabCount].UpdateTab = UpdateTab;
  58. TabCtrl_InsertItem(g_TabCtrlWnd, g_CurrentTabCount++, &tciNew) ;
  59. }
  60. SoftPCI_ChangeTabSelection(
  61. BOOL IncrementCurrent
  62. )
  63. {
  64. SoftPCI_Debug(SoftPciProperty, L"ChangeTabSelection - %s\n", (IncrementCurrent == TRUE) ? L"TRUE" : L"FALSE");
  65. if (IncrementCurrent) {
  66. g_CurrentTabSelection++;
  67. if (g_CurrentTabSelection >= g_CurrentTabCount) {
  68. g_CurrentTabSelection = 0;
  69. }
  70. }else{
  71. g_CurrentTabSelection--;
  72. if (g_CurrentTabSelection <= 0) {
  73. g_CurrentTabSelection = g_CurrentTabCount;
  74. }
  75. }
  76. TabCtrl_SetCurSel(g_TabCtrlWnd, g_CurrentTabSelection);
  77. }
  78. HWND
  79. SoftPCI_CreateTabCtrlEditWindow(
  80. IN HWND Wnd
  81. )
  82. {
  83. SOFTPCI_ASSERT(g_EditWndBuffer == NULL);
  84. if ((g_EditWndBuffer = (PWCHAR) calloc(1, EDITWND_BUFFERSIZE)) == NULL){
  85. SoftPCI_Debug(SoftPciProperty, L"CreateTabCtrlEditWindow - Failed to allocate required memory!\n");
  86. return NULL;
  87. }
  88. return CreateWindowEx(
  89. WS_EX_CLIENTEDGE,// | WS_EX_TRANSPARENT,//WS_EX_STATICEDGE
  90. TEXT("EDIT"),
  91. NULL,
  92. WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP |
  93. WS_VSCROLL | WS_HSCROLL | ES_LEFT | ES_MULTILINE |
  94. ES_READONLY,
  95. 0, 0, 0, 0,
  96. Wnd,
  97. (HMENU) IDC_EDITVIEW,
  98. g_Instance,
  99. NULL);
  100. }
  101. HWND
  102. SoftPCI_CreateTabCtrlPane(
  103. IN HWND Wnd
  104. )
  105. {
  106. //
  107. // Create our TabCtrl pane window
  108. //
  109. g_TabCtrlWnd = CreateWindowEx(
  110. WS_EX_CLIENTEDGE,
  111. WC_TABCONTROL,
  112. NULL,
  113. WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  114. 0, 0, 0, 0,
  115. Wnd,
  116. (HMENU) IDC_TABCTL,
  117. g_Instance,
  118. NULL
  119. );
  120. if (g_TabCtrlWnd == NULL){
  121. SoftPCI_Debug(
  122. SoftPciAlways,
  123. L"CreateTabCtrlPane - Failed to create Tab Control! Error - \"%s\"\n",
  124. SoftPCI_GetLastError()
  125. );
  126. return NULL;
  127. }
  128. SoftPCI_SetWindowFont(g_TabCtrlWnd, L"Comic Sans MS");
  129. //
  130. // Insert ourself as a filter to our tab control
  131. //
  132. g_TabCtrlWndProc = GetWindowLongPtr(g_TabCtrlWnd, GWLP_WNDPROC);
  133. if (!SetWindowLongPtr(g_TabCtrlWnd,
  134. GWLP_WNDPROC,
  135. ((LONG_PTR)SoftPCI_TabCtrlWndProc))){
  136. SOFTPCI_ASSERT(FALSE);
  137. return FALSE;
  138. }
  139. //
  140. // Init out edit window and its buffer.
  141. //
  142. g_EditWnd = SoftPCI_CreateTabCtrlEditWindow(Wnd);
  143. if (g_EditWnd == NULL){
  144. SoftPCI_Debug(
  145. SoftPciAlways,
  146. L"CreateTabCtrlPane - Failed to create g_EditWnd! Error - \"%s\"\n",
  147. SoftPCI_GetLastError()
  148. );
  149. return NULL;
  150. }
  151. SoftPCI_SetWindowFont(g_EditWnd, L"Courier New");
  152. SoftPCI_AddTabCtrlWindow(L"General", SoftPCI_UpdateGeneralTab);
  153. SoftPCI_AddTabCtrlWindow(L"Resources", SoftPCI_UpdateResourceTab);
  154. SoftPCI_AddTabCtrlWindow(L"ConfigSpace", SoftPCI_UpdateConfigSpaceTab);
  155. return g_TabCtrlWnd;
  156. }
  157. VOID
  158. SoftPCI_OnTabCtrlSelectionChange(
  159. VOID
  160. )
  161. {
  162. INT currentTabSelection = 0;
  163. SoftPCI_Debug(SoftPciAlways, L"DevPropWndProc - WM_NOTIFY - TCN_SELCHANGE\n");
  164. currentTabSelection = TabCtrl_GetCurSel(g_TabCtrlWnd);
  165. SoftPCI_Debug(SoftPciAlways, L"DevPropWndProc - currentTabSelection = 0x%x\n", currentTabSelection);
  166. if (currentTabSelection == -1) return;
  167. //if (g_CurrentTabSelection == (ULONG) currentTabSelection) return;
  168. g_CurrentTabSelection = (ULONG) currentTabSelection;
  169. g_PdnToDisplay = SoftPCI_GetDnFromTreeItem(NULL);
  170. SoftPCI_UpdateTabCtrlWindow(currentTabSelection);
  171. }
  172. VOID
  173. SoftPCI_SetWindowFont(
  174. IN HWND Wnd,
  175. IN PWCHAR FontName
  176. )
  177. {
  178. HDC hdc;
  179. LOGFONT lf;
  180. HFONT hFont;
  181. hdc = GetDC(NULL);
  182. lf.lfHeight = -9 * GetDeviceCaps(hdc, LOGPIXELSY) / 72;
  183. lf.lfWidth = 0; // Auto
  184. lf.lfEscapement = 0;
  185. lf.lfOrientation = 0;
  186. lf.lfWeight = FF_DONTCARE;
  187. lf.lfItalic = 0;
  188. lf.lfUnderline = 0;
  189. lf.lfStrikeOut = 0;
  190. lf.lfCharSet = ANSI_CHARSET;
  191. lf.lfOutPrecision = OUT_TT_PRECIS;
  192. lf.lfClipPrecision = CLIP_TT_ALWAYS;
  193. lf.lfQuality = DEFAULT_QUALITY;
  194. lf.lfPitchAndFamily = DEFAULT_PITCH;
  195. wcscpy(lf.lfFaceName, FontName);
  196. hFont = CreateFontIndirect(&lf);
  197. ReleaseDC(NULL, hdc);
  198. SendMessage(Wnd, WM_SETFONT, (WORD)hFont, 0L);
  199. }
  200. LRESULT
  201. WINAPI
  202. SoftPCI_TabCtrlWndProc(
  203. IN HWND Wnd,
  204. IN UINT Message,
  205. IN WPARAM wParam,
  206. IN LPARAM lParam
  207. )
  208. {
  209. POINT pt;
  210. switch (Message) {
  211. case WM_NCHITTEST:
  212. //
  213. // Here we filter this message so as to keep the main windows
  214. // from getting them exept for the small left side border of the
  215. // control as we are using that for our SPLIT Pane.
  216. //
  217. pt.x = (SHORT)GET_X_LPARAM(lParam);
  218. ScreenToClient(Wnd, &pt);
  219. if (pt.x <= GetSystemMetrics(SM_CXSIZEFRAME)) {
  220. return CallWindowProc((WNDPROC)g_TabCtrlWndProc, Wnd, Message, wParam, lParam);
  221. }else{
  222. return DefWindowProc(Wnd, Message, wParam, lParam);
  223. }
  224. break;
  225. default:
  226. return CallWindowProc((WNDPROC)g_TabCtrlWndProc, Wnd, Message, wParam, lParam);
  227. }
  228. return 0;
  229. }
  230. VOID
  231. SoftPCI_UpdateGeneralTab(
  232. VOID
  233. )
  234. {
  235. INT len;
  236. ULONG cmProb = 0;
  237. GUID *guid;
  238. LOG_CONF logConf;
  239. PULONG resBuf = NULL;
  240. ULONG resSize = 0;
  241. SoftPCI_GetDeviceNodeProblem(g_PdnToDisplay->DevNode, &cmProb);
  242. wsprintf(g_EditWndBuffer, L"Bus 0x%02x Device 0x%02x Function 0x%02x\r\n\r\n",
  243. g_PdnToDisplay->Bus,
  244. g_PdnToDisplay->Slot.Device,
  245. g_PdnToDisplay->Slot.Function);
  246. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer), L"Dev Inst ID: %s\r\n\r\n", g_PdnToDisplay->DevId);
  247. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer), L"Dev WMI ID: %s\r\n\r\n", g_PdnToDisplay->WmiId);
  248. guid = &g_PdnToDisplay->DevInfoData.ClassGuid;
  249. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer), L"ClassGUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\r\n\r\n",
  250. guid->Data1, guid->Data2, guid->Data3,
  251. guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
  252. guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
  253. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer), L"CM Problem Code:\t%s\r\n\r\n", SoftPCI_CmProblemTable[cmProb]);
  254. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer), L"SoftPCI Private Flags:\t0x%08x\r\n\r\n", g_PdnToDisplay->Flags);
  255. SetWindowText(g_EditWnd, g_EditWndBuffer);
  256. }
  257. VOID
  258. SoftPCI_UpdateConfigSpaceTab(
  259. VOID
  260. )
  261. {
  262. BOOL maskDumped = FALSE;
  263. PPCI_COMMON_CONFIG commonConfig = NULL;
  264. if (g_DriverHandle == NULL) {
  265. wcscpy(g_EditWndBuffer, L"\r\nSoftPCI Support not installed !\r\n");
  266. }else{
  267. //
  268. // Get the current configspace for this device.
  269. //
  270. commonConfig = (PPCI_COMMON_CONFIG) calloc(1, sizeof(PCI_COMMON_CONFIG));
  271. if ((commonConfig != NULL) &&
  272. (SoftPCI_GetCurrentConfigSpace(g_PdnToDisplay, commonConfig))) {
  273. wcscpy(g_EditWndBuffer, L"Current Config:\r\n");
  274. SoftPCI_FormatConfigBuffer(g_EditWndBuffer, commonConfig);
  275. }else{
  276. wcscpy(g_EditWndBuffer,
  277. L"Failed to retrieve current config information\r\n"
  278. L"from the hardware!\r\n\r\n");
  279. }
  280. if ((g_PdnToDisplay->SoftDev) &&
  281. (!g_PdnToDisplay->SoftDev->Config.PlaceHolder)) {
  282. //
  283. //
  284. //
  285. wcscat(g_EditWndBuffer, L"\r\nSoftPCI Mask:\r\n");
  286. SoftPCI_FormatConfigBuffer(g_EditWndBuffer, &g_PdnToDisplay->SoftDev->Config.Mask);
  287. }
  288. }
  289. if (commonConfig) {
  290. free(commonConfig);
  291. }
  292. SetWindowText(g_EditWnd, g_EditWndBuffer);
  293. }
  294. VOID
  295. SoftPCI_UpdateResourceTab(
  296. VOID
  297. )
  298. {
  299. wcscpy(g_EditWndBuffer, L"Current Resources:\r\n");
  300. if (!SoftPCI_GetResources(g_PdnToDisplay, g_EditWndBuffer, ALLOC_LOG_CONF)){
  301. wcscat(g_EditWndBuffer, L"\tNo Resources Assigned\r\n");
  302. }
  303. wcscat(g_EditWndBuffer, L"\r\n");
  304. wsprintf(g_EditWndBuffer + wcslen(g_EditWndBuffer),
  305. L"%s\r\n", L"BootConfig Resources:");
  306. if (!SoftPCI_GetResources(g_PdnToDisplay, g_EditWndBuffer, BOOT_LOG_CONF)){
  307. wcscat(g_EditWndBuffer, L"\tNo BootConfig Available\r\n");
  308. }
  309. wcscat(g_EditWndBuffer, L"\r\n");
  310. SetWindowText(g_EditWnd, g_EditWndBuffer);
  311. }
  312. VOID
  313. SoftPCI_UpdateTabCtrlWindow(
  314. IN INT CurrentSelection
  315. )
  316. {
  317. SoftPCI_Debug(SoftPciProperty, L"UpdateTabCtrlWindow - CurrentSelection = 0x%x\n", CurrentSelection);
  318. if (g_TabCtrl[CurrentSelection].UpdateTab) {
  319. SoftPCI_Debug(SoftPciProperty, L"UpdateTabCtrlWindow - g_TabCtrl[CurrentSelection].UpdateTab = %p\n",
  320. g_TabCtrl[CurrentSelection].UpdateTab);
  321. g_TabCtrl[CurrentSelection].UpdateTab();
  322. }
  323. UpdateWindow(g_TabCtrlWnd);
  324. }