POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/x86/x86-qemu/pic.c
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #include <types.h>
00019 #include <errno.h>
00020 
00021 #include <arch/x86/ioports.h>
00022 
00023 #include "pic.h"
00024 
00025 int pok_pic_init ()
00026 {
00027    outb (PIC_MASTER_BASE, PIC_MASTER_ICW1);
00028    outb (PIC_SLAVE_BASE, PIC_SLAVE_ICW1);
00029 
00030    outb (PIC_MASTER_BASE + 1, PIC_MASTER_ICW2);
00031    outb (PIC_SLAVE_BASE + 1, PIC_SLAVE_ICW2);
00032 
00033    outb (PIC_MASTER_BASE + 1, PIC_MASTER_ICW3);
00034    outb (PIC_SLAVE_BASE + 1, PIC_SLAVE_ICW3);
00035 
00036    outb (PIC_MASTER_BASE + 1, PIC_MASTER_ICW4);
00037    outb (PIC_SLAVE_BASE + 1, PIC_SLAVE_ICW4);
00038 
00039    /* Mask everything */
00040    outb (PIC_MASTER_BASE + 1, 0xfb);
00041    outb (PIC_SLAVE_BASE + 1, 0xff);
00042 
00043    return (POK_ERRNO_OK);
00044 }
00045 
00046 int pok_pic_mask (uint8_t irq)
00047 {
00048    uint8_t mask;
00049 
00050    if (irq > 15)
00051    {
00052       return (POK_ERRNO_EINVAL);
00053    }
00054 
00055    if (irq < 8)
00056    {
00057       mask = inb (PIC_MASTER_BASE + 1);
00058       outb (PIC_MASTER_BASE + 1, mask | (1 << irq));
00059    }
00060    else
00061    {
00062       mask = inb (PIC_SLAVE_BASE + 1);
00063       outb (PIC_SLAVE_BASE + 1, mask | (1 << (irq - 8)));
00064    }
00065 
00066    return (POK_ERRNO_OK);
00067 }
00068 
00069 int pok_pic_unmask(uint8_t irq)
00070 {
00071    uint8_t mask;
00072 
00073    if (irq > 15)
00074       return (POK_ERRNO_EINVAL);
00075 
00076    if (irq < 8)
00077    {
00078       mask = inb(PIC_MASTER_BASE + 1);
00079       outb(PIC_MASTER_BASE + 1, mask & ~(1 << irq));
00080    }
00081    else
00082    {
00083       mask = inb(PIC_SLAVE_BASE + 1);
00084       outb(PIC_SLAVE_BASE + 1, mask & ~(1 << (irq - 8)));
00085    }
00086 
00087    return (POK_ERRNO_OK);
00088 }
00089 
00090 void pok_pic_eoi (uint8_t irq)
00091 {
00092    if (irq >= 8)
00093    {
00094       outb (PIC_SLAVE_BASE, 0x20);
00095    }
00096 
00097    outb (PIC_MASTER_BASE, 0x20);
00098 }
00099