* Sync up to trunk head (r64921).
[reactos.git] / dll / win32 / devmgr / hwresource.c
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
12
13 typedef struct
14 {
15 HWND hWnd;
16 HWND hWndDevList;
17
18
19 }HARDWARE_RESOURCE_DATA, *PHARDWARE_RESOURCE_DATA;
20
21 /* Physical Addresses are always treated as 64-bit wide */
22 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
23
24 #include <pshpack4.h>
25 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
26 UCHAR Type;
27 UCHAR ShareDisposition;
28 USHORT Flags;
29 union {
30 struct {
31 PHYSICAL_ADDRESS Start;
32 ULONG Length;
33 } Generic;
34 struct {
35 PHYSICAL_ADDRESS Start;
36 ULONG Length;
37 } Port;
38 struct {
39 #if defined(NT_PROCESSOR_GROUPS)
40 USHORT Level;
41 USHORT Group;
42 #else
43 ULONG Level;
44 #endif
45 ULONG Vector;
46 KAFFINITY Affinity;
47 } Interrupt;
48 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
49 struct {
50 _ANONYMOUS_UNION union {
51 struct {
52 #if defined(NT_PROCESSOR_GROUPS)
53 USHORT Group;
54 #else
55 USHORT Reserved;
56 #endif
57 USHORT MessageCount;
58 ULONG Vector;
59 KAFFINITY Affinity;
60 } Raw;
61 struct {
62 #if defined(NT_PROCESSOR_GROUPS)
63 USHORT Level;
64 USHORT Group;
65 #else
66 ULONG Level;
67 #endif
68 ULONG Vector;
69 KAFFINITY Affinity;
70 } Translated;
71 } DUMMYUNIONNAME;
72 } MessageInterrupt;
73 #endif
74 struct {
75 PHYSICAL_ADDRESS Start;
76 ULONG Length;
77 } Memory;
78 struct {
79 ULONG Channel;
80 ULONG Port;
81 ULONG Reserved1;
82 } Dma;
83 struct {
84 ULONG Data[3];
85 } DevicePrivate;
86 struct {
87 ULONG Start;
88 ULONG Length;
89 ULONG Reserved;
90 } BusNumber;
91 struct {
92 ULONG DataSize;
93 ULONG Reserved1;
94 ULONG Reserved2;
95 } DeviceSpecificData;
96 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
97 struct {
98 PHYSICAL_ADDRESS Start;
99 ULONG Length40;
100 } Memory40;
101 struct {
102 PHYSICAL_ADDRESS Start;
103 ULONG Length48;
104 } Memory48;
105 struct {
106 PHYSICAL_ADDRESS Start;
107 ULONG Length64;
108 } Memory64;
109 #endif
110 } u;
111 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
112 #include <poppack.h>
113 typedef struct _CM_PARTIAL_RESOURCE_LIST {
114 USHORT Version;
115 USHORT Revision;
116 ULONG Count;
117 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
118 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
119
120 #define CmResourceTypeNull 0
121 #define CmResourceTypePort 1
122 #define CmResourceTypeInterrupt 2
123 #define CmResourceTypeMemory 3
124 #define CmResourceTypeDma 4
125 #define CmResourceTypeDeviceSpecific 5
126 #define CmResourceTypeBusNumber 6
127 #define CmResourceTypeNonArbitrated 128
128 #define CmResourceTypeConfigData 128
129 #define CmResourceTypeDevicePrivate 129
130 #define CmResourceTypePcCardConfig 130
131 #define CmResourceTypeMfCardConfig 131
132
133 typedef enum _INTERFACE_TYPE {
134 InterfaceTypeUndefined = -1,
135 Internal,
136 Isa,
137 Eisa,
138 MicroChannel,
139 TurboChannel,
140 PCIBus,
141 VMEBus,
142 NuBus,
143 PCMCIABus,
144 CBus,
145 MPIBus,
146 MPSABus,
147 ProcessorInternal,
148 InternalPowerBus,
149 PNPISABus,
150 PNPBus,
151 Vmcs,
152 MaximumInterfaceType
153 } INTERFACE_TYPE, *PINTERFACE_TYPE;
154
155 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
156 INTERFACE_TYPE InterfaceType;
157 ULONG BusNumber;
158 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
159 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
160
161 typedef struct _CM_RESOURCE_LIST {
162 ULONG Count;
163 CM_FULL_RESOURCE_DESCRIPTOR List[1];
164 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
165
166
167 #define CX_TYPECOLUMN_WIDTH 120
168
169 static VOID
170 InitializeDevicesList(
171 IN HWND hWndDevList)
172 {
173 LVCOLUMN lvc;
174 RECT rcClient;
175 WCHAR szColName[255];
176 int iCol = 0;
177
178 /* set the list view style */
179 (void)ListView_SetExtendedListViewStyle(hWndDevList,
180 LVS_EX_FULLROWSELECT);
181
182 GetClientRect(hWndDevList,
183 &rcClient);
184
185 /* add the list view columns */
186 lvc.mask = LVCF_TEXT | LVCF_WIDTH;
187 lvc.fmt = LVCFMT_LEFT;
188 lvc.pszText = szColName;
189
190 if (LoadString(hDllInstance,
191 IDS_RESOURCE_COLUMN,
192 szColName,
193 sizeof(szColName) / sizeof(szColName[0])))
194 {
195 lvc.cx = CX_TYPECOLUMN_WIDTH;
196 (void)ListView_InsertColumn(hWndDevList,
197 iCol++,
198 &lvc);
199 }
200 if (LoadString(hDllInstance,
201 IDS_SETTING_COLUMN,
202 szColName,
203 sizeof(szColName) / sizeof(szColName[0])))
204 {
205 lvc.cx = rcClient.right - CX_TYPECOLUMN_WIDTH -
206 GetSystemMetrics(SM_CXVSCROLL);
207
208 (void)ListView_InsertColumn(hWndDevList,
209 iCol++,
210 &lvc);
211 }
212 }
213
214 VOID
215 InsertListItem(
216 IN HWND hWndDevList,
217 IN INT ItemCount,
218 IN LPWSTR ResourceType,
219 IN LPWSTR ResourceDescription)
220 {
221 INT iItem;
222 LVITEM li = {0};
223
224 li.mask = LVIF_STATE | LVIF_TEXT;
225 li.iItem = ItemCount;
226 li.pszText = ResourceType;
227 //li.iImage = ClassDevInfo->ImageIndex;
228 iItem = ListView_InsertItem(hWndDevList, &li);
229
230 if (iItem != -1)
231 {
232 li.mask = LVIF_TEXT;
233 li.iItem = iItem;
234 li.iSubItem = 1;
235 li.pszText = ResourceDescription;
236 (void)ListView_SetItem(hWndDevList, &li);
237 }
238 }
239
240 VOID
241 AddResourceItems(
242 IN PDEVADVPROP_INFO dap,
243 IN HWND hWndDevList)
244 {
245 HKEY hKey;
246 WCHAR szBuffer[100];
247 WCHAR szDetail[100];
248 BYTE szData[512];
249 DWORD dwSize;
250 PCM_RESOURCE_LIST ResourceList;
251 LONG Result;
252 ULONG ItemCount = 0, Index;
253
254 wsprintf(szBuffer, L"SYSTEM\\CurrentControlSet\\Enum\\%s\\LogConf", dap->szDeviceID);
255 Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ, &hKey);
256 if (Result != ERROR_SUCCESS)
257 {
258 /* failed to open device instance log conf dir */
259 return;
260 }
261
262 dwSize = sizeof(szData);
263 Result = RegQueryValueExW(hKey, L"BootConfig", NULL, NULL, szData, &dwSize);
264
265 RegCloseKey(hKey);
266 if (Result != ERROR_SUCCESS)
267 {
268 /* failed to query resources */
269 return;
270 }
271
272 ResourceList = (PCM_RESOURCE_LIST)szData;
273
274 for (Index = 0; Index < ResourceList->List[0].PartialResourceList.Count; Index++)
275 {
276 PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[Index];
277 if (Descriptor->Type == CmResourceTypeInterrupt)
278 {
279 if (LoadString(hDllInstance, IDS_RESOURCE_INTERRUPT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
280 {
281 wsprintf(szDetail, L"0x%08x (%d)", Descriptor->u.Interrupt.Level, Descriptor->u.Interrupt.Vector);
282 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
283 ItemCount++;
284 }
285 }
286 else if (Descriptor->Type == CmResourceTypePort)
287 {
288 if (LoadString(hDllInstance, IDS_RESOURCE_PORT, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
289 {
290 wsprintf(szDetail, L"%08lx - %08lx", Descriptor->u.Port.Start.LowPart, Descriptor->u.Port.Start.LowPart + Descriptor->u.Port.Length - 1);
291 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
292 ItemCount++;
293 }
294 }
295 else if (Descriptor->Type == CmResourceTypeMemory)
296 {
297 if (LoadString(hDllInstance, IDS_RESOURCE_MEMORY_RANGE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
298 {
299 wsprintf(szDetail, L"%08I64x - %08I64x", Descriptor->u.Memory.Start.QuadPart, Descriptor->u.Memory.Start.QuadPart + Descriptor->u.Memory.Length - 1);
300 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
301 ItemCount++;
302 }
303 }
304 else if (Descriptor->Type == CmResourceTypeDma)
305 {
306 if (LoadString(hDllInstance, IDS_RESOURCE_DMA, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])))
307 {
308 wsprintf(szDetail, L"%08ld", Descriptor->u.Dma.Channel);
309 InsertListItem(hWndDevList, ItemCount, szBuffer, szDetail);
310 ItemCount++;
311 }
312 }
313 }
314 }
315
316
317 static VOID
318 UpdateDriverResourceDlg(IN HWND hwndDlg,
319 IN PDEVADVPROP_INFO dap)
320 {
321 /* set the device image */
322 SendDlgItemMessage(hwndDlg,
323 IDC_DEVICON,
324 STM_SETICON,
325 (WPARAM)dap->hDevIcon,
326 0);
327
328 /* set the device name edit control text */
329 SetDlgItemText(hwndDlg,
330 IDC_DEVNAME,
331 dap->szDevName);
332 }
333
334 INT_PTR
335 CALLBACK
336 ResourcesProcDriverDlgProc(IN HWND hwndDlg,
337 IN UINT uMsg,
338 IN WPARAM wParam,
339 IN LPARAM lParam)
340 {
341 PDEVADVPROP_INFO hpd;
342 HWND hWndDevList;
343 INT_PTR Ret = FALSE;
344
345 hpd = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg,
346 DWL_USER);
347
348 if (hpd != NULL || uMsg == WM_INITDIALOG)
349 {
350 switch (uMsg)
351 {
352 case WM_INITDIALOG:
353 {
354 /* init list */
355 hWndDevList = GetDlgItem(hwndDlg, IDC_DRIVERRESOURCES);
356 InitializeDevicesList(hWndDevList);
357
358 hpd = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam;
359 if (hpd != NULL)
360 {
361 SetWindowLongPtr(hwndDlg,
362 DWL_USER,
363 (DWORD_PTR)hpd);
364
365 SetWindowLongPtr(hwndDlg,
366 DWL_USER,
367 (DWORD_PTR)hpd);
368
369 UpdateDriverResourceDlg(hwndDlg, hpd);
370 AddResourceItems(hpd, hWndDevList);
371 }
372
373 Ret = TRUE;
374 break;
375 }
376 }
377 }
378
379 return Ret;
380 }
381