From 826ff7cb29cb2b9f966c8950a89e88121f3820f8 Mon Sep 17 00:00:00 2001 From: Andre Guedes Date: Thu, 2 Jul 2015 17:46:47 -0300 Subject: [PATCH] x86: Add pic_unmask_irq() helper This patch implements the pic_unmask_irq() helper and uses it where applicable. This function zeros the corresponding bit from the IRQ number in IMR register. This patch doesn't implement the pic_mask_irq() helper since it is not useful at this moment. --- cpu/x86/Makefile.x86 | 2 +- cpu/x86/drivers/pic.c | 48 +++++++++++++++++++++++++++++++++++++++++++ cpu/x86/drivers/pic.h | 2 ++ cpu/x86/drivers/pit.c | 4 ++-- cpu/x86/drivers/rtc.c | 4 ++-- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 cpu/x86/drivers/pic.c diff --git a/cpu/x86/Makefile.x86 b/cpu/x86/Makefile.x86 index eabe99242..57e2006c9 100644 --- a/cpu/x86/Makefile.x86 +++ b/cpu/x86/Makefile.x86 @@ -1,6 +1,6 @@ CONTIKI_CPU_DIRS = . drivers -CONTIKI_SOURCEFILES += mtarch.c gdt.c helpers.S idt.c cpu.c rtc.c pit.c +CONTIKI_SOURCEFILES += mtarch.c gdt.c helpers.S idt.c cpu.c rtc.c pit.c pic.c ### Compiler definitions CC = gcc diff --git a/cpu/x86/drivers/pic.c b/cpu/x86/drivers/pic.c new file mode 100644 index 000000000..2e6428756 --- /dev/null +++ b/cpu/x86/drivers/pic.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (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 "drivers/pic.h" + +void +pic_unmask_irq(unsigned int num) +{ + uint16_t port; + uint8_t bitmap; + + if(num <= 7) { + port = PIC1_DATA_PORT; + } else { + port = PIC2_DATA_PORT; + num -= 8; + } + + bitmap = inb(port); + outb(port, bitmap & ~BIT(num)); +} diff --git a/cpu/x86/drivers/pic.h b/cpu/x86/drivers/pic.h index 3f82a00ab..81de51e7b 100644 --- a/cpu/x86/drivers/pic.h +++ b/cpu/x86/drivers/pic.h @@ -38,6 +38,8 @@ #define PIC2_CMD_PORT 0xA0 #define PIC2_DATA_PORT 0xA1 +void pic_unmask_irq(unsigned int num); + /* This function initializes the daisy-chained Master and Slave 8259 PICs. * It is only called once, so let's give the compiler the option to inline it. * For more information about the ICWs, please refer to http://stanislavs.org/helppc/8259.html. diff --git a/cpu/x86/drivers/pit.c b/cpu/x86/drivers/pit.c index c9ce8ff4c..9eeb38523 100644 --- a/cpu/x86/drivers/pit.c +++ b/cpu/x86/drivers/pit.c @@ -30,6 +30,7 @@ #include +#include "drivers/pic.h" #include "pit.h" #include "helpers.h" #include "interrupt.h" @@ -75,6 +76,5 @@ pit_init(uint32_t ticks_rate, pit_int_callback cb) outb(PIT_COUNTER0_PORT, divisor & 0xFF); /* Write least significant bytes first. */ outb(PIT_COUNTER0_PORT, (divisor >> 8) & 0xFF); - /* FIXME: Unmask IRQ0 from Master PIC. Add a pic_set_mask() or similar and call it here. */ - outb(0x21, 0xfa); + pic_unmask_irq(0); } diff --git a/cpu/x86/drivers/rtc.c b/cpu/x86/drivers/rtc.c index 84d534003..243c6623f 100644 --- a/cpu/x86/drivers/rtc.c +++ b/cpu/x86/drivers/rtc.c @@ -29,6 +29,7 @@ */ #include "drivers/rtc.h" +#include "drivers/pic.h" #include "helpers.h" #include "interrupt.h" @@ -87,6 +88,5 @@ rtc_init(rtc_frequency_t frequency, void (*callback)(void)) outb(RTC_INDEX_REGISTER, 0x0B); outb(RTC_TARGET_REGISTER, reg_b | BIT(6)); - /* Unmask IRQ8 */ - outb(0xA1, 0xFE); + pic_unmask_irq(8); }