1 #include "pci_irq.h"
2 #include "exception/irq.h"
3 #include <common/errno.h>
4 #include <common/kprint.h>
5 // 现在pci设备的中断由自己进行控制,这些不执行内容的函数是为了适配旧的中断处理机制
pci_irq_enable(ul irq_num)6 void pci_irq_enable(ul irq_num)
7 {
8
9 }
pci_irq_disable(ul irq_num)10 void pci_irq_disable(ul irq_num)
11 {
12
13 }
pci_irq_install(ul irq_num)14 void pci_irq_install(ul irq_num)
15 {
16
17 }
pci_irq_uninstall(ul irq_num)18 void pci_irq_uninstall(ul irq_num)
19 {
20
21 }
22 /// @brief 与本操作系统的中断机制进行交互,把中断处理函数等注册到中断结构体中(被rust调用)
23 /// @param irq_num 要进行注册的中断号
24 /// @param pci_irq_handler 对应的中断处理函数
25 /// @param parameter 中断处理函数传入参数
26 /// @param irq_name 中断名字
27 /// @param pci_irq_ack 对于中断的回复,为NULL时会使用默认回应
c_irq_install(ul irq_num,void (* pci_irq_handler)(ul irq_num,ul parameter,struct pt_regs * regs),ul parameter,const char * irq_name,void (* pci_irq_ack)(ul irq_num))28 uint16_t c_irq_install(ul irq_num,void (*pci_irq_handler)(ul irq_num, ul parameter, struct pt_regs *regs),ul parameter,const char *irq_name,void (*pci_irq_ack)(ul irq_num))
29 {
30 // 由于为I/O APIC分配的中断向量号是从32开始的,因此要减去32才是对应的interrupt_desc的元素
31 irq_desc_t *p = NULL;
32 if (irq_num >= 32 && irq_num < 0x80)
33 p = &interrupt_desc[irq_num - 32];
34 else if (irq_num >= 150 && irq_num < 200)
35 p = &local_apic_interrupt_desc[irq_num - 150];
36 else
37 {
38 //kerror("irq install for pci irq: invalid irq num: %ld.", irq_num);
39 return EINVAL;
40 }
41 if(p->irq_name!=NULL)
42 {
43 return EAGAIN;
44 }
45 hardware_intr_controller* pci_interrupt_controller = kmalloc(sizeof(hardware_intr_controller),0);
46 pci_interrupt_controller->enable = pci_irq_enable;
47 pci_interrupt_controller->disable = pci_irq_disable;
48 pci_interrupt_controller->install= pci_irq_install;
49 pci_interrupt_controller->uninstall= pci_irq_uninstall;
50 if(pci_irq_ack)
51 pci_interrupt_controller->ack = pci_irq_ack;
52 int namelen = sizeof(strlen(irq_name) + 1);
53 p->irq_name = (char *)kmalloc(namelen, 0);
54 memset(p->irq_name, 0, namelen);
55 strncpy(p->irq_name, irq_name, namelen);
56 p->parameter = parameter;
57 p->flags = 0;
58 p->handler = pci_irq_handler;
59 return 0;
60 };
61
62 /// @brief 与本操作系统的中断机制进行交互,把中断处理函数等从中断结构体中移除,需要释放空间的进行空间的释放
63 /// @param irq_num 要进行注销的中断号
c_irq_uninstall(ul irq_num)64 void c_irq_uninstall(ul irq_num)
65 {
66 // 由于为I/O APIC分配的中断向量号是从32开始的,因此要减去32才是对应的interrupt_desc的元素
67 irq_desc_t *p = NULL;
68 if (irq_num >= 32 && irq_num < 0x80)
69 p = &interrupt_desc[irq_num - 32];
70 else if (irq_num >= 150 && irq_num < 200)
71 p = &local_apic_interrupt_desc[irq_num - 150];
72 else
73 {
74 kerror("irq install for pci irq: invalid irq num: %ld.", irq_num);
75 }
76 if(p->irq_name!=NULL)
77 {
78 kfree(p->irq_name);
79 p->irq_name = NULL;
80 }
81 if(p->controller!=NULL)
82 {
83 kfree(p->controller);
84 p->controller = NULL;
85 }
86 p->parameter = 0;
87 p->handler = NULL;
88 }