embox

Форк
0
102 строки · 2.1 Кб
1
/**
2
 * @file
3
 * @brief Interrupt controller driver for i8952 chip 9x86 platform.
4
 *
5
 * @details
6
 *   This driver believes that there are two i8952 chip in the system and
7
 *   slave is connected to master's second line.
8
 *   We also suppose that we use only x86 platform.
9
 *
10
 * @date 22.12.10
11
 * @author Nikolay Korotky
12
 */
13

14
#include <asm/io.h>
15
#include <asm/regs.h>
16
#include <asm/traps.h>
17
#include <drivers/irqctrl.h>
18
#include <hal/arch.h>
19
#include <hal/reg.h>
20

21
#include <embox/unit.h>
22

23
#include "i8259_regs.h"
24

25
EMBOX_UNIT_INIT(pic_init);
26

27
/**
28
 * Initialize the PIC
29
 */
30
static int pic_init(void) {
31
	static int inited = 0;
32
	if (1 == inited) {
33
		return 0;
34
	}
35
	inited = 1;
36

37
	/* Initialize the master */
38
	out8(PIC1_ICW1, PIC1_COMMAND);
39
	out8(PIC1_BASE, PIC1_DATA);
40
	out8(PIC1_ICW3, PIC1_DATA);
41
	out8(PIC1_ICW4, PIC1_DATA);
42

43
	/* Initialize the slave */
44
	out8(PIC2_ICW1, PIC2_COMMAND);
45
	out8(PIC2_BASE, PIC2_DATA);
46
	out8(PIC2_ICW3, PIC2_DATA);
47
	out8(PIC2_ICW4, PIC2_DATA);
48

49
	out8(NON_SPEC_EOI, PIC1_COMMAND);
50
	out8(NON_SPEC_EOI, PIC2_COMMAND);
51

52
	out8(PICM_MASK, PIC1_DATA);
53
	out8(PICS_MASK, PIC2_DATA);
54

55
	irqctrl_enable(2); /* enable slave irq controller irq 8-16 */
56

57
	return 0;
58
}
59

60
void apic_init(void) {
61
	pic_init();
62
}
63

64
void irqctrl_enable(unsigned int irq) {
65
	if (irq < 8) {
66
		out8(in8(PIC1_DATA) & ~(1 << irq), PIC1_DATA);
67
	} else {
68
		out8(in8(PIC2_DATA) & ~(1 << (irq - 8)), PIC2_DATA);
69
	}
70
}
71

72
void irqctrl_disable(unsigned int irq) {
73
	if (irq < 8) {
74
		out8(in8(PIC1_DATA) | (1 << irq), PIC1_DATA);
75
	} else {
76
		out8(in8(PIC2_DATA) | (1 << (irq - 8)), PIC2_DATA);
77
	}
78
}
79

80
void irqctrl_force(unsigned int irq) {
81
	// TODO Emm?.. -- Eldar
82
}
83

84
int irqctrl_pending(unsigned int irq) {
85
	if (irq < 8) {
86
		return in8(PIC1_COMMAND) & (1 << irq);
87
	} else {
88
		return in8(PIC2_COMMAND) & (1 << (irq - 8));
89
	}
90
}
91

92
/* Sends an EOI (end of interrupt) signal to the PICs. */
93
void irqctrl_eoi(unsigned int irq) {
94
	if (irq >= 8) {
95
		/* Send reset signal to slave. */
96
		out8(NON_SPEC_EOI, PIC2_COMMAND);
97
	}
98
	/* Send reset signal to master. (As well as to slave, if necessary). */
99
	out8(NON_SPEC_EOI, PIC1_COMMAND);
100
}
101

102
IRQCTRL_DEF(pic, pic_init);
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.