ReactOS 0.4.16-dev-319-g6cf4263
kdpci.c File Reference
#include <hal.h>
Include dependency graph for kdpci.c:

Go to the source code of this file.

Macros

#define DPRINT0
 

Functions

static ULONG HalpPciBarLength (_In_ ULONG CurrentBar, _In_ ULONG NextBar)
 
static BOOLEAN HalpConfigureDebuggingDevice (_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice, _In_ ULONG PciBus, _In_ PCI_SLOT_NUMBER PciSlot, _Inout_ PPCI_COMMON_HEADER PciConfig)
 
static BOOLEAN HalpMatchDebuggingDevice (_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice, _In_ ULONG PciBus, _In_ PCI_SLOT_NUMBER PciSlot, _In_ PPCI_COMMON_HEADER PciConfig)
 
static BOOLEAN HalpFindMatchingDebuggingDevice (_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 
VOID NTAPI HalpRegisterPciDebuggingDeviceInfo (VOID)
 
NTSTATUS NTAPI HalpReleasePciDeviceForDebugging (_Inout_ PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 Releases the PCI device MMIO mappings previously allocated with HalpSetupPciDeviceForDebugging().
 
NTSTATUS NTAPI HalpSetupPciDeviceForDebugging (_In_opt_ PVOID LoaderBlock, _Inout_ PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 Finds and fully initializes the PCI device associated with the supplied debug device descriptor.
 

Variables

PCI_TYPE1_CFG_CYCLE_BITS HalpPciDebuggingDevice [2] = {0}
 

Macro Definition Documentation

◆ DPRINT0

#define DPRINT0

Definition at line 27 of file kdpci.c.

Function Documentation

◆ HalpConfigureDebuggingDevice()

static BOOLEAN HalpConfigureDebuggingDevice ( _In_ PDEBUG_DEVICE_DESCRIPTOR  PciDevice,
_In_ ULONG  PciBus,
_In_ PCI_SLOT_NUMBER  PciSlot,
_Inout_ PPCI_COMMON_HEADER  PciConfig 
)
static

Definition at line 72 of file kdpci.c.

77{
79
80 Register = PciConfig->Command & ~(PCI_ENABLE_MEMORY_SPACE |
83 PciSlot,
84 &Register,
86 sizeof(USHORT));
87
88 /* Fill out the device descriptor */
89 for (i = 0; i < MAXIMUM_DEBUG_BARS; ++i)
90 {
91 ULONG Length, NextBar;
93
94 DeviceAddress = &PciDevice->BaseAddress[i];
95 DeviceAddress->Valid = FALSE;
96
97 Register = 0xFFFFFFFF;
99 PciSlot,
100 &Register,
101 FIELD_OFFSET(PCI_COMMON_HEADER, u.type0.BaseAddresses[i]),
102 sizeof(ULONG));
104 PciSlot,
105 &Register,
106 FIELD_OFFSET(PCI_COMMON_HEADER, u.type0.BaseAddresses[i]),
107 sizeof(ULONG));
109 PciSlot,
110 &PciConfig->u.type0.BaseAddresses[i],
111 FIELD_OFFSET(PCI_COMMON_HEADER, u.type0.BaseAddresses[i]),
112 sizeof(ULONG));
113
114 if (i < MAXIMUM_DEBUG_BARS - 1)
115 NextBar = PciConfig->u.type0.BaseAddresses[i + 1];
116 else
117 NextBar = 0;
118
119 Length = HalpPciBarLength(Register, NextBar);
120 if (Register == 0 || Length == 0)
121 continue;
122
123 /* I/O space */
125 {
127 DeviceAddress->Length = Length;
128 DeviceAddress->Valid = TRUE;
129 DeviceAddress->TranslatedAddress =
130 UlongToPtr(PciConfig->u.type0.BaseAddresses[i] & PCI_ADDRESS_IO_ADDRESS_MASK);
131
132 DPRINT0("BAR[%u] IO %lx, length 0x%lx, 0x%lx\n",
133 i,
134 DeviceAddress->TranslatedAddress,
135 Length,
136 Register);
137 }
138 else
139 {
141 BOOLEAN SkipBar = FALSE;
142
144 DeviceAddress->Length = Length;
145 DeviceAddress->Valid = TRUE;
146
147 /* 32-bit memory space */
150 PciConfig->u.type0.BaseAddresses[i] & PCI_ADDRESS_MEMORY_ADDRESS_MASK;
151
152 /* 64-bit memory space */
154 {
155 PhysicalAddress.HighPart = NextBar;
156 SkipBar = TRUE;
157 }
158
159 DPRINT0("BAR[%u] MEM %I64x, length 0x%lx, 0x%lx\n",
160 i,
162 Length,
163 Register);
164
165 if (SkipBar)
166 {
167 ++i;
168 }
169
170 DeviceAddress->TranslatedAddress =
172 }
173 }
174 PciDevice->Bus = PciBus;
175 PciDevice->Slot = PciSlot.u.AsULONG;
176 PciDevice->VendorID = PciConfig->VendorID;
177 PciDevice->DeviceID = PciConfig->DeviceID;
178 PciDevice->BaseClass = PciConfig->BaseClass;
179 PciDevice->SubClass = PciConfig->SubClass;
180 PciDevice->ProgIf = PciConfig->ProgIf;
181
182 /* Enable decodes */
183 PciConfig->Command |= (PCI_ENABLE_MEMORY_SPACE |
187 PciSlot,
188 &PciConfig->Command,
190 sizeof(USHORT));
191
192 return TRUE;
193}
unsigned char BOOLEAN
ULONG HalpPhase0SetPciDataByOffset(_In_ ULONG Bus, _In_ PCI_SLOT_NUMBER PciSlot, _In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Offset, _In_ ULONG Length)
Definition: pcibus.c:437
ULONG HalpPhase0GetPciDataByOffset(_In_ ULONG Bus, _In_ PCI_SLOT_NUMBER PciSlot, _Out_writes_bytes_all_(Length) PVOID Buffer, _In_ ULONG Offset, _In_ ULONG Length)
Definition: pcibus.c:368
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define UlongToPtr(u)
Definition: config.h:106
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
PVOID NTAPI HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress, IN PFN_COUNT PageCount)
Definition: memory.c:140
_In_ PUSB_DEVICE_HANDLE _Out_ PUSHORT DeviceAddress
Definition: hubbusif.h:360
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypePort
Definition: hwresource.cpp:123
static ULONG HalpPciBarLength(_In_ ULONG CurrentBar, _In_ ULONG NextBar)
Definition: kdpci.c:38
#define DPRINT0
Definition: kdpci.c:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
Definition: shell.h:41
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
#define PCI_TYPE_64BIT
Definition: iotypes.h:4239
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
#define PCI_ADDRESS_IO_ADDRESS_MASK
Definition: iotypes.h:4233
#define PCI_ENABLE_BUS_MASTER
Definition: iotypes.h:3618
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3616
#define PCI_ADDRESS_IO_SPACE
Definition: iotypes.h:4230
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3617
#define PCI_ADDRESS_MEMORY_ADDRESS_MASK
Definition: iotypes.h:4234
#define PCI_ADDRESS_MEMORY_TYPE_MASK
Definition: iotypes.h:4231
#define MAXIMUM_DEBUG_BARS
Definition: kdtypes.h:53
* PDEBUG_DEVICE_ADDRESS
Definition: kdtypes.h:21
#define BYTES_TO_PAGES(Size)

