Kernel: Make HPET read_main_counter() atomic with 32 bit main counter
This commit is contained in:
parent
9594ee8e47
commit
59abb5d344
|
@ -153,7 +153,7 @@ namespace Kernel
|
||||||
|
|
||||||
m_is_64bit = regs.capabilities & COUNT_SIZE_CAP;
|
m_is_64bit = regs.capabilities & COUNT_SIZE_CAP;
|
||||||
|
|
||||||
// Disable main counter and reset value
|
// Disable and reset main counter
|
||||||
regs.configuration.low = regs.configuration.low & ~ENABLE_CNF;
|
regs.configuration.low = regs.configuration.low & ~ENABLE_CNF;
|
||||||
regs.main_counter.high = 0;
|
regs.main_counter.high = 0;
|
||||||
regs.main_counter.low = 0;
|
regs.main_counter.low = 0;
|
||||||
|
@ -244,27 +244,28 @@ namespace Kernel
|
||||||
if (m_is_64bit)
|
if (m_is_64bit)
|
||||||
return regs.main_counter.full;
|
return regs.main_counter.full;
|
||||||
|
|
||||||
uint32_t current = regs.main_counter.low;
|
CriticalScope _;
|
||||||
uint64_t wraps = m_32bit_wraps;
|
uint32_t current_low = regs.main_counter.low;
|
||||||
if (current < (uint32_t)m_last_ticks)
|
uint32_t wraps = m_32bit_wraps;
|
||||||
|
if (current_low < (uint32_t)m_last_ticks)
|
||||||
wraps++;
|
wraps++;
|
||||||
return (wraps << 32) | current;
|
return ((uint64_t)wraps << 32) | current_low;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPET::handle_irq()
|
void HPET::handle_irq()
|
||||||
{
|
{
|
||||||
auto& regs = registers();
|
auto& regs = registers();
|
||||||
|
|
||||||
uint64_t current_ticks { 0 };
|
uint64_t current_ticks;
|
||||||
|
|
||||||
if (m_is_64bit)
|
if (m_is_64bit)
|
||||||
current_ticks = regs.main_counter.full;
|
current_ticks = regs.main_counter.full;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32_t current = regs.main_counter.low;
|
uint32_t current_low = regs.main_counter.low;
|
||||||
if (current < (uint32_t)m_last_ticks)
|
if (current_low < (uint32_t)m_last_ticks)
|
||||||
m_32bit_wraps++;
|
m_32bit_wraps++;
|
||||||
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current;
|
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current_low;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_last_ticks = current_ticks;
|
m_last_ticks = current_ticks;
|
||||||
|
|
Loading…
Reference in New Issue