ReactOS 0.4.17-dev-1281-g065abb3
slots.cpp File Reference
#include "xhcidrv.h"
#include <debug.h>
Include dependency graph for slots.cpp:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define XHCI_SCRATCHPAD_BYTES   4096
 

Functions

 _IRQL_requires_ (PASSIVE_LEVEL) NTSTATUS XhciSlotTable
 Sends a synchronous IOCTL to the specified device object.
 
static XhciUsbDevice *NTAPI XhciSlotDevice (_In_ PVOID Entry)
 
 _IRQL_requires_max_ (DISPATCH_LEVEL) NTSTATUS XhciSlotTable
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file slots.cpp.

◆ XHCI_SCRATCHPAD_BYTES

#define XHCI_SCRATCHPAD_BYTES   4096

Definition at line 14 of file slots.cpp.

Function Documentation

◆ _IRQL_requires_()

_IRQL_requires_ ( PASSIVE_LEVEL  )

Sends a synchronous IOCTL to the specified device object.

Parameters
[in]IoControlCodeThe IOCTL to send to the device.
[in]DeviceObjectPointer to the device object that will handle the IOCTL.
[in]InputBufferOptional pointer to a buffer containing input data for the IOCTL. When specified, the buffer should be at least of InputBufferLength size.
[in]InputBufferLengthSize in bytes, of the buffer pointed by InputBuffer.
[out]OutputBufferOptional pointer to a buffer that will receive output data from the IOCTL. When specified, the buffer should be at least of OutputBufferLength size.
[in]OutputBufferLengthSize in bytes, of the buffer pointed by OutputBuffer.
[in]FileObjectOptional pointer to a file object that may be necessary for the IOCTL.
Returns
An NTSTATUS code indicating success or failure of this function.
Note
Must be called at PASSIVE_LEVEL with all APCs enabled.

Nothing is found unless the PCI bus driver publishes the properties.

The root hub name without its prefix; NULL when the PDO has no name.

Grows a private buffer to what the helper asks for.

Lets KMDF handle the IRP, then hands it back here still uncompleted.

Waits for the device machine to answer a PnP or power event; returns the PnP status.

Deletes the UCX endpoints of the disabled pipes, then the interface record.

One 4 byte value; the registry type is not checked.

Reread whenever user experience settings change; the open status is returned.

Sends a synchronous IOCTL to the specified device object.

STATUS_SUCCESS when the caller's token is an administrator's.

Sends a synchronous IOCTL to the specified device object.

Reads one value of a walk. A missing value only clears Present; FALSE means stop.

Reads up to Size bytes of a value into a zeroed buffer; the type is not checked.

Writes a REG_BINARY value into the device's usbflags subkey.

Sets or clears ExtPropertiesInstalled from ExtPropDescSemaphore in the hardware key.

Fails only when a port cannot be bound to the USB4 host router its ACPI node names.

Assigns device, hardware, compatible, container and instance ids to a new child PDO.

Answers IRP_MN_QUERY_DEVICE_TEXT on a child PDO; always completes the IRP.

Takes the connector map lock, needed around HubConnectorFindCompanion.

Device hardware key values read at PDO prepare hardware.

Saves the MS OS 2.0 set info in usbflags when the set asks for alternate enumeration.

MsOs20Flags and EnumerationRetryCount, written at PDO start.

Rereads the UXD record; UpdateRequired says whether the device id changes.

Replacement PnP id of a UXD reserved device, or an empty String. Always succeeds.

Telemetry values under the device's Ceip subkey.

BootPathSurpriseRemovalCount + 1.

This machine's dual role features for a dual role partner.

Tells UCX the WDM PDO of the device; call right after the child PDO was created.

IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME: Argument1 and its length Argument2.

IOCTL_INTERNAL_USB_GET_BUS_INFO for the device: the 16 byte USB_BUS_NOTIFICATION at Argument1.

Registers the GUID_USB_WMI_NODE_INFO instance of a child PDO (not for hubs or composites).

Registers the boot device surprise removal event on an external, non hub boot PDO.

Fires the boot device surprise removal event, if one is registered.

Sends a synchronous IOCTL to the specified device object.

Publishes "<port>#<host>" for every bound port on the hub's PDO. QUIRK: with no bound port an older value is left in place.

Binds USB 3 ports to the host routers named by the USB4 DVSEC; an earlier ACPI mapping wins.

Waits on a PnP handshake event with no timeout, printing a watchdog line every minute so a stuck machine is visible in the debugger.

Copies up to Size bytes of a device property; a failed query leaves the field zero.

Only the controller name length is real; both bandwidth fields read 0.

The answer overlays a USB_HUB_NAME on TotalSize, so TotalSize comes back as the name length + 4.

Evaluates a method without arguments into Output.

Drops every MSI descriptor and keeps only lists that still offer a line interrupt.

Picks the list with the best MSI offer: MSI-X first, then the most messages.

Keeps message descriptors covering Wanted messages and removes the others.

Evaluates _DSM on the controller ACPI object with a buffer as Arg3; returns up to 8 result bytes, 0 on failure.

Definition at line 27 of file slots.cpp.