Referenced by HalpFindMatchingDebuggingDevice().

◆ HalpFindMatchingDebuggingDevice()

static BOOLEAN HalpFindMatchingDebuggingDevice ( _In_ PDEBUG_DEVICE_DESCRIPTOR  PciDevice)
static

Definition at line 237 of file kdpci.c.

239{
240 ULONG BusNumber, DeviceNumber, FunctionNumber;
241
242 for (BusNumber = 0; BusNumber < 0xFF; ++BusNumber)
243 {
245 {
246 for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; ++FunctionNumber)
247 {
248 ULONG Bytes;
249 PCI_SLOT_NUMBER PciSlot;
250 PCI_COMMON_HEADER PciConfig;
251
252 PciSlot.u.bits.DeviceNumber = DeviceNumber;
253 PciSlot.u.bits.FunctionNumber = FunctionNumber;
254 PciSlot.u.bits.Reserved = 0;
256 PciSlot,
257 &PciConfig,
258 0,
261 PciConfig.VendorID == PCI_INVALID_VENDORID ||
262 PciConfig.VendorID == 0)
263 {
264 if (FunctionNumber == 0)
265 {
266 /* This slot has no single- or a multi-function device */
267 break;
268 }
269 else
270 {
271 /* Continue scanning the functions */
272 continue;
273 }
274 }
275
276 DPRINT0("Check %02x:%02x.%x [%04x:%04x]\n",
277 BusNumber, DeviceNumber, FunctionNumber,
278 PciConfig.VendorID, PciConfig.DeviceID);
279
280 switch (PCI_CONFIGURATION_TYPE(&PciConfig))
281 {
282 case PCI_DEVICE_TYPE:
283 {
284 if (HalpMatchDebuggingDevice(PciDevice, BusNumber, PciSlot, &PciConfig))
285 {
286 DPRINT0("Found device\n");
287
288 if (HalpConfigureDebuggingDevice(PciDevice,
289 BusNumber,
290 PciSlot,
291 &PciConfig))
292 {
293 DPRINT0("Device is ready\n");
294 return TRUE;
295 }
296 }
297 break;
298 }
299
300 case PCI_BRIDGE_TYPE:
301 {
302 /* FIXME: Implement PCI resource allocator */
303 break;
304 }
305
307 {
308 /* FIXME: Implement PCI resource allocator */
309 break;
310 }
311
312 default:
313 break;
314 }
315
316 if (!PCI_MULTIFUNCTION_DEVICE(&PciConfig))
317 {
318 /* The device is a single function device */
319 break;
320 }
321 }
322 }
323 }
324
325 return FALSE;
326}
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
static BOOLEAN HalpConfigureDebuggingDevice(_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice, _In_ ULONG PciBus, _In_ PCI_SLOT_NUMBER PciSlot, _Inout_ PPCI_COMMON_HEADER PciConfig)
Definition: kdpci.c:72
static BOOLEAN HalpMatchDebuggingDevice(_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice, _In_ ULONG PciBus, _In_ PCI_SLOT_NUMBER PciSlot, _In_ PPCI_COMMON_HEADER PciConfig)
Definition: kdpci.c:198
_In_ UINT Bytes
Definition: mmcopy.h:9
union _PCI_SLOT_NUMBER::@4023 u
struct _PCI_SLOT_NUMBER::@4023::@4024 bits
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
#define PCI_INVALID_VENDORID
Definition: iotypes.h:3601
#define PCI_CONFIGURATION_TYPE(PciData)
Definition: iotypes.h:3609
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3599
#define PCI_BRIDGE_TYPE
Definition: iotypes.h:3606
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3594
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598
#define PCI_MULTIFUNCTION_DEVICE(PciData)
Definition: iotypes.h:3612
#define PCI_DEVICE_TYPE
Definition: iotypes.h:3605
#define PCI_CARDBUS_BRIDGE_TYPE
Definition: iotypes.h:3607

