Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 36... Line 36...
36
#include <arch/drivers/pic.h>
36
#include <arch/drivers/pic.h>
37
#include <mm/page.h>
37
#include <mm/page.h>
38
#include <byteorder.h>
38
#include <byteorder.h>
39
#include <bitops.h>
39
#include <bitops.h>
40
 
40
 
41
static volatile uint32_t *pic;
41
static volatile uint32_t *pic = NULL;
42
 
42
 
43
void pic_init(uintptr_t base, size_t size)
43
void pic_init(uintptr_t base, size_t size)
44
{
44
{
45
    pic = (uint32_t *) hw_map(base, size);
45
    pic = (uint32_t *) hw_map(base, size);
46
}
46
}
47
 
47
 
48
void pic_enable_interrupt(int intnum)
48
void pic_enable_interrupt(int intnum)
49
{
49
{
-
 
50
    if (pic) {
50
    if (intnum < 32) {
51
        if (intnum < 32)
51
        pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] | (1 << intnum);
52
            pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] | (1 << intnum);
52
    } else {
53
        else
53
        pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] | (1 << (intnum - 32));
54
            pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] | (1 << (intnum - 32));
54
    }
55
    }
55
   
56
   
56
}
57
}
57
 
58
 
58
void pic_disable_interrupt(int intnum)
59
void pic_disable_interrupt(int intnum)
59
{
60
{
-
 
61
    if (pic) {
60
    if (intnum < 32) {
62
        if (intnum < 32)
61
        pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] & (~(1 << intnum));
63
            pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] & (~(1 << intnum));
62
    } else {
64
        else
63
        pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] & (~(1 << (intnum - 32)));
65
            pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] & (~(1 << (intnum - 32)));
64
    }
66
    }
65
}
67
}
66
 
68
 
67
void pic_ack_interrupt(int intnum)
69
void pic_ack_interrupt(int intnum)
68
{
70
{
-
 
71
    if (pic) {
69
    if (intnum < 32)
72
        if (intnum < 32)
70
        pic[PIC_ACK_LOW] = 1 << intnum;
73
            pic[PIC_ACK_LOW] = 1 << intnum;
71
    else
74
        else
72
        pic[PIC_ACK_HIGH] = 1 << (intnum - 32);
75
            pic[PIC_ACK_HIGH] = 1 << (intnum - 32);
-
 
76
    }
73
}
77
}
74
 
78
 
75
/** Return number of pending interrupt */
79
/** Return number of pending interrupt */
76
int pic_get_pending(void)
80
int pic_get_pending(void)
77
{
81
{
-
 
82
    if (pic) {
78
    int pending;
83
        int pending;
79
 
84
       
80
    pending = pic[PIC_PENDING_LOW];
85
        pending = pic[PIC_PENDING_LOW];
81
    if (pending)
86
        if (pending)
82
        return fnzb32(pending);
87
            return fnzb32(pending);
83
   
88
       
84
    pending = pic[PIC_PENDING_HIGH];
89
        pending = pic[PIC_PENDING_HIGH];
85
    if (pending)
90
        if (pending)
86
        return fnzb32(pending) + 32;
91
            return fnzb32(pending) + 32;
-
 
92
    }
87
   
93
   
88
    return -1;
94
    return -1;
89
}
95
}
90
 
96
 
91
/** @}
97
/** @}