From 04a41afc8fd8faf491933c6aab0767ec37296787 Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Fri, 8 Oct 2021 08:56:23 +0000 Subject: [PATCH] pit: fix initialization init_pit() should send first to the command port the value for the chosen configuration, not 0. This 0 value is due to an error in how the value is set using bits. Signed-off-by: Daniele Ahmed Reported-By: Mathias Krause --- drivers/pit.c | 3 +-- include/drivers/pit.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/pit.c b/drivers/pit.c index 3c54cbe0..d90597c9 100644 --- a/drivers/pit.c +++ b/drivers/pit.c @@ -32,8 +32,7 @@ void init_pit(uint8_t dst_cpus) { printk("Initializing PIT\n"); - outb(PIT_COMMAND_PORT, - PIT_CHANNEL_0 & PIT_ACCESS_MODE_LH & PIT_OP_MODE_RATE & PIT_BCD_MODE); + outb(PIT_COMMAND_PORT, PIT_CHANNEL_0 | PIT_ACCESS_MODE_LH | PIT_OP_MODE_RATE); outb(PIT_DATA_PORT_CH0, PIT_FREQUENCY & 0xFF); /* send low byte */ outb(PIT_DATA_PORT_CH0, (PIT_FREQUENCY & 0xFF00) >> 8); /* send high byte */ configure_isa_irq(PIT_IRQ, PIT_IRQ0_OFFSET, IOAPIC_DEST_MODE_PHYSICAL, dst_cpus); diff --git a/include/drivers/pit.h b/include/drivers/pit.h index 8072cdc1..b1e8aedd 100644 --- a/include/drivers/pit.h +++ b/include/drivers/pit.h @@ -37,24 +37,24 @@ #define PIT_DATA_PORT_CH0 0x40 #define PIT_COMMAND_PORT 0x43 -#define PIT_CHANNEL_0 (~((1 << 7) | (1 << 6))) +#define PIT_CHANNEL_0 0 #define PIT_ACCESS_MODE_LOW (1 << 4) #define PIT_ACCESS_MODE_HIGH (1 << 5) #define PIT_ACCESS_MODE_LH (PIT_ACCESS_MODE_LOW | PIT_ACCESS_MODE_HIGH) enum pit_operational_mode { - PIT_OP_MODE_COUNT = 0x00, /* interrupt on terminal count */ - PIT_OP_MODE_ONE_SHOT = 0x01, /* hardware re-triggerable one-shot */ - PIT_OP_MODE_RATE = 0x02, /* rate generator */ - PIT_OP_MODE_WAVE = 0x03, /* square wave generator */ - PIT_OP_MODE_SW_STROBE = 0x04, /* software triggered strobe */ - PIT_OP_MODE_HW_STROBE = 0x05, /* hardware triggered strobe */ - PIT_OP_MODE_RATE_6 = 0x06, /* rate generator */ - PIT_OP_MODE_WAVE_7 = 0x07 /* square wave generator */ + PIT_OP_MODE_COUNT = 0x00 << 1, /* interrupt on terminal count */ + PIT_OP_MODE_ONE_SHOT = 0x01 << 1, /* hardware re-triggerable one-shot */ + PIT_OP_MODE_RATE = 0x02 << 1, /* rate generator */ + PIT_OP_MODE_WAVE = 0x03 << 1, /* square wave generator */ + PIT_OP_MODE_SW_STROBE = 0x04 << 1, /* software triggered strobe */ + PIT_OP_MODE_HW_STROBE = 0x05 << 1, /* hardware triggered strobe */ + PIT_OP_MODE_RATE_6 = 0x06 << 1, /* rate generator */ + PIT_OP_MODE_WAVE_7 = 0x07 << 1 /* square wave generator */ }; typedef enum pit_operational_mode pit_operational_mode_t; -#define PIT_BCD_MODE (~(1 << 0)) +#define PIT_BCD_MODE 1 extern void init_pit(uint8_t dst_cpus); extern void pit_disable(void);