Referenced by HalpSetupPciDeviceForDebugging().

◆ HalpMatchDebuggingDevice()

static BOOLEAN HalpMatchDebuggingDevice ( _In_ PDEBUG_DEVICE_DESCRIPTOR  PciDevice,
_In_ ULONG  PciBus,
_In_ PCI_SLOT_NUMBER  PciSlot,
_In_ PPCI_COMMON_HEADER  PciConfig 
)
static

Definition at line 198 of file kdpci.c.

203{
204 /* Check if we weren't given a specific device location */
205 if (PciDevice->Bus == 0xFFFFFFFF && PciDevice->Slot == 0xFFFFFFFF)
206 {
207 if (PciDevice->DeviceID == 0xFFFF && PciDevice->VendorID == 0xFFFF)
208 {
209 if (PciDevice->BaseClass == PciConfig->BaseClass &&
210 PciDevice->SubClass == PciConfig->SubClass)
211 {
212 if (PciDevice->ProgIf == 0xFF ||
213 PciDevice->ProgIf == PciConfig->ProgIf)
214 {
215 return TRUE;
216 }
217 }
218 }
219 else if (PciDevice->DeviceID == PciConfig->DeviceID &&
220 PciDevice->VendorID == PciConfig->VendorID)
221 {
222 return TRUE;
223 }
224 }
225 else if (PciDevice->Bus == PciBus &&
226 PciDevice->Slot == PciSlot.u.AsULONG)
227 {
228 return TRUE;
229 }
230
231 return FALSE;
232}

