PCIData.cpp
上传用户:zhuqijet
上传日期:2007-01-04
资源大小:138k
文件大小:9k
源码类别:

驱动编程

开发平台:

Visual C++

  1. // PCIData.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "PCI Explorer.h"
  5. #include "NumericEdit.h"
  6. #include "IDCombo.h"
  7. #include "pci.h"
  8. #include "DataDisplay.h"
  9. #include "PCIScanIoctl.h"
  10. #include "PCIData.h"
  11. #include "codes.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. static IDData Displays[] = {
  18. { IDS_HEX_BYTES, DISPLAY_HEX_BYTES},
  19. { IDS_HEX_WORDS, DISPLAY_HEX_WORDS},
  20. { IDS_HEX_DWORDS, DISPLAY_HEX_DWORDS},
  21. { IDS_DECIMAL_BYTES, DISPLAY_DECIMAL_BYTES},
  22. { IDS_DECIMAL_WORDS, DISPLAY_DECIMAL_WORDS},
  23. { IDS_DECIMAL_DWORDS, DISPLAY_DECIMAL_DWORDS},
  24. { IDS_ANSI_CHARACTERS, DISPLAY_ANSI_CHARACTERS},
  25.         { IDS_UNICODE_CHARACTERS, DISPLAY_UNICODE_CHARACTERS},
  26. {0, 0} //EOT
  27.    };
  28. /////////////////////////////////////////////////////////////////////////////
  29. // PCIData property page
  30. IMPLEMENT_DYNCREATE(PCIData, CPropertyPage)
  31. PCIData::PCIData() : CPropertyPage(PCIData::IDD)
  32. {
  33. //{{AFX_DATA_INIT(PCIData)
  34. //}}AFX_DATA_INIT
  35. }
  36. PCIData::PCIData(CString cpt) : CPropertyPage(PCIData::IDD)
  37.     {
  38.      TCHAR * title = new TCHAR[cpt.GetLength()+1];
  39.      lstrcpy(title, cpt);
  40.      m_psp.pszTitle = title;
  41.      m_psp.dwFlags |= PSP_USETITLE;
  42.     }
  43. PCIData::~PCIData()
  44. {
  45. }
  46. void PCIData::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CPropertyPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(PCIData)
  50. DDX_Control(pDX, IDC_FUNCTION, c_Function);
  51. DDX_Control(pDX, IDC_DEVICE, c_Device);
  52. DDX_Control(pDX, IDC_BUS, c_Bus);
  53. DDX_Control(pDX, IDC_VENDORNAME, c_VendorName);
  54. DDX_Control(pDX, IDC_DEVICENAME, c_DeviceName);
  55. DDX_Control(pDX, IDC_HEX, c_Hex);
  56. DDX_Control(pDX, IDC_DECIMAL, c_Decimal);
  57. DDX_Control(pDX, IDC_SUBSYSTEMID, c_SubSystemID);
  58. DDX_Control(pDX, IDC_SUBVENDORID, c_SubVendorID);
  59. DDX_Control(pDX, IDC_ROMBASEADDRESS, c_ROMBaseAddress);
  60. DDX_Control(pDX, IDC_RESERVED2, c_Reserved2);
  61. DDX_Control(pDX, IDC_RESERVED1, c_Reserved1);
  62. DDX_Control(pDX, IDC_VENDORID, c_VendorID);
  63. DDX_Control(pDX, IDC_SUBCLASS, c_SubClass);
  64. DDX_Control(pDX, IDC_STATUS, c_Status);
  65. DDX_Control(pDX, IDC_REVISIONID, c_RevisionID);
  66. DDX_Control(pDX, IDC_PROGIF, c_ProgIf);
  67. DDX_Control(pDX, IDC_MINIMUMGRANT, c_MinimumGrant);
  68. DDX_Control(pDX, IDC_MAXIMUMLATENCY, c_MaximumLatency);
  69. DDX_Control(pDX, IDC_LATENCYTIMER, c_LatencyTimer);
  70. DDX_Control(pDX, IDC_INTERRUPTPIN, c_InterruptPin);
  71. DDX_Control(pDX, IDC_INTERRUPTLINE, c_InterruptLine);
  72. DDX_Control(pDX, IDC_HEADERTYPE, c_HeaderType);
  73. DDX_Control(pDX, IDC_DISPLAYAS, c_DisplayAs);
  74. DDX_Control(pDX, IDC_DEVICEID, c_DeviceID);
  75. DDX_Control(pDX, IDC_DATA, c_Data);
  76. DDX_Control(pDX, IDC_COMMAND, c_Command);
  77. DDX_Control(pDX, IDC_CIS, c_CIS);
  78. DDX_Control(pDX, IDC_CACHELINESIZE, c_CacheLineSize);
  79. DDX_Control(pDX, IDC_BIST, c_BIST);
  80. DDX_Control(pDX, IDC_BASECLASS, c_BaseClass);
  81. DDX_Control(pDX, IDC_BASEADDRESS5, c_BaseAddress5);
  82. DDX_Control(pDX, IDC_BASEADDRESS4, c_BaseAddress4);
  83. DDX_Control(pDX, IDC_BASEADDRESS3, c_BaseAddress3);
  84. DDX_Control(pDX, IDC_BASEADDRESS2, c_BaseAddress2);
  85. DDX_Control(pDX, IDC_BASEADDRESS1, c_BaseAddress1);
  86. DDX_Control(pDX, IDC_BASEADDRESS0, c_BaseAddress0);
  87. //}}AFX_DATA_MAP
  88. }
  89. BEGIN_MESSAGE_MAP(PCIData, CPropertyPage)
  90. //{{AFX_MSG_MAP(PCIData)
  91. ON_BN_CLICKED(IDC_HEX, OnHex)
  92. ON_BN_CLICKED(IDC_DECIMAL, OnDecimal)
  93. ON_CBN_SELENDOK(IDC_DISPLAYAS, OnSelendokDisplayas)
  94. //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96. /////////////////////////////////////////////////////////////////////////////
  97. // PCIData message handlers
  98. /****************************************************************************
  99. *                            PCIData::LoadPCIData
  100. * Result: void
  101. *       
  102. * Effect: 
  103. *       Loads the PCI data to the display using the selected radix
  104. ****************************************************************************/
  105. void PCIData::LoadPCIData()
  106.     {
  107.      CString ByteFormat;
  108.      CString WordFormat;
  109.      CString DWordFormat;
  110.      BOOL hex = c_Hex.GetCheck() == BST_CHECKED;
  111.      BOOL found = FALSE;
  112.      CString fullname;
  113.      CString shortname;
  114.      found = findVendor(data.PciData.VendorID, shortname, fullname);
  115.      if(found)
  116.  c_VendorName.SetWindowText(fullname);
  117.      c_VendorName.ShowWindow(found ? SW_SHOW : SW_HIDE);
  118.      CString chip;
  119.      CString desc;
  120.      found = findDevice(data.PciData.VendorID, data.PciData.DeviceID,
  121.       chip, desc);
  122.      if(found)
  123. { /* found it */
  124.  // ID cases display
  125.  // --------------------------------
  126.  // I "" "desc" desc
  127.  // II "chip" "" chip
  128.  // III  "chip" "desc" chip: desc
  129.  // IV "" "" none
  130.  found = TRUE;
  131.  if(lstrlen(chip) == 0 && lstrlen(desc) != 0)
  132.     { /* I */
  133.      c_DeviceName.SetWindowText(desc);
  134.     } /* I */
  135.  else
  136.  if(lstrlen(chip) != 0 && lstrlen(desc) == 0)
  137.     { /* II */
  138.      c_DeviceName.SetWindowText(chip);
  139.     } /* II */
  140.  else
  141.  if(lstrlen(chip) != 0 && lstrlen(desc) != 0)
  142.     { /* III */
  143.      CString s;
  144.      s.Format(_T("%s: %s"), chip, desc);
  145.      c_DeviceName.SetWindowText(s);
  146.     } /* III */
  147.  else
  148.  if(lstrlen(chip) == 0 && lstrlen(desc) == 0)
  149.     { /* IV */
  150.      found = FALSE; // found, but not interesting, pretend didn't
  151.     } /* IV */
  152. } /* found it */
  153.      c_DeviceName.ShowWindow(found ? SW_SHOW : SW_HIDE);
  154.      ByteFormat = (hex ? _T("%02x") : _T("%u"));
  155.      WordFormat = (hex ? _T("%04x") : _T("%u"));
  156.      DWordFormat = (hex ? _T("%08x") : _T("%u"));
  157.      c_VendorID.SetWindowText(data.PciData.VendorID, WordFormat);
  158.      c_DeviceID.SetWindowText(data.PciData.DeviceID, WordFormat);
  159.      c_Command.SetWindowText(data.PciData.Command, WordFormat);
  160.      c_Status.SetWindowText(data.PciData.Status, WordFormat);
  161.      c_RevisionID.SetWindowText(data.PciData.RevisionID, ByteFormat);
  162.      c_ProgIf.SetWindowText(data.PciData.ProgIf, ByteFormat);
  163.      c_SubClass.SetWindowText(data.PciData.SubClass, ByteFormat);
  164.      c_BaseClass.SetWindowText(data.PciData.BaseClass, ByteFormat);
  165.      c_CacheLineSize.SetWindowText(data.PciData.CacheLineSize, ByteFormat);
  166.      c_LatencyTimer.SetWindowText(data.PciData.LatencyTimer, ByteFormat);
  167.      c_HeaderType.SetWindowText(data.PciData.HeaderType, ByteFormat);
  168.      c_BIST.SetWindowText(data.PciData.BIST, ByteFormat);
  169.      
  170.      c_Bus.SetWindowText(data.BusNumber, ByteFormat);
  171.      c_Device.SetWindowText(data.SlotData.u.bits.DeviceNumber, ByteFormat);
  172.      c_Function.SetWindowText(data.SlotData.u.bits.FunctionNumber, ByteFormat);
  173.      // This is always a Type 0 header. A Type 1 header would use a
  174.      // different class, or subclass this one...
  175.      c_BaseAddress0.SetWindowText  (data.PciData.u.type0.BaseAddresses[0], DWordFormat);
  176.      c_BaseAddress1.SetWindowText  (data.PciData.u.type0.BaseAddresses[1], DWordFormat);
  177.      c_BaseAddress2.SetWindowText  (data.PciData.u.type0.BaseAddresses[2], DWordFormat);
  178.      c_BaseAddress3.SetWindowText  (data.PciData.u.type0.BaseAddresses[3], DWordFormat);
  179.      c_BaseAddress4.SetWindowText  (data.PciData.u.type0.BaseAddresses[4], DWordFormat);
  180.      c_BaseAddress5.SetWindowText  (data.PciData.u.type0.BaseAddresses[5], DWordFormat);
  181.      c_CIS.SetWindowText           (data.PciData.u.type0.CIS, DWordFormat);
  182.      c_SubVendorID.SetWindowText   (data.PciData.u.type0.SubVendorID, WordFormat);
  183.      c_SubSystemID.SetWindowText   (data.PciData.u.type0.SubSystemID, WordFormat);
  184.      c_ROMBaseAddress.SetWindowText(data.PciData.u.type0.ROMBaseAddress, DWordFormat);
  185.      c_Reserved1.SetWindowText     (data.PciData.u.type0.Reserved2[0], DWordFormat);
  186.      c_Reserved2.SetWindowText     (data.PciData.u.type0.Reserved2[1], DWordFormat);
  187.      c_InterruptLine.SetWindowText (data.PciData.u.type0.InterruptLine, ByteFormat);
  188.      c_InterruptPin.SetWindowText  (data.PciData.u.type0.InterruptPin, ByteFormat);
  189.      c_MinimumGrant.SetWindowText  (data.PciData.u.type0.MinimumGrant, ByteFormat);
  190.      c_MaximumLatency.SetWindowText(data.PciData.u.type0.MaximumLatency, ByteFormat);
  191.      c_Data.ResetContent();
  192.      for(int i = 0; i < sizeof(data.PciData.DeviceSpecific); i += sizeof(DWORD))
  193.         { /* load dev specific */
  194.  c_Data.AddString(*(DWORD*)&data.PciData.DeviceSpecific[i]);
  195. } /* load dev specific */
  196.     }
  197. BOOL PCIData::OnInitDialog() 
  198. {
  199. CPropertyPage::OnInitDialog();
  200.   CheckRadioButton(IDC_HEX, IDC_DECIMAL, IDC_HEX);
  201. c_DisplayAs.AddStrings(Displays);
  202. c_DisplayAs.SetCurSel(0);
  203. c_Data.SetFormat(c_DisplayAs.GetItemData(c_DisplayAs.GetCurSel()));
  204.   LoadPCIData();
  205. SetWindowText(caption);
  206. return TRUE;  // return TRUE unless you set the focus to a control
  207.               // EXCEPTION: OCX Property Pages should return FALSE
  208. }
  209. void PCIData::OnHex() 
  210. {
  211.  LoadPCIData();
  212. }
  213. void PCIData::OnDecimal() 
  214. {
  215.  LoadPCIData();
  216. }
  217. void PCIData::OnSelendokDisplayas() 
  218. {
  219.  c_Data.SetFormat(c_DisplayAs.GetItemData(c_DisplayAs.GetCurSel()));
  220. }
  221. void PCIData::PostNcDestroy() 
  222. {
  223.   delete [] (LPTSTR)m_psp.pszTitle;
  224.   delete this;
  225. CPropertyPage::PostNcDestroy();
  226. }