30{
31 XhciCommonBuffer* Pool = &m_Controller->m_Buffers;
32 volatile ULONG64* Entries;
33 PULONG64 Array;
35 SIZE_T MapBytes;
38
39 InitializeListHead(&m_ScratchpadPages);
40
41 m_Dcbaa = Pool->Acquire(XHCI_DCBAA_ENTRIES * sizeof(ULONG64));
42 if (m_Dcbaa == NULL)
43 {
44 DPRINT1("No common buffer for the DCBAA\n");
46 goto Fail;
47 }
48
49 Entries = (volatile ULONG64*)m_Dcbaa->VirtualAddress;
50
51 m_ScratchpadCount = m_Controller->m_Registers.ScratchpadCount();
52 if (m_ScratchpadCount != 0)
53 {
54 /* QUIRK: above 512 scratchpads the array no longer fits a pool page and this fails */
55 m_ScratchpadArray = Pool->Acquire(m_ScratchpadCount * sizeof(ULONG64));
56 if (m_ScratchpadArray == NULL)
57 {
58 DPRINT1("No common buffer for the array of %lu scratchpads\n", m_ScratchpadCount);
60 goto Fail;
61 }
62
63 Status = Pool->AcquireList(XHCI_SCRATCHPAD_BYTES, m_ScratchpadCount, &m_ScratchpadPages);
64 if (!NT_SUCCESS(Status))
65 {
66 DPRINT1("Acquiring %lu scratchpad pages failed 0x%lx\n", m_ScratchpadCount, Status);
67 goto Fail;
68 }
69
70 Array = (PULONG64)m_ScratchpadArray->VirtualAddress;
71 Index = 0;
72 for (Entry = m_ScratchpadPages.Flink; Entry != &m_ScratchpadPages; Entry = Entry->Flink)
73 {
75
76 Array[Index++] = Page->LogicalAddress.QuadPart;
77 }
78
79 Entries[0] = m_ScratchpadArray->LogicalAddress.QuadPart;
80 }
81
82 m_SlotCount = m_Controller->m_Registers.MaxSlots();
83
84 /* Index 0 is never a slot id; keeping it makes the slot id the index */
85 MapBytes = (m_SlotCount + 1) * sizeof(*m_SlotMap);
86 m_SlotMap = (PVOID*)ExAllocatePoolZero(NonPagedPool, MapBytes, XHCI_TAG_SLOT);
87 if (m_SlotMap == NULL)
88 {
89 DPRINT1("No pool for the map of %lu slots\n", m_SlotCount);
91 goto Fail;
92 }
93
94 DPRINT("Slot table: %lu slots, %lu scratchpads, DCBAA at 0x%I64x\n",
95 m_SlotCount, m_ScratchpadCount, m_Dcbaa->LogicalAddress.QuadPart);
96 return STATUS_SUCCESS;
97
98Fail:
99 FreeTables();
100 return Status;
101}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: bufpool.h:50
PLIST_ENTRY Entry
Definition: devhcd.cpp:1262
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
int Fail
Definition: ehthrow.cxx:24
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:24
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned __int64 * PULONG64
Definition: imports.h:198
static const ENTRY Entries[]
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
Definition: mm.h:1287
#define STATUS_SUCCESS
Definition: shellext.h:65
#define XHCI_SCRATCHPAD_BYTES
Definition: slots.cpp:14
#define DPRINT
Definition: sndvol32.h:73
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
for(Attempt=0;Attempt< UCX_LEGACY_NAME_ATTEMPTS;Attempt++)
Definition: userreq.cpp:715
_In_ WDFCOLLECTION _In_ ULONG Index
#define XHCI_DCBAA_ENTRIES
Definition: xhcihw.h:194
#define XHCI_TAG_SLOT
Definition: xhciutil.h:17

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( DISPATCH_LEVEL  )

IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION; the idle machine owns the IRP afterwards.

Records hub over current in the hub hardware key, once per devnode.

First selective suspend of the device; the registry write runs in a work item.

"USB device not recognized" popup for a port.

A hub was attached beyond the allowed tier depth.

The selected configuration draws more power than the port can give.

The controller ran out of bandwidth for the device; fired by the out of bandwidth timer.

Definition at line 260 of file slots.cpp.

266{
267 volatile ULONG64* Entries;
268
269 if (!IsValidSlot(SlotId) || m_Dcbaa == NULL)
270 {
271 DPRINT1("Slot id %lu is outside the slot table\n", SlotId);
273 }
274
275 Entries = (volatile ULONG64*)m_Dcbaa->VirtualAddress;
276
277 /* Software clears the entry once the slot is disabled (xHCI 4.6.4) */
278 if (OutputContextAddress == 0)
279 {
280 ASSERT(Device == NULL || m_SlotMap[SlotId] == Device);
281 m_SlotMap[SlotId] = NULL;
282 Entries[SlotId] = 0;
283 return STATUS_SUCCESS;
284 }
285
286 /* QUIRK: nothing is recorded while the controller is inaccessible */
287 if (!m_Controller->IsAccessible())
288 return STATUS_SUCCESS;
289
290 if (Entries[SlotId] != 0)
291 {
292 DPRINT1("DCBAA entry of slot %lu is already 0x%I64x\n", SlotId, (ULONG64)Entries[SlotId]);
294 }
295
296 m_SlotMap[SlotId] = Device;
297 Entries[SlotId] = OutputContextAddress;
298 return STATUS_SUCCESS;
299}
_Must_inspect_result_ _In_ PUCXHUB_DEVICE_CREATE_INFO _Out_ UCXUSBDEVICE * Device
Definition: hubucx.h:258
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ XhciSlotDevice()

static XhciUsbDevice *NTAPI XhciSlotDevice ( _In_ PVOID  Entry)
static

Definition at line 192 of file slots.cpp.

194{
195 return static_cast<XhciUsbDevice*>(Entry);
196}

Referenced by XhciSlotTable::DisableAll(), XhciSlotTable::OnDeviceNotificationEvent(), and XhciSlotTable::OnHostLost().