Index: OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c =================================================================== --- OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c (revision 8827) +++ OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c (working copy) @@ -17,10 +17,23 @@ #include #include #include +#include #define ACPI_TIMER_FREQUENCY 3579545 #define ACPI_TIMER_COUNT_SIZE 0x01000000 +struct DeviceProbe +{ + UINT8 Device; + UINT16 VendorID; + UINT16 DeviceID; +}; + +struct DeviceProbe DeviceProber[] = +{ + {1, 0xabad, 0xbabe }, /*qemu, todo fill right values */ + {7, 0x8086, 0x7113 }, /*vbox*/ +}; /** The constructor function enables ACPI IO space. @@ -36,17 +49,30 @@ VOID ) { - UINT8 Device; + UINT8 Device = (UINT8)~0; + UINT16 DeviceID; + UINT16 VendorID; + UINTN i; + for (i = 0; i < 2; ++i) + { + VendorID = PciRead16(PCI_LIB_ADDRESS(0, DeviceProber[i].Device, 0, 0)); + DeviceID = PciRead16(PCI_LIB_ADDRESS(0, DeviceProber[i].Device, 0, 2)); + DEBUG((DEBUG_INFO, "TM(%d)(VendorID:%x, DeviceID(%x))\n", DeviceProber[i].Device, VendorID, DeviceID)); + if (VendorID == DeviceProber[i].VendorID + && DeviceID == DeviceProber[i].DeviceID) + { + Device = DeviceProber[i].Device; + break; + } + } + ASSERT(Device != (UINT8)~0); - Device = 1; - // Device = 7; - // - // ACPI Timer enable is in Bus 0, Device ?, Function 3 + // ACPI Timer enable is in Bus 0, Device ?, Function 0 // - PciOr8 (PCI_LIB_ADDRESS (0,Device,3,0x04), 0x01); - PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40), (UINT32) ~0xfc0, 0x400); - PciOr8 (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01); return RETURN_SUCCESS; + PciOr8 (PCI_LIB_ADDRESS (0,Device,0,0x04), 0x01); + PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,0,0x40), (UINT32) ~0xfc0, 0x400); + PciOr8 (PCI_LIB_ADDRESS (0,Device,0,0x80), 0x01); return RETURN_SUCCESS; } /**