Skip to content

Commit 1bd675f

Browse files
committed
[USBDRIVER]
- Fix an off-by-one error in the probing code - Scan all PCI buses instead of just the first two - Fix a horrible bug that resulted in reinitializing EHCI controllers as UHCI controllers which caused a crash on VirtualBox (with _MULTI_UHCI) - Implement support for multiple EHCI controllers and enable support for multiple UHCI controllers (greatly increases compatibility with real hardware because the first controller detected is often internal) svn path=/trunk/; revision=47136
1 parent 438916e commit 1bd675f

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

reactos/drivers/usb/nt4compat/usbdriver/ehci.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,18 +3461,19 @@ ehci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
34613461
PDEVICE_OBJECT pdev;
34623462
BYTE buffer[sizeof(PCI_COMMON_CONFIG)];
34633463
PEHCI_DEVICE_EXTENSION pdev_ext;
3464+
LONG count = 0;
34643465

34653466
slot_num.u.AsULONG = 0;
34663467
pci_config = (PPCI_COMMON_CONFIG) buffer;
34673468
pdev = NULL;
34683469

3469-
//scan the bus to find ehci controller
3470-
for(bus = 0; bus < 3; bus++) /* enum bus0-bus2 */
3470+
//scan the PCI buses to find ehci controller
3471+
for (bus = 0; bus <= PCI_MAX_BRIDGE_NUMBER; bus++) //Yes, it should be <=
34713472
{
3472-
for(i = 0; i < PCI_MAX_DEVICES; i++)
3473+
for(i = 0; i <= PCI_MAX_DEVICES; i++)
34733474
{
34743475
slot_num.u.bits.DeviceNumber = i;
3475-
for(j = 0; j < PCI_MAX_FUNCTIONS; j++)
3476+
for(j = 0; j <= PCI_MAX_FUNCTION; j++)
34763477
{
34773478
slot_num.u.bits.FunctionNumber = j;
34783479

@@ -3490,9 +3491,12 @@ ehci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
34903491
{
34913492
//well, we find our usb host controller( EHCI ), create device
34923493
pdev = ehci_alloc(drvr_obj, reg_path, ((bus << 8) | (i << 3) | j), dev_mgr);
3493-
3494-
if (!pdev)
3495-
continue;
3494+
if (pdev)
3495+
#ifdef _MULTI_EHCI
3496+
count++;
3497+
#else
3498+
goto LBL_LOOPOUT;
3499+
#endif
34963500
}
34973501
}
34983502

@@ -3501,6 +3505,11 @@ ehci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
35013505
}
35023506
}
35033507

3508+
#ifndef _MULTI_EHCI
3509+
LBL_LOOPOUT:
3510+
#endif
3511+
DbgPrint("Found %d EHCI controllers\n", count);
3512+
35043513
if (pdev)
35053514
{
35063515
pdev_ext = pdev->DeviceExtension;

reactos/drivers/usb/nt4compat/usbdriver/uhci.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,13 @@ uhci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
626626
count = 0;
627627
pdev = NULL;
628628

629-
//scan the bus to find uhci controller
630-
for(bus = 0; bus < 3; bus++) /* enum bus0-bus2 */
629+
//scan the PCI buses to find uhci controller
630+
for (bus = 0; bus <= PCI_MAX_BRIDGE_NUMBER; bus++)
631631
{
632-
for(i = 0; i < PCI_MAX_DEVICES; i++)
632+
for(i = 0; i <= PCI_MAX_DEVICES; i++)
633633
{
634634
slot_num.u.bits.DeviceNumber = i;
635-
for(j = 0; j < PCI_MAX_FUNCTIONS; j++)
635+
for(j = 0; j <= PCI_MAX_FUNCTION; j++)
636636
{
637637
slot_num.u.bits.FunctionNumber = j;
638638

@@ -645,18 +645,15 @@ uhci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
645645
if (ret == 2) /*no device on the slot */
646646
break;
647647

648-
if (pci_config->BaseClass == 0x0c && pci_config->SubClass == 0x03)
648+
if (pci_config->BaseClass == 0x0c && pci_config->SubClass == 0x03 &&
649+
pci_config->ProgIf == 0x00)
649650
{
650651
// well, we find our usb host controller, create device
651-
#ifdef _MULTI_UHCI
652-
{
653-
pdev = uhci_alloc(drvr_obj, reg_path, ((bus << 8) | (i << 3) | j), dev_mgr);
654-
if (pdev)
655-
count++;
656-
}
657-
#else
658652
pdev = uhci_alloc(drvr_obj, reg_path, ((bus << 8) | (i << 3) | j), dev_mgr);
659653
if (pdev)
654+
#ifdef _MULTI_UHCI
655+
count++;
656+
#else
660657
goto LBL_LOOPOUT;
661658
#endif
662659
}
@@ -669,6 +666,8 @@ uhci_probe(PDRIVER_OBJECT drvr_obj, PUNICODE_STRING reg_path, PUSB_DEV_MANAGER d
669666
#ifndef _MULTI_UHCI
670667
LBL_LOOPOUT:
671668
#endif
669+
DbgPrint("Found %d UHCI controllers\n", count);
670+
672671
if (pdev)
673672
{
674673
pdev_ext = pdev->DeviceExtension;

reactos/drivers/usb/nt4compat/usbdriver/usbdriver.rbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
33
<module name="usbdriver" type="kernelmodedriver" installbase="system32/drivers" installname="usbdriver.sys">
44
<define name="INCLUDE_EHCI" />
5+
<define name="_MULTI_UHCI" />
6+
<define name="_MULTI_EHCI" />
57
<define name="_X86" />
68
<include base="usbdriver">.</include>
79
<library>ntoskrnl</library>

0 commit comments

Comments
 (0)