Referenced by HalpFindMatchingDebuggingDevice().

◆ HalpPciBarLength()

static ULONG HalpPciBarLength ( _In_ ULONG  CurrentBar,
_In_ ULONG  NextBar 
)
static

Definition at line 38 of file kdpci.c.

41{
44
45 Bar = CurrentBar;
46
47 if (CurrentBar & PCI_ADDRESS_IO_SPACE)
48 {
49 Length = 1 << 2;
50 }
51 else
52 {
53 if ((CurrentBar & PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_64BIT)
54 {
55 Bar = ((ULONG64)NextBar << 32) | CurrentBar;
56 }
57
58 Length = 1 << 4;
59 }
60
61 while (!(Bar & Length) && Length)
62 {
63 Length <<= 1;
64 }
65
66 return Length;
67}
unsigned __int64 ULONG64
Definition: imports.h:198
void Bar(void)
Definition: terminate.cpp:70

Referenced by HalpConfigureDebuggingDevice().

◆ HalpRegisterPciDebuggingDeviceInfo()

VOID NTAPI HalpRegisterPciDebuggingDeviceInfo ( VOID  )

Definition at line 331 of file kdpci.c.

332{
333 ULONG i;
337 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\"
338 L"CurrentControlSet\\Services\\PCI\\Debug");
340
341 PAGED_CODE();
342
343 for (i = 0; i < RTL_NUMBER_OF(HalpPciDebuggingDevice); ++i)
344 {
345 if (HalpPciDebuggingDevice[i].InUse)
346 {
348 break;
349 }
350 }
352 {
353 /* Nothing to register */
354 return;
355 }
356
358 if (!NT_SUCCESS(Status))
359 return;
360
361 for (i = 0; i < RTL_NUMBER_OF(HalpPciDebuggingDevice); ++i)
362 {
363 ULONG Value;
364 PCI_SLOT_NUMBER PciSlot;
365
366 if (!HalpPciDebuggingDevice[i].InUse)
367 continue;
368
369 RtlInitEmptyUnicodeString(&KeyName, StringBuffer, sizeof(StringBuffer));
372 Handle,
373 &KeyName,
375 TRUE);
376 if (!NT_SUCCESS(Status))
377 continue;
378
381 ZwSetValueKey(KeyHandle,
382 &KeyName,
383 0,
384 REG_DWORD,
385 &Value,
386 sizeof(Value));
387
388 PciSlot.u.AsULONG = 0;
389 PciSlot.u.bits.DeviceNumber = HalpPciDebuggingDevice[i].DeviceNumber;
390 PciSlot.u.bits.FunctionNumber = HalpPciDebuggingDevice[i].FunctionNumber;
391 Value = PciSlot.u.AsULONG;
393 ZwSetValueKey(KeyHandle,
394 &KeyName,
395 0,
396 REG_DWORD,
397 &Value,
398 sizeof(Value));
399
401 }
402
404}
#define PAGED_CODE()
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI HalpOpenRegistryKey(IN PHANDLE KeyHandle, IN HANDLE RootKey, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN BOOLEAN Create)
Definition: misc.c:104
PCI_TYPE1_CFG_CYCLE_BITS HalpPciDebuggingDevice[2]
Definition: kdpci.c:31
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define L(x)
Definition: ntvdm.h:50
BOOLEAN HasDebuggingDevice
Definition: pci.c:32
#define REG_DWORD
Definition: sdbapi.c:596
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by HalReportResourceUsage().

