IBNOS
pic.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_PIC_
29 #define _H_PIC_
30 
31 #ifdef __KERNEL__
32 
33  #include <stdbool.h>
34  #include <stdint.h>
35 
36  #define PIC1_PORT 0x20
37  #define PIC2_PORT 0xA0
38  #define PIC1_COMMAND_PORT PIC1_PORT
39  #define PIC1_DATA_PORT (PIC1_PORT+1)
40  #define PIC2_COMMAND_PORT PIC2_PORT
41  #define PIC2_DATA_PORT (PIC2_PORT+1)
42 
43  #define ICW1_ICW4 0x01
44  #define ICW1_SINGLE 0x02
45  #define ICW1_INTERVAL4 0x04
46  #define ICW1_LEVEL 0x08
47  #define ICW1_INIT 0x10
48 
49  #define ICW4_8086 0x01
50  #define ICW4_AUTO 0x02
51  #define ICW4_BUF_SLAVE 0x08
52  #define ICW4_BUF_MASTER 0x0C
53  #define ICW4_SFNM 0x10
54 
55  #define PIC_EOI 0x20
56 
57  #define IRQ_COUNT 16
58 
65  #define IRQ_PIT 0
66  #define IRQ_KEYBOARD 1
67  #define IRQ_SLAVE 2
68  #define IRQ_COM2 3
69  #define IRQ_COM1 4
70  #define IRQ_LPT2 5
71  #define IRQ_FLOPPY 6
72  #define IRQ_LPT1 7
73  #define IRQ_CMOS_CLOCK 8
74  #define IRQ_PS2_MOUSE 12
75  #define IRQ_FPU 13
76  #define IRQ_ATA1 14
77  #define IRQ_ATA2 15
82  typedef uint32_t (*irq_callback)(uint32_t irq);
83 
84  void picInit(uint32_t interruptOffset);
85  bool picReserveIRQ(uint32_t irq, irq_callback callback);
86  void picFreeIRQ(uint32_t irq);
87 
88 #endif
89 
90 #endif /* _H_PIC_ */
uint32_t(* irq_callback)(uint32_t irq)
Definition: pic.h:82
bool picReserveIRQ(uint32_t irq, irq_callback callback)
Assign a callback function to an IRQ.
Definition: pic.c:151
void picInit(uint32_t interruptOffset)
Initializes the programmable interrupt controller.
Definition: pic.c:103
void picFreeIRQ(uint32_t irq)
Release an IRQ.
Definition: pic.c:186