From 7dcd88ccf634b8636c055314e426805750b53556 Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Fri, 23 Oct 2020 07:00:38 -0400 Subject: [PATCH] drivers: PIT delivered with APIC PIT interrupt routed to cpus using IOAPIC IRQ delivery Signed-off-by: Daniele Ahmed --- common/setup.c | 2 +- drivers/pit.c | 11 ++++++++--- include/drivers/pit.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/setup.c b/common/setup.c index f436f9e7..88dddc80 100644 --- a/common/setup.c +++ b/common/setup.c @@ -228,7 +228,7 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic, uart_input_init(0); /* Initialize Programmable Interrupt Timer */ - init_pit(); + init_pit(0); /* Jump from .text.init section to .text */ asm volatile("push %0; ret" ::"r"(&kernel_main)); diff --git a/drivers/pit.c b/drivers/pit.c index bedef063..ef63cb6e 100644 --- a/drivers/pit.c +++ b/drivers/pit.c @@ -22,23 +22,28 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include +#include #include #include static volatile uint64_t ticks = 0; -void init_pit(void) { +void init_pit(uint8_t dst_cpus) { outb(PIT_COMMAND_PORT, PIT_CHANNEL_0 & PIT_ACCESS_MODE_LH & PIT_OP_MODE_RATE & PIT_BCD_MODE); outb(PIT_DATA_PORT_CH0, PIT_FREQUENCY & 0xFF); /* send low byte */ outb(PIT_DATA_PORT_CH0, (PIT_FREQUENCY & 0xFF00) >> 8); /* send high byte */ - pic_enable_irq(PIC1_DEVICE_SEL, PIT_IRQ); + configure_isa_irq(PIT_IRQ, PIT_IRQ0_OFFSET, IOAPIC_DEST_MODE_PHYSICAL, dst_cpus); } -void pit_interrupt_handler(void) { ++ticks; } +void pit_interrupt_handler(void) { + ++ticks; + apic_EOI(); +} void pit_sleep(uint64_t ms) { uint64_t end = ticks + ms; diff --git a/include/drivers/pit.h b/include/drivers/pit.h index a66dd688..a3a8310c 100644 --- a/include/drivers/pit.h +++ b/include/drivers/pit.h @@ -56,7 +56,7 @@ typedef enum pit_operational_mode pit_operational_mode_t; #define PIT_BCD_MODE (~(1 << 0)) -extern void init_pit(void); +extern void init_pit(uint8_t dst_cpus); extern void pit_interrupt_handler(void); extern void pit_sleep(uint64_t ms);