diff options
author | Marvin Borner | 2020-09-06 19:37:58 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-06 19:37:58 +0200 |
commit | 586d58192b2c576393077c3944338b582c873f45 (patch) | |
tree | 7f93d4f5168266118541ffdbcefd32696ce0b281 /kernel | |
parent | 2876d92663be7f1b46d72217e79b9f83d1756fd8 (diff) |
Finished switch to hpet timer
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/acpi.c | 15 | ||||
-rw-r--r-- | kernel/drivers/timer.c | 6 | ||||
-rw-r--r-- | kernel/inc/acpi.h | 65 | ||||
-rw-r--r-- | kernel/main.c | 1 |
4 files changed, 40 insertions, 47 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c index 999c0ed..15007d7 100644 --- a/kernel/drivers/acpi.c +++ b/kernel/drivers/acpi.c @@ -74,15 +74,18 @@ void acpi_install() hpet = find_sdt(rsdt, HPET_MAGIC); } -void hpet_install() +void hpet_install(int period) { if (hpet && hpet->legacy_replacement && hpet->comparator_count > 0) { struct hpet_registers *r = (struct hpet_registers *)hpet->address.phys; - printf("HPET tick period: %dns\n", r->features.tick_period / 1000000); - printf("Periodic support: %d\n", r->timer.periodic_support); - r->config.enable = 1; - r->config.legacy_replacement = 1; - r->timer.enable = 1; + printf("HPET tick period: %dns\n", r->tick_period / 1000000); + if ((r->timer0 & hpet_periodic_support) == hpet_periodic_support) { + r->config |= hpet_enable; + r->config |= hpet_legacy_replacement; + r->timer0 |= hpet_periodic | hpet_set_accumulator | hpet_enable_timer; + r->timer_comparator0 = r->tick_period + period; + r->timer_comparator0 = period; + } } else { hpet = NULL; } diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 79e3cd8..788e286 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -1,5 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include <acpi.h> #include <cpu.h> #include <def.h> #include <interrupts.h> @@ -19,7 +20,6 @@ u32 timer_get() return timer_ticks; } -// Executed 1000 times per second void timer_handler() { timer_ticks++; @@ -39,6 +39,8 @@ void timer_wait(u32 ticks) // Install timer handler into IRQ0 void timer_install() { - timer_phase(1000); + hpet_install(10000); // TODO: Find optimal femtosecond period + if (!hpet) + timer_phase(1000); irq_install_handler(0, timer_handler); } diff --git a/kernel/inc/acpi.h b/kernel/inc/acpi.h index 498384e..3a25098 100644 --- a/kernel/inc/acpi.h +++ b/kernel/inc/acpi.h @@ -68,48 +68,37 @@ struct hpet { u8 page_protection; }; +enum hpet_features { hpet_counter_size = 1 << 3, hpet_legacy_replacement_support = 1 << 5 }; +enum hpet_config { hpet_enable = 1 << 0, hpet_legacy_replacement = 1 << 1 }; +enum hpet_timer { + hpet_type = 1 << 1, + hpet_enable_timer = 1 << 2, + hpet_periodic = 1 << 3, + hpet_periodic_support = 1 << 4, + hpet_size = 1 << 5, // 1 if 64 bit + hpet_set_accumulator = 1 << 6, + hpet_force_32 = 1 << 8, // For 64 bit + hpet_apic_routing = 1 << 13, + hpet_fsb = 1 << 14, + hpet_fsb_support = 1 << 15, + /* routing_capability = 1 << 63 */ +}; + struct hpet_registers { - struct { - u8 revision; - u8 comparator_count : 5; - u8 counter_size : 1; - u8 reserved : 1; - u8 legacy_replacement : 1; - u16 pci_vendor_id; - u32 tick_period; - } features; + u32 features; // enum hpet_features + u32 tick_period; u64 reserved1; - struct { - u8 enable : 1; - u8 legacy_replacement : 1; - u64 reserved : 62; - } config; + u64 config; // enum hpet_config u64 reserved2; - struct { - u32 status; // For timer #n - u32 reserved; - } int_status; - u8 reserved3[200]; // Why?! + u32 int_status; // For timer #n + u32 reserved3; + u8 reserved4[200]; // Why?! u32 counter; u32 counter_high; // 0 due to 64 bit - u64 reserved4; - struct { - u8 reserved1 : 1; - u8 type : 1; - u8 enable : 1; - u8 periodic : 1; - u8 periodic_support : 1; - u8 size : 1; // 1 if 64 bit - u8 set_accumulator : 1; - u8 reserved2 : 1; - u8 force_32 : 1; // For 64 bit - u8 apic_routing : 5; - u8 fsb : 1; - u8 fsb_support : 1; - u16 reserved3; - u32 routing_capability; - } timer; -}; + u64 reserved5; + u64 timer0; // enum hpet_timer + u64 timer_comparator0; // In femtoseconds +} __attribute__((packed)); struct rsdp { struct sdp_header header; @@ -121,6 +110,6 @@ struct fadt *fadt; struct hpet *hpet; void acpi_install(); -void hpet_install(); +void hpet_install(int period); #endif diff --git a/kernel/main.c b/kernel/main.c index fc304b2..34332e2 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -25,7 +25,6 @@ void kernel_main(struct vid_info *vid_info) // Install drivers acpi_install(); - hpet_install(); interrupts_install(); fpu_install(); timer_install(); |