◆ HalpReleasePciDeviceForDebugging()

NTSTATUS NTAPI HalpReleasePciDeviceForDebugging ( _Inout_ PDEBUG_DEVICE_DESCRIPTOR  PciDevice)

Releases the PCI device MMIO mappings previously allocated with HalpSetupPciDeviceForDebugging().

This is used to release resources when a device specific initialization fails.

Parameters
[in,out]PciDevicePointer to the debug device descriptor, whose mappings are to be released.
Returns
STATUS_SUCCESS.

Definition at line 421 of file kdpci.c.

423{
424 ULONG i;
425
426 DPRINT0("%s(%p) called\n", __FUNCTION__, PciDevice);
427
428 for (i = 0; i < MAXIMUM_DEBUG_BARS; ++i)
429 {
430 PDEBUG_DEVICE_ADDRESS DeviceAddress = &PciDevice->BaseAddress[i];
431
432 if (DeviceAddress->Type == CmResourceTypeMemory && DeviceAddress->Valid)
433 {
434 HalpUnmapVirtualAddress(DeviceAddress->TranslatedAddress,
436
437 DeviceAddress->Valid = FALSE;
438 }
439 }
440
441 return STATUS_SUCCESS;
442}
#define __FUNCTION__
Definition: types.h:116
VOID NTAPI HalpUnmapVirtualAddress(IN PVOID VirtualAddress, IN PFN_COUNT PageCount)
Definition: memory.c:148
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by HalpRegisterKdSupportFunctions().

◆ HalpSetupPciDeviceForDebugging()

NTSTATUS NTAPI HalpSetupPciDeviceForDebugging ( _In_opt_ PVOID  LoaderBlock,
_Inout_ PDEBUG_DEVICE_DESCRIPTOR  PciDevice 
)

Finds and fully initializes the PCI device associated with the supplied debug device descriptor.

Parameters
[in]LoaderBlockPointer to the Loader parameter block. Can be NULL.
[in,out]PciDevicePointer to the debug device descriptor.
Returns
Status.

This routine is used to match devices to debug device descriptors during boot phase of the system. This function will search the first device that matches the criteria given by the fields of the debug device descriptor. A value of all 1's for the field will indicate that the function should ignore that field in the search criteria. The Length field of the debug memory requirements optionally specifies library-determined number of bytes to be allocated for the device context.

Example:

PciDevice.VendorID = 0xFFFF;
PciDevice.DeviceID = 0xFFFF;
PciDevice.Bus = 0xFFFFFFFF;
PciDevice.Slot = 0xFFFFFFFF;
PciDevice.BaseClass = PCI_CLASS_SERIAL_BUS_CTLR;
PciDevice.SubClass = PCI_SUBCLASS_SB_USB;
PciDevice.ProgIf = 0x30;
PciDevice.Memory.Length = sizeof(HW_EXTENSION);
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define PCI_SUBCLASS_SB_USB
Definition: iotypes.h:4207
#define PCI_CLASS_SERIAL_BUS_CTLR
Definition: iotypes.h:4115
See also
HalpReleasePciDeviceForDebugging

Definition at line 483 of file kdpci.c.

486{
487 ULONG i;
488 ULONG64 MaxAddress;
489 PFN_NUMBER PageCount;
490 PCI_SLOT_NUMBER PciSlot;
492 PPCI_TYPE1_CFG_CYCLE_BITS DebuggingDevice;
493
494#if defined(EARLY_DEBUG)
495 if (LoaderBlock)
496 {
497 /* Define your own function or use the trick with FreeLoader */
498 DPRINT0 = ((PLOADER_PARAMETER_BLOCK)LoaderBlock)->u.I386.CommonDataArea;
499 }
500#endif
501
502 DPRINT0("%s(%p, %p) called\n", __FUNCTION__, LoaderBlock, PciDevice);
503
504 if (!HalpFindMatchingDebuggingDevice(PciDevice))
505 {
506 DPRINT0("No device found matching given device descriptor!\n");
508 }
509
510 if (PciDevice->Initialized)
511 return STATUS_SUCCESS;
512
513 PciSlot.u.AsULONG = PciDevice->Slot;
514
515 /* Check if the device is already present */
516 for (i = 0; i < RTL_NUMBER_OF(HalpPciDebuggingDevice); ++i)
517 {
518 DebuggingDevice = &HalpPciDebuggingDevice[i];
519
520 if (DebuggingDevice->InUse &&
521 DebuggingDevice->DeviceNumber == PciSlot.u.bits.DeviceNumber &&
522 DebuggingDevice->FunctionNumber == PciSlot.u.bits.FunctionNumber &&
523 DebuggingDevice->BusNumber == PciDevice->Bus)
524 {
525 DPRINT0("Device %p(0x%lx) is already in use!\n", PciDevice, PciDevice->Slot);
526 return STATUS_UNSUCCESSFUL;
527 }
528 }
529
530 /* Save the device location */
531 for (i = 0; i < RTL_NUMBER_OF(HalpPciDebuggingDevice); ++i)
532 {
533 DebuggingDevice = &HalpPciDebuggingDevice[i];
534
535 if (!DebuggingDevice->InUse)
536 {
537 DebuggingDevice->DeviceNumber = PciSlot.u.bits.DeviceNumber;
538 DebuggingDevice->FunctionNumber = PciSlot.u.bits.FunctionNumber;
539 DebuggingDevice->BusNumber = PciDevice->Bus;
540 DebuggingDevice->InUse = TRUE;
541
542 PciDevice->Initialized = TRUE;
543 break;
544 }
545 }
547 {
548 DPRINT0("Maximum device count reached!\n");
549 return STATUS_UNSUCCESSFUL;
550 }
551
552 if (!PciDevice->Memory.Length)
553 return STATUS_SUCCESS;
554
555 if (!LoaderBlock)
557
558 if (!PciDevice->Memory.MaxEnd.QuadPart)
559 {
560 PciDevice->Memory.MaxEnd.QuadPart = (ULONG64)-1;
561 }
562 MaxAddress = min(PciDevice->Memory.MaxEnd.QuadPart, 0xFFFFFFFF);
563 PageCount = BYTES_TO_PAGES(PciDevice->Memory.Length);
564
565 /* Allocate the device context */
567 MaxAddress,
568 PageCount,
569 FALSE);
570 PciDevice->Memory.Start = PhysicalAddress;
572 {
574 }
575 PciDevice->Memory.VirtualAddress = HalpMapPhysicalMemory64(PhysicalAddress, PageCount);
576
577 return STATUS_SUCCESS;
578}
ULONG64 NTAPI HalpAllocPhysicalMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN ULONG64 MaxAddress, IN PFN_NUMBER PageCount, IN BOOLEAN Aligned)
Definition: memory.c:29
static BOOLEAN HalpFindMatchingDebuggingDevice(_In_ PDEBUG_DEVICE_DESCRIPTOR PciDevice)
Definition: kdpci.c:237
#define min(a, b)
Definition: monoChain.cc:55
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
struct _LOADER_PARAMETER_BLOCK * PLOADER_PARAMETER_BLOCK
ULONG PFN_NUMBER
Definition: ke.h:9
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by HalpRegisterKdSupportFunctions().

Variable Documentation

◆ HalpPciDebuggingDevice

PCI_TYPE1_CFG_CYCLE_BITS HalpPciDebuggingDevice[2] = {0}

Definition at line 31 of file kdpci.c.

Referenced by HalpRegisterPciDebuggingDeviceInfo(), and HalpSetupPciDeviceForDebugging().