Kernel: Simplify 64-bit HPET reads on x86_64

We don't have to worry about racy 32-bit reads when we're reading the
64-bit HPET value using a 64-bit CPU. :^)
This commit is contained in:
Andreas Kling 2021-12-11 18:59:40 +01:00
parent a23edd42b8
commit 63117f826b
Notes: sideshowbarker 2024-07-17 22:59:02 +09:00

View file

@ -46,8 +46,13 @@ enum class TimerConfiguration : u32 {
};
struct [[gnu::packed]] HPETRegister {
volatile u32 low;
volatile u32 high;
union {
volatile u64 full;
struct {
volatile u32 low;
volatile u32 high;
};
};
};
struct [[gnu::packed]] TimerStructure {
@ -87,6 +92,9 @@ static_assert(AssertSize<HPETRegistersBlock, 0x500>());
static u64 read_register_safe64(const HPETRegister& reg)
{
#if ARCH(X86_64)
return reg.full;
#else
// As per 2.4.7 this reads the 64 bit value in a consistent manner
// using only 32 bit reads
u32 low, high = reg.high;
@ -98,6 +106,7 @@ static u64 read_register_safe64(const HPETRegister& reg)
high = new_high;
}
return ((u64)high << 32) | (u64)low;
#endif
}
static HPET* s_hpet;