1
1
forked from 0ad/0ad

# bugfix for ACPI init on Win2k

mahaf: add API to check whether physical memory mapping ought to work
acpi: no longer consider itself initialized if the above is not true
(fixes undue warning in PMT and possibly HPET about invalid ACPI table
on Win2k)

cpu: remove redundant include

This was SVN commit r5329.
This commit is contained in:
janwas 2007-09-05 21:29:33 +00:00
parent ebd7446d8a
commit 94456a218a
6 changed files with 27 additions and 8 deletions

View File

@ -316,6 +316,9 @@ bool acpi_Init()
if(!mahaf_Init())
goto fail;
if(mahaf_IsPhysicalMappingDangerous())
goto fail;
if(!LatchAllTables())
goto fail;

View File

@ -27,9 +27,6 @@
#if OS_WIN
# include "lib/sysdep/win/wcpu.h"
#endif
#if OS_UNIX
# include "lib/sysdep/unix/ucpu.h"
#endif
ERROR_ASSOCIATE(ERR::CPU_FEATURE_MISSING, "This CPU doesn't support a required feature", -1);

View File

@ -94,13 +94,21 @@ void mahaf_WritePort32(u16 port, u32 value)
}
volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numBytes)
bool mahaf_IsPhysicalMappingDangerous()
{
// WinXP introduced checks that ensure we don't re-map pages with
// incompatible attributes. without this, mapping physical pages risks
// disaster due to TLB corruption, so disable it for safety.
// disaster due to TLB corruption.
if(wutil_WindowsVersion() < WUTIL_VERSION_XP)
return 0;
return true;
return false;
}
volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numBytes)
{
debug_assert(!mahaf_IsPhysicalMappingDangerous());
AkenMapIn in;
in.physicalAddress = (DWORD64)physicalAddress;
@ -124,6 +132,8 @@ volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numByte
void mahaf_UnmapPhysicalMemory(volatile void* virtualAddress)
{
debug_assert(!mahaf_IsPhysicalMappingDangerous());
AkenUnmapIn in;
in.virtualAddress = (DWORD64)virtualAddress;

View File

@ -24,6 +24,15 @@ extern void mahaf_WritePort8 (u16 port, u8 value);
extern void mahaf_WritePort16(u16 port, u16 value);
extern void mahaf_WritePort32(u16 port, u32 value);
/**
* @return whether mapping physical memory is known to be dangerous
* on this platform.
*
* note: mahaf_MapPhysicalMemory will warn if it is called despite this
* function having returned true.
**/
extern bool mahaf_IsPhysicalMappingDangerous();
extern volatile void* mahaf_MapPhysicalMemory(uintptr_t physicalAddress, size_t numBytes);
extern void mahaf_UnmapPhysicalMemory(volatile void* virtualAddress);

View File

@ -56,7 +56,7 @@ LibError CounterHPET::Activate()
if(!mahaf_Init())
return ERR::FAIL; // NOWARN (no Administrator privileges)
if(!acpi_Init())
WARN_RETURN(ERR::FAIL);
return ERR::FAIL; // NOWARN (happens on Win2k; see mahaf_IsPhysicalMappingDangerous)
const HpetDescriptionTable* hpet = (const HpetDescriptionTable*)acpi_GetTable("HPET");
if(!hpet)
return ERR::NO_SYS; // NOWARN (HPET not reported by BIOS)

View File

@ -36,7 +36,7 @@ LibError CounterPMT::Activate()
if(!mahaf_Init())
return ERR::FAIL; // NOWARN (no Administrator privileges)
if(!acpi_Init())
WARN_RETURN(ERR::FAIL);
return ERR::FAIL; // NOWARN (happens on Win2k; see mahaf_IsPhysicalMappingDangerous)
// (note: it's called FADT, but the signature is "FACP")
const FADT* fadt = (const FADT*)acpi_GetTable("FACP");
if(!fadt)