From 893b9e96e8593b810caebefbf6fdba4545179986 Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Mon, 19 Oct 2020 17:03:23 +0200 Subject: [PATCH] uart: use IOAPIC's IRQ delivery for UART Signed-off-by: Pawel Wieczorkiewicz --- common/setup.c | 6 +++--- drivers/serial.c | 13 ++++++++----- include/drivers/serial.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/setup.c b/common/setup.c index e8662a35..d5d7130f 100644 --- a/common/setup.c +++ b/common/setup.c @@ -175,9 +175,6 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic, /* Initialize Programmable Interrupt Controller */ init_pic(); - /* Initialize console input */ - uart_input_init(); - /* PIC is initialized - enable local interrupts */ sti(); @@ -222,6 +219,9 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic, init_ioapic(); + /* Initialize console input */ + uart_input_init(0); + /* Jump from .text.init section to .text */ asm volatile("push %0; ret" ::"r"(&kernel_main)); diff --git a/drivers/serial.c b/drivers/serial.c index 543c46e5..1c1c103a 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -22,7 +22,8 @@ * (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 @@ -91,14 +92,15 @@ void uart_init(io_port_t port, unsigned baud) { outb(port + UART_MCR_REG_OFFSET, mcr.reg); } -void uart_input_init() { +void uart_input_init(uint8_t dst_cpus) { /* Initialize input state */ memset(&input_state, 0, sizeof(input_state)); /* Enable IRQ lines */ printk("Enabling serial input\n"); - pic_enable_irq(PIC1_DEVICE_SEL, COM1_IRQ); - pic_enable_irq(PIC2_DEVICE_SEL, COM2_IRQ); + + configure_isa_irq(COM1_IRQ, COM1_IRQ0_OFFSET, IOAPIC_DEST_MODE_PHYSICAL, dst_cpus); + configure_isa_irq(COM2_IRQ, COM2_IRQ0_OFFSET, IOAPIC_DEST_MODE_PHYSICAL, dst_cpus); } static inline int uart_port_status(io_port_t port) { @@ -169,5 +171,6 @@ void uart_handler(io_port_t ports[2]) { printk("%c", input); } } - outb(PIC1_PORT_CMD, PIC_EOI); + + apic_EOI(); } diff --git a/include/drivers/serial.h b/include/drivers/serial.h index d56157d8..83d9166b 100644 --- a/include/drivers/serial.h +++ b/include/drivers/serial.h @@ -126,7 +126,7 @@ typedef union interrupt_enable_register ier_t; extern void uart_init(io_port_t port, unsigned baud); extern void uart_handler(io_port_t ports[2]); -extern void uart_input_init(); +extern void uart_input_init(uint8_t dst_cpus); extern int serial_putchar(io_port_t port, char c); extern int serial_write(io_port_t port, const char *buf, size_t len);