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.

1347 lines
35 KiB

  1. #include "pch.h"
  2. #include "dialogp.h"
  3. HWND g_NewDevDlg;
  4. PSOFTPCI_DEVICE g_NewDevice;
  5. PHPS_HWINIT_DESCRIPTOR g_HPSInitDesc;
  6. PPCI_DN g_ParentPdn;
  7. ULONG g_PossibleDeviceNums;
  8. #define HPS_HWINIT_OFFSET 0x4a
  9. #define HPS_MAX_SLOTS 0x1f //Max number of slots for each type
  10. #define HPS_MAX_SLOT_LABEL 0xff //Max number to start slot labeling
  11. struct _BAR_CONTROL{
  12. INT tb;
  13. INT mrb;
  14. INT irb;
  15. INT pref;
  16. INT bit64;
  17. INT tx;
  18. ULONG Bar;
  19. }BarControl[PCI_TYPE0_ADDRESSES] = {
  20. {IDC_BAR0_TB, IDC_BAR0MEM_RB, IDC_BAR0IO_RB, IDC_BAR0_PREF_XB, IDC_BAR0_64BIT_XB, IDC_SLIDER0_TX, 0},
  21. {IDC_BAR1_TB, IDC_BAR1MEM_RB, IDC_BAR1IO_RB, IDC_BAR1_PREF_XB, IDC_BAR1_64BIT_XB, IDC_SLIDER1_TX, 0},
  22. {IDC_BAR2_TB, IDC_BAR2MEM_RB, IDC_BAR2IO_RB, IDC_BAR2_PREF_XB, IDC_BAR2_64BIT_XB, IDC_SLIDER2_TX, 0},
  23. {IDC_BAR3_TB, IDC_BAR3MEM_RB, IDC_BAR3IO_RB, IDC_BAR3_PREF_XB, IDC_BAR3_64BIT_XB, IDC_SLIDER3_TX, 0},
  24. {IDC_BAR4_TB, IDC_BAR4MEM_RB, IDC_BAR4IO_RB, IDC_BAR4_PREF_XB, IDC_BAR4_64BIT_XB, IDC_SLIDER4_TX, 0},
  25. {IDC_BAR5_TB, IDC_BAR5MEM_RB, IDC_BAR5IO_RB, IDC_BAR5_PREF_XB, 0, IDC_SLIDER5_TX, 0 }
  26. };
  27. INT_PTR
  28. CALLBACK
  29. SoftPCI_NewDevDlgProc(
  30. IN HWND Dlg,
  31. IN UINT Msg,
  32. IN WPARAM wParam,
  33. IN LPARAM lParam
  34. )
  35. /*++
  36. Routine Description:
  37. Dialog handling routine for new device creation
  38. Arguments:
  39. Return Value:
  40. --*/
  41. {
  42. BOOL rc = FALSE;
  43. LONG width, height, i;
  44. RECT mainRect, dlgRect;
  45. HWND devtype;
  46. WCHAR buffer[256];
  47. LONG_PTR dlgstyle;
  48. PPCI_DN pdn = (PPCI_DN)lParam;
  49. PPCI_DN bridgePdn;
  50. PHPS_HWINIT_DESCRIPTOR hotplugData;
  51. switch ( Msg ) {
  52. case WM_INITDIALOG:
  53. SOFTPCI_ASSERT(pdn != NULL);
  54. if (pdn == NULL) {
  55. PostMessage(Dlg, WM_CLOSE, 0, 0);
  56. break;
  57. }
  58. //
  59. // Allocate a new device. We will fill this out as the user selects
  60. // options.
  61. //
  62. g_NewDevice = (PSOFTPCI_DEVICE) calloc(1, sizeof(SOFTPCI_DEVICE));
  63. if (!g_NewDevice) {
  64. MessageBox(Dlg, L"Failed to allocate memory for new device!",
  65. NULL, MB_OK | MB_ICONEXCLAMATION);
  66. SoftPCI_ResetNewDevDlg();
  67. return FALSE;
  68. }
  69. g_ParentPdn = pdn;
  70. g_PossibleDeviceNums = SoftPCI_GetPossibleDevNumMask(g_ParentPdn);
  71. //
  72. // Clear our BarControl BARS
  73. //
  74. for (i=0; i < PCI_TYPE0_ADDRESSES; i++) {
  75. BarControl[i].Bar = 0;
  76. }
  77. //
  78. // Grab the bus we are going to reside on
  79. //
  80. bridgePdn = pdn;
  81. while (bridgePdn->SoftDev == NULL) {
  82. bridgePdn = bridgePdn->Parent;
  83. }
  84. g_NewDevice->Bus = bridgePdn->SoftDev->Config.Current.u.type1.SecondaryBus;
  85. //
  86. // Initialize our drop list
  87. //
  88. devtype = GetDlgItem(Dlg, IDC_DEVTYPE_CB);
  89. SendMessage(devtype, CB_ADDSTRING, 0L, (LPARAM) L"DEVICE");
  90. SendMessage(devtype, CB_ADDSTRING, 0L, (LPARAM) L"PCI BRIDGE");
  91. SendMessage(devtype, CB_ADDSTRING, 0L, (LPARAM) L"HOTPLUG BRIDGE");
  92. SendMessage(devtype, CB_ADDSTRING, 0L, (LPARAM) L"CARDBUS DEVICE");
  93. SendMessage(devtype, CB_ADDSTRING, 0L, (LPARAM) L"CARDBUS BRIDGE");
  94. SetFocus(devtype);
  95. //
  96. // Set the Window size
  97. //
  98. GetWindowRect(g_SoftPCIMainWnd, &mainRect );
  99. GetWindowRect(Dlg, &dlgRect );
  100. width = (mainRect.right - mainRect.left) + 30;
  101. height = (mainRect.bottom - mainRect.top);
  102. dlgRect.right -= dlgRect.left;
  103. dlgRect.bottom -= dlgRect.top;
  104. //MoveWindow(Dlg, mainRect.right, mainRect.top, dlgRect.right, dlgRect.bottom, TRUE );
  105. MoveWindow(Dlg, mainRect.left, mainRect.top, dlgRect.right, dlgRect.bottom, TRUE );
  106. g_NewDevDlg = Dlg;
  107. break;
  108. HANDLE_MSG(Dlg, WM_COMMAND, SoftPCI_DlgOnCommand);
  109. case WM_HSCROLL:
  110. HANDLE_TRACKBAR(wParam, lParam);
  111. //SoftPCI_HandleTrackBar(Dlg, wParam, lParam);
  112. break;
  113. case WM_VSCROLL:
  114. HANDLE_SPINNER(wParam, lParam);
  115. //HANDLE_TRACKBAR(wParam, lParam);
  116. //SoftPCI_HandleTrackBar(Dlg, wParam, lParam);
  117. break;
  118. case WM_CLOSE:
  119. g_NewDevDlg = 0;
  120. if (g_NewDevice) {
  121. free(g_NewDevice);
  122. }
  123. EndDialog(Dlg, 0);
  124. break;
  125. default:
  126. break;
  127. }
  128. return rc; //DefDlgProc(Dlg, Msg, wParam, lParam);
  129. }
  130. ULONG
  131. SoftPCI_GetPossibleDevNumMask(
  132. IN PPCI_DN ParentDn
  133. )
  134. {
  135. HPS_HWINIT_DESCRIPTOR hpData;
  136. BOOL status;
  137. if (!ParentDn->SoftDev) {
  138. return 0;
  139. }
  140. if (ParentDn->Flags & SOFTPCI_HOTPLUG_CONTROLLER) {
  141. //
  142. // For hotplug bridges, we remove any hotplug slots, because devices
  143. // have to be children of the slot objects to be in hotplug slots.
  144. //
  145. status = SoftPCI_GetHotplugData(ParentDn,
  146. &hpData
  147. );
  148. if (!status) {
  149. return 0;
  150. } else {
  151. return (((ULONG)(-1)) -
  152. ((ULONG)(1 << (hpData.FirstDeviceID + hpData.NumSlots)) - 1) +
  153. ((ULONG)(1 << (hpData.FirstDeviceID)) - 1));
  154. }
  155. } else if (ParentDn->Flags & SOFTPCI_HOTPLUG_SLOT) {
  156. //
  157. // The only legal device number is the one controlled by this slot.
  158. //
  159. return (1 << ParentDn->Slot.Device);
  160. } else {
  161. return (ULONG)-1;
  162. }
  163. }
  164. VOID
  165. SoftPCI_DisplayDlgOptions(
  166. IN SOFTPCI_DEV_TYPE DevType
  167. )
  168. {
  169. HWND control, bargroup;
  170. ULONG i;
  171. RECT barRect, dlgRect, rect;
  172. LONG width, height;
  173. POINT pt;
  174. WCHAR buffer[100];
  175. SoftPCI_ResetNewDevDlg();
  176. SoftPCI_ShowCommonNewDevDlg();
  177. bargroup = GetDlgItem(g_NewDevDlg, IDC_BARS_GB);
  178. GetClientRect(bargroup, &barRect);
  179. width = barRect.right - barRect.left;
  180. height = barRect.bottom - barRect.top;
  181. //
  182. // Disable our Bars until something is selected.
  183. //
  184. for (i=0; i < PCI_TYPE0_ADDRESSES; i++) {
  185. control = GetDlgItem(g_NewDevDlg, BarControl[i].tb);
  186. SoftPCI_DisableWindow(control);
  187. control = GetDlgItem(g_NewDevDlg, BarControl[i].tx);
  188. SoftPCI_DisableWindow(control);
  189. control = GetDlgItem(g_NewDevDlg, BarControl[i].pref);
  190. SoftPCI_DisableWindow(control);
  191. control = GetDlgItem(g_NewDevDlg, BarControl[i].bit64);
  192. SoftPCI_DisableWindow(control);
  193. }
  194. SoftPCI_ResetLowerBars(-1);
  195. //
  196. // We want this checked by default for now....
  197. //
  198. CheckDlgButton(g_NewDevDlg, IDC_DEFAULTDEV_XB, BST_CHECKED);
  199. //
  200. // Start with a clean configspace
  201. //
  202. RtlZeroMemory(&g_NewDevice->Config.Current, (sizeof(PCI_COMMON_CONFIG) * 3));
  203. switch (DevType) {
  204. case TYPE_DEVICE:
  205. for (i = IDC_BAR2_TB; i < IDC_BRIDGEWIN_GB; i++) {
  206. control = GetDlgItem(g_NewDevDlg, i);
  207. if (control) {
  208. SoftPCI_ShowWindow(control);
  209. }
  210. }
  211. SoftPCI_InitializeDevice(g_NewDevice, TYPE_DEVICE);
  212. height = 215;
  213. break;
  214. case TYPE_PCI_BRIDGE:
  215. for (i = IDC_DECODE_GB; i < LAST_CONTROL_ID; i++) {
  216. control = GetDlgItem(g_NewDevDlg, i);
  217. if (control) {
  218. SoftPCI_ShowWindow(control);
  219. }
  220. }
  221. SoftPCI_InitializeDevice(g_NewDevice, TYPE_PCI_BRIDGE);
  222. //
  223. // update the height of our bar group box
  224. //
  225. height = 78;
  226. break;
  227. case TYPE_HOTPLUG_BRIDGE:
  228. for (i=IDC_ATTBTN_XB; i < LAST_CONTROL_ID; i++) {
  229. control = GetDlgItem(g_NewDevDlg, i);
  230. if (control) {
  231. SoftPCI_ShowWindow(control);
  232. }
  233. }
  234. //
  235. // Allocate our HPS Descriptor
  236. //
  237. g_HPSInitDesc = (PHPS_HWINIT_DESCRIPTOR)((PUCHAR)&g_NewDevice->Config.Current + HPS_HWINIT_OFFSET);
  238. g_HPSInitDesc->ProgIF = 1;
  239. SoftPCI_InitializeHotPlugControls();
  240. SoftPCI_InitializeDevice(g_NewDevice, TYPE_HOTPLUG_BRIDGE);
  241. //
  242. // update the height of our bar group box
  243. //
  244. height = 78;
  245. break;
  246. case TYPE_CARDBUS_DEVICE:
  247. case TYPE_CARDBUS_BRIDGE:
  248. //
  249. // These are currently not implemented yet....
  250. //
  251. SoftPCI_ResetNewDevDlg();
  252. control = GetDlgItem(g_NewDevDlg, IDC_NEWDEVINFO_TX);
  253. SoftPCI_ShowWindow(control);
  254. SetWindowText (control, L"DEVICE TYPE NOT IMPLEMENTED YET");
  255. break;
  256. }
  257. //
  258. // Update our various window positions
  259. //
  260. SetWindowPos(bargroup, HWND_TOP, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
  261. }
  262. VOID
  263. SoftPCI_DlgOnCommand(
  264. IN HWND Wnd,
  265. IN INT ControlID,
  266. IN HWND ControlWnd,
  267. IN UINT NotificationCode
  268. )
  269. {
  270. SOFTPCI_DEV_TYPE selection = 0;
  271. switch (ControlID){
  272. case IDC_DEVTYPE_CB:
  273. switch (NotificationCode){
  274. case CBN_SELENDOK:
  275. selection = SendDlgItemMessage(Wnd,
  276. IDC_DEVTYPE_CB,
  277. CB_GETCURSEL,
  278. (WPARAM) 0,
  279. (LPARAM) 0
  280. );
  281. SoftPCI_DisplayDlgOptions(selection);
  282. break;
  283. default:
  284. break;
  285. }
  286. //
  287. // Handle our CheckBoxes
  288. //
  289. case IDC_SAVETOREG_XB:
  290. case IDC_DEFAULTDEV_XB:
  291. case IDC_MEMENABLE_XB:
  292. case IDC_IOENABLE_XB:
  293. case IDC_BUSMSTR_XB:
  294. case IDC_BAR0_PREF_XB:
  295. case IDC_BAR0_64BIT_XB:
  296. case IDC_BAR1_PREF_XB:
  297. case IDC_BAR1_64BIT_XB:
  298. case IDC_BAR2_PREF_XB:
  299. case IDC_BAR2_64BIT_XB:
  300. case IDC_BAR3_PREF_XB:
  301. case IDC_BAR3_64BIT_XB:
  302. case IDC_BAR4_PREF_XB:
  303. case IDC_BAR4_64BIT_XB:
  304. case IDC_BAR5_PREF_XB:
  305. case IDC_POSDECODE_XB:
  306. case IDC_SUBDECODE_XB:
  307. case IDC_ATTBTN_XB:
  308. case IDC_MRL_XB:
  309. SoftPCI_HandleCheckBox(ControlWnd, ControlID, NotificationCode);
  310. break;
  311. //
  312. // Handle our TrackBar/Sliders
  313. //
  314. case IDC_BAR0_TB:
  315. case IDC_BAR1_TB:
  316. case IDC_BAR2_TB:
  317. case IDC_BAR3_TB:
  318. case IDC_BAR4_TB:
  319. case IDC_BAR5_TB:
  320. case IDC_BRIDGEMEM_TB:
  321. case IDC_BRIDGEIO_TB:
  322. break;
  323. //
  324. // Handle the Radio Buttons
  325. //
  326. case IDC_BAR0IO_RB:
  327. case IDC_BAR0MEM_RB:
  328. case IDC_BAR1IO_RB:
  329. case IDC_BAR1MEM_RB:
  330. case IDC_BAR2IO_RB:
  331. case IDC_BAR2MEM_RB:
  332. case IDC_BAR3IO_RB:
  333. case IDC_BAR3MEM_RB:
  334. case IDC_BAR4IO_RB:
  335. case IDC_BAR4MEM_RB:
  336. case IDC_BAR5IO_RB:
  337. case IDC_BAR5MEM_RB:
  338. SoftPCI_HandleRadioButton(ControlWnd, ControlID, NotificationCode);
  339. break;
  340. case IDC_SLOTLABELUP_RB:
  341. g_HPSInitDesc->UpDown = 1;
  342. break;
  343. case IDC_SLOTLABELDN_RB:
  344. g_HPSInitDesc->UpDown = 0;
  345. break;
  346. //
  347. // Handle our Edit boxes (attached to our spinners)
  348. //
  349. case IDC_33CONV_EB:
  350. case IDC_66CONV_EB:
  351. case IDC_66PCIX_EB:
  352. case IDC_100PCIX_EB:
  353. case IDC_133PCIX_EB:
  354. case IDC_ALLSLOTS_EB:
  355. case IDC_1STDEVSEL_EB:
  356. case IDC_1STSLOTLABEL_EB:
  357. if (g_HPSInitDesc && (NotificationCode == EN_CHANGE)) {
  358. //
  359. // ISSUE: This should probably be done some other way as this
  360. // makes us dependant on the numbering in resource.h
  361. //
  362. SoftPCI_HandleSpinnerControl(GetDlgItem(g_NewDevDlg, ControlID+1), SB_ENDSCROLL, 0);
  363. }
  364. break;
  365. case IDC_INSTALL_BUTTON:
  366. //
  367. // Add code to vaildate selection and install new device.
  368. //
  369. if (NotificationCode == BN_CLICKED) {
  370. SoftPCI_HandleDlgInstallDevice(Wnd);
  371. PostMessage(Wnd, WM_CLOSE, 0, 0);
  372. }
  373. break;
  374. case IDC_CANCEL_BUTTON:
  375. if (NotificationCode == BN_CLICKED) {
  376. //
  377. // User wants to Cancel creation of new device
  378. //
  379. PostMessage(Wnd, WM_CLOSE, 0, 0);
  380. }
  381. break;
  382. default:
  383. break;
  384. }
  385. }
  386. VOID
  387. SoftPCI_HandleCheckBox(
  388. IN HWND Wnd,
  389. IN INT ControlID,
  390. IN UINT NotificationCode
  391. )
  392. {
  393. HWND control;
  394. BOOL isChecked;
  395. ULONG barIndex = 0;
  396. isChecked = (BOOL)IsDlgButtonChecked(g_NewDevDlg, ControlID);
  397. if (!SoftPCI_GetAssociatedBarControl(ControlID, &barIndex)){
  398. //
  399. // Not sure what I should do here...
  400. //
  401. }
  402. if (NotificationCode == BN_CLICKED) {
  403. switch (ControlID) {
  404. case IDC_SAVETOREG_XB:
  405. //
  406. // ISSUE: Add code here to save device selection to registry.
  407. //
  408. MessageBox(NULL, L"This is still under developement...", L"NOT IMPLEMENTED YET", MB_OK | MB_ICONEXCLAMATION);
  409. SoftPCI_UnCheckDlgBox(Wnd);
  410. SoftPCI_DisableWindow(Wnd);
  411. break;
  412. case IDC_DEFAULTDEV_XB:
  413. MessageBox(NULL, L"This is still under developement...", L"NOT FULLY IMPLEMENTED YET", MB_OK | MB_ICONEXCLAMATION);
  414. SoftPCI_CheckDlgBox(Wnd);
  415. break;
  416. //
  417. // Now deal with our Command Register
  418. //
  419. case IDC_MEMENABLE_XB:
  420. if (isChecked) {
  421. g_NewDevice->Config.Current.Command |= PCI_ENABLE_MEMORY_SPACE;
  422. }else{
  423. g_NewDevice->Config.Current.Command &= ~PCI_ENABLE_MEMORY_SPACE;
  424. }
  425. break;
  426. case IDC_IOENABLE_XB:
  427. if (isChecked) {
  428. g_NewDevice->Config.Current.Command |= PCI_ENABLE_IO_SPACE;
  429. }else{
  430. g_NewDevice->Config.Current.Command &= ~PCI_ENABLE_IO_SPACE;
  431. }
  432. break;
  433. case IDC_BUSMSTR_XB:
  434. if (isChecked) {
  435. g_NewDevice->Config.Current.Command |= PCI_ENABLE_BUS_MASTER;
  436. }else{
  437. g_NewDevice->Config.Current.Command &= ~PCI_ENABLE_BUS_MASTER;
  438. }
  439. break;
  440. case IDC_BAR0_PREF_XB:
  441. case IDC_BAR1_PREF_XB:
  442. case IDC_BAR2_PREF_XB:
  443. case IDC_BAR3_PREF_XB:
  444. case IDC_BAR4_PREF_XB:
  445. case IDC_BAR5_PREF_XB:
  446. if (isChecked) {
  447. BarControl[barIndex].Bar |= PCI_ADDRESS_MEMORY_PREFETCHABLE;
  448. g_NewDevice->Config.Mask.u.type0.BaseAddresses[barIndex] |= PCI_ADDRESS_MEMORY_PREFETCHABLE;
  449. }else{
  450. BarControl[barIndex].Bar &= ~PCI_ADDRESS_MEMORY_PREFETCHABLE;
  451. g_NewDevice->Config.Mask.u.type0.BaseAddresses[barIndex] &= ~PCI_ADDRESS_MEMORY_PREFETCHABLE;
  452. }
  453. //SendMessage(g_NewDevDlg, WM_HSCROLL, (WPARAM)SB_THUMBPOSITION, (LPARAM)Wnd);
  454. break;
  455. case IDC_BAR0_64BIT_XB:
  456. case IDC_BAR1_64BIT_XB:
  457. case IDC_BAR2_64BIT_XB:
  458. case IDC_BAR3_64BIT_XB:
  459. case IDC_BAR4_64BIT_XB:
  460. SoftPCI_ResetLowerBars(barIndex);
  461. if (isChecked) {
  462. //
  463. // Disable the next BAR
  464. //
  465. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].mrb);
  466. SoftPCI_UnCheckDlgBox(control);
  467. SoftPCI_DisableWindow(control);
  468. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].irb);
  469. SoftPCI_UnCheckDlgBox(control);
  470. SoftPCI_DisableWindow(control);
  471. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].pref);
  472. SoftPCI_UnCheckDlgBox(control);
  473. SoftPCI_DisableWindow(control);
  474. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].bit64);
  475. SoftPCI_UnCheckDlgBox(control);
  476. SoftPCI_DisableWindow(control);
  477. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].tb);
  478. SoftPCI_ResetTrackBar(control);
  479. SoftPCI_DisableWindow(control);
  480. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].tx);
  481. SoftPCI_DisableWindow(control);
  482. BarControl[barIndex].Bar |= PCI_TYPE_64BIT;
  483. }else{
  484. //
  485. // Enable next BAR
  486. //
  487. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].mrb);
  488. SoftPCI_UnCheckDlgBox(control);
  489. SoftPCI_EnableWindow(control);
  490. control = GetDlgItem(g_NewDevDlg, BarControl[barIndex+1].irb);
  491. SoftPCI_UnCheckDlgBox(control);
  492. SoftPCI_EnableWindow(control);
  493. BarControl[barIndex].Bar &= ~PCI_TYPE_64BIT;
  494. }
  495. SoftPCI_InitializeBar(barIndex);
  496. break;
  497. case IDC_ATTBTN_XB:
  498. case IDC_MRL_XB:
  499. if (isChecked) {
  500. g_HPSInitDesc->MRLSensorsImplemented = 1;
  501. g_HPSInitDesc->AttentionButtonImplemented = 1;
  502. }else{
  503. g_HPSInitDesc->MRLSensorsImplemented = 0;
  504. g_HPSInitDesc->AttentionButtonImplemented = 0;
  505. }
  506. break;
  507. case IDC_POSDECODE_XB:
  508. case IDC_SUBDECODE_XB:
  509. SOFTPCI_ASSERT(IS_BRIDGE(g_NewDevice));
  510. if (isChecked) {
  511. g_NewDevice->Config.Current.ProgIf = 0x1;
  512. g_NewDevice->Config.Mask.ProgIf = 0x1;
  513. }else{
  514. g_NewDevice->Config.Current.ProgIf = 0;
  515. g_NewDevice->Config.Mask.ProgIf = 0;
  516. }
  517. break;
  518. }
  519. }
  520. }
  521. VOID
  522. SoftPCI_HandleDlgInstallDevice(
  523. IN HWND Wnd
  524. )
  525. {
  526. BOOL defaultDev = FALSE;
  527. SOFTPCI_DEV_TYPE selection = 0;
  528. SOFTPCI_ASSERTMSG("Attempting to install a NULL device!\n\nHave BrandonA check this out!!",
  529. (g_NewDevice != NULL));
  530. if (!g_NewDevice){
  531. return;
  532. }
  533. //
  534. // If we're inserting in a hotplug slot, store the device away
  535. // in hpsim and return without telling softpci.sys about it.
  536. //
  537. if (g_ParentPdn->Flags & SOFTPCI_HOTPLUG_SLOT) {
  538. g_NewDevice->Slot.Device = g_ParentPdn->Slot.Device;
  539. SoftPCI_AddHotplugDevice(g_ParentPdn->Parent,
  540. g_NewDevice
  541. );
  542. SoftPCI_CreateTreeView();
  543. return;
  544. }
  545. switch (g_NewDevice->DevType) {
  546. case TYPE_CARDBUS_DEVICE:
  547. case TYPE_CARDBUS_BRIDGE:
  548. MessageBox(Wnd, L"This device type has not been implemented fully!",
  549. L"NOT IMPLEMENTED YET", MB_OK | MB_ICONEXCLAMATION);
  550. return;
  551. }
  552. #if DBG
  553. if ((IS_BRIDGE(g_NewDevice)) &&
  554. ((g_NewDevice->Config.Mask.u.type1.PrimaryBus == 0) ||
  555. (g_NewDevice->Config.Mask.u.type1.SecondaryBus == 0) ||
  556. (g_NewDevice->Config.Mask.u.type1.SubordinateBus == 0))){
  557. SOFTPCI_ASSERTMSG("A bus number config mask is zero!",
  558. ((g_NewDevice->Config.Mask.u.type1.PrimaryBus != 0) ||
  559. (g_NewDevice->Config.Mask.u.type1.SecondaryBus != 0) ||
  560. (g_NewDevice->Config.Mask.u.type1.SubordinateBus != 0)));
  561. return;
  562. }
  563. #endif
  564. defaultDev = IsDlgButtonChecked(Wnd , IDC_DEFAULTDEV_XB);
  565. if (!SoftPCI_CreateDevice(g_NewDevice, g_PossibleDeviceNums, FALSE)){
  566. MessageBox(Wnd, L"Failed to install specified SoftPCI device.....", L"ERROR", MB_OK);
  567. }
  568. }
  569. VOID
  570. SoftPCI_HandleRadioButton(
  571. IN HWND Wnd,
  572. IN INT ControlID,
  573. IN UINT NotificationCode
  574. )
  575. {
  576. HWND control;
  577. ULONG i = 0;
  578. if (!SoftPCI_GetAssociatedBarControl(ControlID, &i)){
  579. //
  580. // Not sure what I should do here...
  581. //
  582. SOFTPCI_ASSERTMSG("SoftPCI_GetAssociatedBarControl() failed!", FALSE);
  583. }
  584. if (NotificationCode == BN_CLICKED) {
  585. switch (ControlID) {
  586. case IDC_BAR0IO_RB:
  587. case IDC_BAR1IO_RB:
  588. case IDC_BAR2IO_RB:
  589. case IDC_BAR3IO_RB:
  590. case IDC_BAR4IO_RB:
  591. case IDC_BAR5IO_RB:
  592. control = GetDlgItem(g_NewDevDlg, BarControl[i].tb);
  593. SoftPCI_EnableWindow(control);
  594. control = GetDlgItem(g_NewDevDlg, BarControl[i].tx);
  595. SoftPCI_EnableWindow(control);
  596. control = GetDlgItem(g_NewDevDlg, BarControl[i].pref);
  597. SoftPCI_UnCheckDlgBox(control);
  598. SoftPCI_DisableWindow(control);
  599. control = GetDlgItem(g_NewDevDlg, BarControl[i].bit64);
  600. //
  601. // Reset the bars below this one if it was
  602. // set to 64 bit mem bar
  603. //
  604. if (IsDlgButtonChecked(g_NewDevDlg, BarControl[i].bit64)) {
  605. SoftPCI_ResetLowerBars(i);
  606. }
  607. SoftPCI_UnCheckDlgBox(control);
  608. SoftPCI_DisableWindow(control);
  609. //
  610. // Initialize BAR
  611. //
  612. BarControl[i].Bar |= PCI_ADDRESS_IO_SPACE;
  613. SoftPCI_InitializeBar(i);
  614. break;
  615. case IDC_BAR0MEM_RB:
  616. case IDC_BAR1MEM_RB:
  617. case IDC_BAR2MEM_RB:
  618. case IDC_BAR3MEM_RB:
  619. case IDC_BAR4MEM_RB:
  620. case IDC_BAR5MEM_RB:
  621. //
  622. // Initialize BAR
  623. //
  624. BarControl[i].Bar &= ~PCI_ADDRESS_IO_SPACE;
  625. SoftPCI_InitializeBar(i);
  626. control = GetDlgItem(g_NewDevDlg, BarControl[i].tb);
  627. SoftPCI_EnableWindow(control);
  628. control = GetDlgItem(g_NewDevDlg, BarControl[i].tx);
  629. SoftPCI_EnableWindow(control);
  630. control = GetDlgItem(g_NewDevDlg, BarControl[i].pref);
  631. SoftPCI_EnableWindow(control);
  632. if (g_NewDevice &&
  633. IS_BRIDGE(g_NewDevice) &&
  634. ControlID == IDC_BAR1MEM_RB) {
  635. //
  636. // We only have two BARs on a bridge and therefore cannot
  637. // allow the second bar to set 64Bit.
  638. //
  639. break;
  640. }
  641. control = GetDlgItem(g_NewDevDlg, BarControl[i].bit64);
  642. SoftPCI_EnableWindow(control);
  643. break;
  644. }
  645. }
  646. }
  647. VOID
  648. SoftPCI_HandleTrackBar(
  649. IN HWND Wnd,
  650. IN WORD NotificationCode,
  651. IN WORD CurrentPos
  652. )
  653. {
  654. HWND sliderWnd;
  655. UINT controlID;
  656. ULONG currentPos = 0;
  657. WCHAR buffer[MAX_PATH];
  658. ULONG barIndex = 0, *pbar = NULL, saveBar = 0;
  659. ULONGLONG bar = 0, barMask = 0, barSize = 0;
  660. SOFTPCI_ASSERTMSG("Attempting to init a NULL device!\n\nHave BrandonA check this out!!",
  661. (g_NewDevice != NULL));
  662. if (!g_NewDevice){
  663. return;
  664. }
  665. switch (NotificationCode) {
  666. case SB_ENDSCROLL:
  667. case SB_THUMBPOSITION:
  668. case SB_THUMBTRACK:
  669. controlID = GetDlgCtrlID(Wnd);
  670. if ((controlID == IDC_BRIDGEMEM_TB) || (controlID == IDC_BRIDGEIO_TB)) {
  671. //
  672. // Implement this...
  673. //
  674. return;
  675. }
  676. if (!SoftPCI_GetAssociatedBarControl(controlID, &barIndex)){
  677. //
  678. // Not sure what I should do here...
  679. //
  680. }
  681. sliderWnd = GetDlgItem(g_NewDevDlg, BarControl[barIndex].tx);
  682. //
  683. // Save our current Bar value so we can restore any important bits after we
  684. // mangle it.
  685. //
  686. saveBar = BarControl[barIndex].Bar;
  687. //
  688. // Set intial BAR values
  689. //
  690. if (BarControl[barIndex].Bar & PCI_ADDRESS_IO_SPACE) {
  691. bar = PCI_ADDRESS_IO_ADDRESS_MASK;
  692. }else{
  693. bar = PCI_ADDRESS_MEMORY_ADDRESS_MASK;
  694. }
  695. //
  696. // Get the current position of the slider
  697. //
  698. currentPos = (ULONG) SoftPCI_GetTrackBarPosition(Wnd);
  699. //
  700. // Fill in the rest of the BAR if we are dealing with 64 bit
  701. //
  702. if ((BarControl[barIndex].Bar & PCI_TYPE_64BIT)) {
  703. pbar = &((ULONG)bar);
  704. pbar++;
  705. *pbar = 0xffffffff;
  706. }
  707. //
  708. // Shift the bar by the sliders returned position
  709. //
  710. bar <<= currentPos;
  711. barMask = bar;
  712. //
  713. // Update our Bar Control for this bar
  714. //
  715. if (saveBar & PCI_ADDRESS_IO_SPACE) {
  716. bar &= 0xffff;
  717. barMask &= 0xffff;
  718. bar |= PCI_ADDRESS_IO_SPACE;
  719. } else {
  720. bar |= (saveBar & (PCI_ADDRESS_MEMORY_TYPE_MASK | PCI_ADDRESS_MEMORY_PREFETCHABLE));
  721. }
  722. if (IS_BRIDGE(g_NewDevice)){
  723. g_NewDevice->Config.Current.u.type1.BaseAddresses[barIndex] = (ULONG)bar;
  724. g_NewDevice->Config.Mask.u.type1.BaseAddresses[barIndex] = (ULONG) barMask;
  725. SOFTPCI_ASSERTMSG("A bus number config mask is zero!",
  726. ((g_NewDevice->Config.Mask.u.type1.PrimaryBus != 0) ||
  727. (g_NewDevice->Config.Mask.u.type1.SecondaryBus != 0) ||
  728. (g_NewDevice->Config.Mask.u.type1.SubordinateBus != 0)));
  729. }else{
  730. g_NewDevice->Config.Current.u.type0.BaseAddresses[barIndex] = (ULONG)bar;
  731. g_NewDevice->Config.Mask.u.type0.BaseAddresses[barIndex] = (ULONG) barMask ;
  732. }
  733. GetDlgItem(g_NewDevDlg, BarControl[barIndex].tx);
  734. //
  735. // Update the next bar if we are dealing with 64 bit
  736. //
  737. if ((BarControl[barIndex].Bar & PCI_TYPE_64BIT)) {
  738. g_NewDevice->Config.Mask.u.type0.BaseAddresses[barIndex+1] = (ULONG)(bar >> 32);
  739. }
  740. //
  741. // Get the size so we can display its current setting
  742. //
  743. barSize = SoftPCI_GetLengthFromBar(bar);
  744. SOFTPCI_ASSERT(barSize != 0);
  745. //
  746. // Update our sliders text field
  747. //
  748. SoftPCI_UpdateBarText(buffer, barSize);
  749. SetWindowText (sliderWnd, buffer);
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. VOID
  756. SoftPCI_HandleSpinnerControl(
  757. IN HWND Wnd,
  758. IN WORD NotificationCode,
  759. IN WORD CurrentPos
  760. )
  761. {
  762. SOFTPCI_ASSERTMSG("Attempting to init a NULL device!\n\nHave BrandonA check this out!!",
  763. (g_NewDevice != NULL));
  764. if (!g_NewDevice){
  765. PostMessage(g_NewDevDlg, WM_CLOSE, 0, 0);
  766. }
  767. switch (NotificationCode) {
  768. case SB_ENDSCROLL:
  769. case SB_THUMBPOSITION:
  770. switch (GetDlgCtrlID(Wnd)) {
  771. case IDC_33CONV_SP:
  772. g_HPSInitDesc->NumSlots33Conv = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  773. break;
  774. case IDC_66CONV_SP:
  775. g_HPSInitDesc->NumSlots66Conv = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  776. break;
  777. case IDC_66PCIX_SP:
  778. g_HPSInitDesc->NumSlots66PciX = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  779. break;
  780. case IDC_100PCIX_SP:
  781. g_HPSInitDesc->NumSlots100PciX = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  782. break;
  783. case IDC_133PCIX_SP:
  784. g_HPSInitDesc->NumSlots133PciX = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  785. break;
  786. case IDC_ALLSLOTS_SP:
  787. g_HPSInitDesc->NumSlots = (WORD) SoftPCI_GetSpinnerValue(Wnd);
  788. break;
  789. case IDC_1STDEVSEL_SP:
  790. g_HPSInitDesc->FirstDeviceID = (UCHAR) SoftPCI_GetSpinnerValue(Wnd);
  791. break;
  792. case IDC_1STSLOTLABEL_SP:
  793. g_HPSInitDesc->FirstSlotLabelNumber = (UCHAR)SoftPCI_GetSpinnerValue(Wnd);
  794. break;
  795. default:
  796. break;
  797. }
  798. }
  799. }
  800. VOID
  801. SoftPCI_InitializeBar(
  802. IN INT Bar
  803. )
  804. {
  805. HWND control;
  806. WCHAR buffer[50];
  807. ULONGLONG bar64 = 0;
  808. //
  809. // Get the track bar associated with this bar
  810. //
  811. control = GetDlgItem(g_NewDevDlg, BarControl[Bar].tb);
  812. if (BarControl[Bar].Bar & PCI_ADDRESS_IO_SPACE) {
  813. //
  814. // IO Bar
  815. //
  816. SendMessage(control, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 6));
  817. SendMessage(control, TBM_SETPOS, (WPARAM)TRUE, 0);
  818. SendMessage(g_NewDevDlg, WM_HSCROLL, (WPARAM)SB_THUMBPOSITION, (LPARAM)control);
  819. }else{
  820. //
  821. // Mem Bar
  822. //
  823. control = GetDlgItem(g_NewDevDlg, BarControl[Bar].tb);
  824. if (IsDlgButtonChecked(g_NewDevDlg, BarControl[Bar].bit64)) {
  825. //
  826. // Init this as 64 bit bar. Bit Range 0 - 60
  827. //
  828. SendMessage(control, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 59));
  829. SendMessage(control, TBM_SETPOS, (WPARAM)TRUE, 0);
  830. SendMessage(g_NewDevDlg, WM_HSCROLL, (WPARAM)SB_THUMBPOSITION, (LPARAM)control);
  831. }else{
  832. //
  833. // Standard 32bit bar. Bit Range 0 - 28
  834. //
  835. SendMessage(control, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 27));
  836. SendMessage(control, TBM_SETPOS, (WPARAM)TRUE, 0);
  837. SendMessage(g_NewDevDlg, WM_HSCROLL, (WPARAM)SB_THUMBPOSITION, (LPARAM)control);
  838. }
  839. }
  840. }
  841. VOID
  842. SoftPCI_InitializeHotPlugControls(
  843. VOID
  844. )
  845. {
  846. INT controlID = IDC_ATTBTN_XB;
  847. HWND controlWnd;
  848. while (controlID < LAST_CONTROL_ID) {
  849. controlWnd = GetDlgItem(g_NewDevDlg, controlID);
  850. switch (controlID) {
  851. case IDC_ATTBTN_XB:
  852. case IDC_MRL_XB:
  853. SoftPCI_CheckDlgBox(controlWnd);
  854. g_HPSInitDesc->MRLSensorsImplemented = 1;
  855. g_HPSInitDesc->AttentionButtonImplemented = 1;
  856. break;
  857. //
  858. // init our Spinners
  859. //
  860. case IDC_33CONV_SP:
  861. case IDC_66CONV_SP:
  862. case IDC_66PCIX_SP:
  863. case IDC_100PCIX_SP:
  864. case IDC_133PCIX_SP:
  865. case IDC_ALLSLOTS_SP:
  866. case IDC_1STDEVSEL_SP:
  867. SoftPCI_InitSpinnerControl(controlWnd, 0, HPS_MAX_SLOTS, 0);
  868. //if (controlID == IDC_1STDEVSEL_SP) {
  869. // SendMessage(GetDlgItem(g_NewDevDlg, controlID), UDM_SETBASE, (WPARAM) 16, 0);
  870. //}
  871. break;
  872. case IDC_1STSLOTLABEL_SP:
  873. SoftPCI_InitSpinnerControl(controlWnd, 0, HPS_MAX_SLOT_LABEL, 1);
  874. break;
  875. case IDC_SLOTLABELUP_RB:
  876. SoftPCI_CheckDlgBox(controlWnd);
  877. g_HPSInitDesc->UpDown = 1;
  878. break;
  879. case IDC_33CONV_EB:
  880. case IDC_66CONV_EB:
  881. case IDC_66PCIX_EB:
  882. case IDC_100PCIX_EB:
  883. case IDC_133PCIX_EB:
  884. case IDC_ALLSLOTS_EB:
  885. case IDC_1STDEVSEL_EB:
  886. case IDC_1STSLOTLABEL_EB:
  887. break;
  888. default:
  889. break;
  890. }
  891. controlID++;
  892. }
  893. }
  894. BOOL
  895. SoftPCI_GetAssociatedBarControl(
  896. IN INT ControlID,
  897. OUT INT *Bar
  898. )
  899. {
  900. INT i = 0;
  901. *Bar = 0;
  902. for (i=0; i < PCI_TYPE0_ADDRESSES; i++ ) {
  903. if ((ControlID == BarControl[i].tb) ||
  904. (ControlID == BarControl[i].mrb) ||
  905. (ControlID == BarControl[i].irb) ||
  906. (ControlID == BarControl[i].pref) ||
  907. (ControlID == BarControl[i].bit64) ||
  908. (ControlID == BarControl[i].tx)) {
  909. *Bar = i;
  910. return TRUE;
  911. }
  912. }
  913. return FALSE;
  914. }
  915. VOID
  916. SoftPCI_ResetLowerBars(
  917. IN INT Bar
  918. )
  919. {
  920. INT i;
  921. HWND control;
  922. WCHAR buffer[10];
  923. for (i = Bar+1; i < PCI_TYPE0_ADDRESSES; i++ ) {
  924. control = GetDlgItem(g_NewDevDlg, BarControl[i].mrb);
  925. SoftPCI_UnCheckDlgBox(control);
  926. SoftPCI_EnableWindow(control);
  927. control = GetDlgItem(g_NewDevDlg, BarControl[i].irb);
  928. SoftPCI_UnCheckDlgBox(control);
  929. SoftPCI_EnableWindow(control);
  930. control = GetDlgItem(g_NewDevDlg, BarControl[i].pref);
  931. SoftPCI_UnCheckDlgBox(control);
  932. SoftPCI_DisableWindow(control);
  933. control = GetDlgItem(g_NewDevDlg, BarControl[i].bit64);
  934. SoftPCI_UnCheckDlgBox(control);
  935. SoftPCI_DisableWindow(control);
  936. control = GetDlgItem(g_NewDevDlg, BarControl[i].tb);
  937. SoftPCI_ResetTrackBar(control);
  938. SoftPCI_DisableWindow(control);
  939. control = GetDlgItem(g_NewDevDlg, BarControl[i].tx);
  940. wsprintf(buffer, L"BAR%d", i);
  941. SetWindowText (control, buffer);
  942. SoftPCI_DisableWindow(control);
  943. }
  944. }
  945. VOID
  946. SoftPCI_ResetNewDevDlg(VOID)
  947. {
  948. HWND control;
  949. ULONG i = 0;
  950. for (i = IDC_SAVETOREG_XB; i < LAST_CONTROL_ID; i++) {
  951. control = GetDlgItem(g_NewDevDlg, i);
  952. if (control) {
  953. SoftPCI_HideWindow(control);
  954. }
  955. }
  956. }
  957. VOID
  958. SoftPCI_ShowCommonNewDevDlg(VOID)
  959. {
  960. HWND control;
  961. ULONG i = 0;
  962. for (i = IDC_SAVETOREG_XB; i < IDC_BAR2_TB; i++) {
  963. control = GetDlgItem(g_NewDevDlg, i);
  964. if (control) {
  965. SoftPCI_ShowWindow(control);
  966. }
  967. }
  968. control = GetDlgItem(g_NewDevDlg, IDC_INSTALL_BUTTON);
  969. SoftPCI_ShowWindow(control);
  970. control = GetDlgItem(g_NewDevDlg, IDC_CANCEL_BUTTON);
  971. SoftPCI_ShowWindow(control);
  972. }
  973. VOID
  974. SoftPCI_UpdateBarText(
  975. IN PWCHAR Buffer,
  976. IN ULONGLONG BarSize
  977. )
  978. {
  979. #define SIZE_1KB 0x400
  980. #define SIZE_1MB 0x100000
  981. #define SIZE_1GB 0x40000000
  982. #define SIZE_1TB 0x10000000000
  983. #define SIZE_1PB 0x4000000000000
  984. #define SIZE_1XB 0x1000000000000000
  985. if (BarSize < SIZE_1KB) {
  986. wsprintf(Buffer, L"%d Bytes", BarSize);
  987. }else if ((BarSize >= SIZE_1KB) && (BarSize < SIZE_1MB)) {
  988. wsprintf(Buffer, L"%d KB", (BarSize / SIZE_1KB));
  989. }else if ((BarSize >= SIZE_1MB) && (BarSize < SIZE_1GB)) {
  990. wsprintf(Buffer, L"%d MB", (BarSize / SIZE_1MB));
  991. }else if ((BarSize >= SIZE_1GB) && (BarSize < SIZE_1TB)) {
  992. wsprintf(Buffer, L"%d GB", (BarSize / SIZE_1GB));
  993. }else if ((BarSize >= SIZE_1TB) && (BarSize < SIZE_1PB)) {
  994. wsprintf(Buffer, L"%d TB", (BarSize / SIZE_1TB));
  995. }else if ((BarSize >= SIZE_1PB) && (BarSize < SIZE_1XB)) {
  996. wsprintf(Buffer, L"%d PB", (BarSize / SIZE_1PB));
  997. }else if (BarSize >= SIZE_1XB) {
  998. wsprintf(Buffer, L"%d XB", (BarSize / SIZE_1XB));
  999. }
  1000. }