ReactOS  0.4.15-dev-1392-g3014417
hwresource.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS devmgr.dll
3  * FILE: dll/win32/devmgr/hwresource.c
4  * PURPOSE: ReactOS Device Manager
5  * PROGRAMMER: Johannes Anderwald <johannes.anderwald@reactos.org>
6  * UPDATE HISTORY:
7  * 2005/11/24 Created
8  */
9 
10 #include "precomp.h"
11 #include "properties.h"
12 #include "resource.h"
13 
14 
15 typedef struct
16 {
19 
20 
22 
23 /* Physical Addresses are always treated as 64-bit wide */
25 
26 #include <pshpack4.h>
31  union {
32  struct {
35  } Generic;
36  struct {
38  ULONG Length;
39  } Port;
40  struct {
41 #if defined(NT_PROCESSOR_GROUPS)
42  USHORT Level;
43  USHORT Group;
44 #else
46 #endif
49  } Interrupt;
50 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
51  struct {
52  union {
53  struct {
54 #if defined(NT_PROCESSOR_GROUPS)
55  USHORT Group;
56 #else
58 #endif
60  ULONG Vector;
62  } Raw;
63  struct {
64 #if defined(NT_PROCESSOR_GROUPS)
65  USHORT Level;
66  USHORT Group;
67 #else
68  ULONG Level;
69 #endif
70  ULONG Vector;
72  } Translated;
75 #endif
76  struct {
78  ULONG Length;
79  } Memory;
80  struct {
84  } Dma;
85  struct {
86  ULONG Data[3];
87  } DevicePrivate;
88  struct {
90  ULONG Length;
92  } BusNumber;
93  struct {
98 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
99  struct {
102  } Memory40;
103  struct {
106  } Memory48;
107  struct {
110  } Memory64;
111 #endif
112  } u;
114 #include <poppack.h>
121 
122 #define CmResourceTypeNull 0
123 #define CmResourceTypePort 1
124 #define CmResourceTypeInterrupt 2
125 #define CmResourceTypeMemory 3
126 #define CmResourceTypeDma 4
127 #define CmResourceTypeDeviceSpecific 5
128 #define CmResourceTypeBusNumber 6
129 #define CmResourceTypeNonArbitrated 128
130 #define CmResourceTypeConfigData 128
131 #define CmResourceTypeDevicePrivate 129
132 #define CmResourceTypePcCardConfig 130
133 #define CmResourceTypeMfCardConfig 131
134 
135 typedef enum _INTERFACE_TYPE {
156 
162 
163 typedef struct _CM_RESOURCE_LIST {
167 
168 
169 #define CX_TYPECOLUMN_WIDTH 120
170 
171 static VOID
173  IN HWND hWndDevList)
174 {
175  LVCOLUMN lvc;
176  RECT rcClient;
177  WCHAR szColName[255];
178  int iCol = 0;
179 
180  /* set the list view style */
183 
184  GetClientRect(hWndDevList,
185  &rcClient);
186 
187  /* add the list view columns */
188  lvc.mask = LVCF_TEXT | LVCF_WIDTH;
189  lvc.fmt = LVCFMT_LEFT;
190  lvc.pszText = szColName;
191 
194  szColName,
195  sizeof(szColName) / sizeof(szColName[0])))
196  {
197  lvc.cx = CX_TYPECOLUMN_WIDTH;
198  (void)ListView_InsertColumn(hWndDevList,
199  iCol++,
200  &lvc);
201  }
204  szColName,
205  sizeof(szColName) / sizeof(szColName[0])))
206  {
207  lvc.cx = rcClient.right - CX_TYPECOLUMN_WIDTH -
209 
210  (void)ListView_InsertColumn(hWndDevList,
211  iCol++,
212  &lvc);
213  }
214 }
215 
216 VOID
218  IN HWND hWndDevList,
219  IN INT ItemCount,
220  IN LPWSTR ResourceType,
221  IN LPWSTR ResourceDescription)
222 {
223  INT iItem;
224  LVITEM li = {0};
225 
226  li.mask = LVIF_STATE | LVIF_TEXT;
227  li.iItem = ItemCount;
228  li.pszText = ResourceType;
229  //li.iImage = ClassDevInfo->ImageIndex;
230  iItem = ListView_InsertItem(hWndDevList, &li);
231 
232  if (iItem != -1)
233  {
234  li.mask = LVIF_TEXT;
235  li.iItem = iItem;
236  li.iSubItem = 1;
237  li.pszText = ResourceDescription;
238  (void)ListView_SetItem(hWndDevList, &li);
239  }
240 }
241 
242 VOID
244  IN PDEVADVPROP_INFO dap,
245  IN HWND hWndDevList)
246 {
247  WCHAR szBuffer[100];
248  WCHAR szDetail[100];
250  ULONG ItemCount = 0, Index;
251 
252  ResourceList = (PCM_RESOURCE_LIST)dap->pResourceList;
253 
254  for (Index = 0; Index < ResourceList->List[0].PartialResourceList.Count; Index++)
255  {
256  PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[Index];
257  if (Descriptor->Type == CmResourceTypeInterrupt)
258  {
259  if (LoadString(hDllInstance, IDS_RESOURCE_INTERRUPT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
260  {
261  wsprintf(szDetail, L"0x%08x (%d)", Descriptor->u.Interrupt.Level, Descriptor->u.Interrupt.Vector);
262  InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
263  ItemCount++;
264  }
265  }
266  else if (Descriptor->Type == CmResourceTypePort)
267  {
268  if (LoadString(hDllInstance, IDS_RESOURCE_PORT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
269  {
270  wsprintf(szDetail, L"%08lx - %08lx", Descriptor->u.Port.Start.LowPart, Descriptor->u.Port.Start.LowPart + Descriptor->u.Port.Length - 1);
271  InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
272  ItemCount++;
273  }
274  }
275  else if (Descriptor->Type == CmResourceTypeMemory)
276  {
277  if (LoadString(hDllInstance, IDS_RESOURCE_MEMORY_RANGE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
278  {
279  wsprintf(szDetail, L"%08I64x - %08I64x", Descriptor->u.Memory.Start.QuadPart, Descriptor->u.Memory.Start.QuadPart + Descriptor->u.Memory.Length - 1);
280  InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
281  ItemCount++;
282  }
283  }
284  else if (Descriptor->Type == CmResourceTypeDma)
285  {
286  if (LoadString(hDllInstance, IDS_RESOURCE_DMA, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
287  {
288  wsprintf(szDetail, L"%08ld", Descriptor->u.Dma.Channel);
289  InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
290  ItemCount++;
291  }
292  }
293  }
294 }
295 
296 
297 static VOID
299  IN PDEVADVPROP_INFO dap)
300 {
301  /* set the device image */
302  SendDlgItemMessage(hwndDlg,
303  IDC_DEVICON,
304  STM_SETICON,
305  (WPARAM)dap->hDevIcon,
306  0);
307 
308  /* set the device name edit control text */
309  SetDlgItemText(hwndDlg,
310  IDC_DEVNAME,
311  dap->szDevName);
312 }
313 
314 INT_PTR
315 CALLBACK
317  IN UINT uMsg,
318  IN WPARAM wParam,
319  IN LPARAM lParam)
320 {
321  PDEVADVPROP_INFO hpd;
322  HWND hWndDevList;
323  INT_PTR Ret = FALSE;
324 
326 
327  if (hpd != NULL || uMsg == WM_INITDIALOG)
328  {
329  switch (uMsg)
330  {
331  case WM_INITDIALOG:
332  {
333  /* init list */
334  hWndDevList = GetDlgItem(hwndDlg, IDC_DRIVERRESOURCES);
335  InitializeDevicesList(hWndDevList);
336 
338  if (hpd != NULL)
339  {
340  SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR)hpd);
341 
342  UpdateDriverResourceDlg(hwndDlg, hpd);
343  AddResourceItems(hpd, hWndDevList);
344  }
345 
346  Ret = TRUE;
347  break;
348  }
349  }
350  }
351 
352  return Ret;
353 }
354 
355 
356 PVOID
358  LPWSTR pszDeviceID)
359 {
360  PCM_RESOURCE_LIST pResourceList = NULL;
361  HKEY hKey = NULL;
362  DWORD dwError, dwSize;
363 
364  CStringW keyName = L"SYSTEM\\CurrentControlSet\\Enum\\";
365  keyName += pszDeviceID;
366  keyName += L"\\LogConf";
367 
368  dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey);
369  if (dwError != ERROR_SUCCESS)
370  {
371  /* failed to open device instance log conf dir */
372  return NULL;
373  }
374 
375  dwSize = 0;
376  RegQueryValueExW(hKey, L"BootConfig", NULL, NULL, NULL, &dwSize);
377  if (dwSize == 0)
378  goto done;
379 
380  pResourceList = static_cast<PCM_RESOURCE_LIST>(HeapAlloc(GetProcessHeap(), 0, dwSize));
381  if (pResourceList == NULL)
382  goto done;
383 
384  dwError = RegQueryValueExW(hKey, L"BootConfig", NULL, NULL, (LPBYTE)pResourceList, &dwSize);
385  if (dwError != ERROR_SUCCESS)
386  {
387  HeapFree(GetProcessHeap(), 0, pResourceList);
388  pResourceList = NULL;
389  }
390 
391 done:
392  if (hKey != NULL)
393  RegCloseKey(hKey);
394 
395  return (PVOID)pResourceList;
396 }
struct _CM_PARTIAL_RESOURCE_LIST CM_PARTIAL_RESOURCE_LIST
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define STM_SETICON
Definition: winuser.h:2074
#define IN
Definition: typedefs.h:39
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR * PCM_PARTIAL_RESOURCE_DESCRIPTOR
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@397 Memory64
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
#define LVCF_WIDTH
Definition: commctrl.h:2583
enum _INTERFACE_TYPE INTERFACE_TYPE
#define ERROR_SUCCESS
Definition: deptool.c:10
INT_PTR CALLBACK ResourcesProcDriverDlgProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: hwresource.cpp:316
#define ListView_SetItem(hwnd, pitem)
Definition: commctrl.h:2397
struct _DEVADVPROP_INFO * PDEVADVPROP_INFO
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@389::@398::@400 Translated
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@388 Interrupt
#define LVCF_TEXT
Definition: commctrl.h:2584
struct _CM_PARTIAL_RESOURCE_LIST * PCM_PARTIAL_RESOURCE_LIST
#define IDC_DEVICON
Definition: resource.h:223
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@392 DevicePrivate
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
_In_opt_ PSID Group
Definition: rtlfuncs.h:1605
#define CALLBACK
Definition: compat.h:35
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2730
#define LVCFMT_LEFT
Definition: commctrl.h:2594
struct _CM_FULL_RESOURCE_DESCRIPTOR CM_FULL_RESOURCE_DESCRIPTOR
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@389::@398 DUMMYUNIONNAME
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@394 DeviceSpecificData
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5817
enum _INTERFACE_TYPE * PINTERFACE_TYPE
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2404
int32_t INT_PTR
Definition: typedefs.h:64
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@387 Port
LONG right
Definition: windef.h:308
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
struct HARDWARE_RESOURCE_DATA * PHARDWARE_RESOURCE_DATA
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define LVIF_TEXT
Definition: commctrl.h:2305
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
static VOID InitializeDevicesList(IN HWND hWndDevList)
Definition: hwresource.cpp:172
#define LVCOLUMN
Definition: commctrl.h:2577
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385 u
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2632
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
#define IDC_DRIVERRESOURCES
Definition: resource.h:253
#define IDS_RESOURCE_MEMORY_RANGE
Definition: resource.h:126
struct _CM_FULL_RESOURCE_DESCRIPTOR * PCM_FULL_RESOURCE_DESCRIPTOR
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@391 Dma
#define LPPROPSHEETPAGE
Definition: prsht.h:390
VOID AddResourceItems(IN PDEVADVPROP_INFO dap, IN HWND hWndDevList)
Definition: hwresource.cpp:243
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_DEVNAME
Definition: resource.h:224
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@393 BusNumber
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@395 Memory40
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@389 MessageInterrupt
static HINSTANCE hDllInstance
Definition: clb.c:30
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@396 Memory48
VOID InsertListItem(IN HWND hWndDevList, IN INT ItemCount, IN LPWSTR ResourceType, IN LPWSTR ResourceDescription)
Definition: hwresource.cpp:217
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LARGE_INTEGER * PPHYSICAL_ADDRESS
Definition: hwresource.cpp:24
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
PVOID GetResourceList(LPWSTR pszDeviceID)
Definition: hwresource.cpp:357
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ WDFCOLLECTION _In_ ULONG Index
#define CX_TYPECOLUMN_WIDTH
Definition: hwresource.cpp:169
int WINAPI GetSystemMetrics(_In_ int)
#define for
Definition: utility.h:88
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_RESOURCE_INTERRUPT
Definition: resource.h:127
#define ListView_SetExtendedListViewStyle(hwndLV, dw)
Definition: commctrl.h:2721
#define SetDlgItemText
Definition: winuser.h:5824
static VOID UpdateDriverResourceDlg(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap)
Definition: hwresource.cpp:298
unsigned char UCHAR
Definition: xmlstorage.h:181
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
static const WCHAR L[]
Definition: oid.c:1250
#define DWLP_USER
Definition: winuser.h:866
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@389::@398::@399 Raw
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
uint32_t DWORD_PTR
Definition: typedefs.h:65
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
LARGE_INTEGER PHYSICAL_ADDRESS
Definition: hwresource.cpp:24
_INTERFACE_TYPE
Definition: hwresource.cpp:135
unsigned short USHORT
Definition: pedump.c:61
FxAutoRegKey hKey
ULONG_PTR KAFFINITY
Definition: compat.h:85
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define SM_CXVSCROLL
Definition: winuser.h:951
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define IDS_RESOURCE_PORT
Definition: resource.h:129
#define LVITEM
Definition: commctrl.h:2371
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@386 Generic
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
CAtlStringW CStringW
Definition: atlstr.h:130
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LVIF_STATE
Definition: commctrl.h:2308
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define IDS_RESOURCE_DMA
Definition: resource.h:128
#define wsprintf
Definition: winuser.h:5840
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@390 Memory
#define IDS_RESOURCE_COLUMN
Definition: resource.h:124
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define HeapFree(x, y, z)
Definition: compat.h:594
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define LoadString
Definition: winuser.h:5794
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
#define CmResourceTypeDma
Definition: hwresource.cpp:126
#define IDS_SETTING_COLUMN
Definition: resource.h:125
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12