1 #include "ata.h"
2 #include <common/kprint.h>
3 #include <driver/interrupt/apic/apic.h>
4
5 struct apic_IO_APIC_RTE_entry entry;
6
7 /**
8 * @brief 硬盘中断上半部处理程序
9 *
10 * @param irq_num
11 * @param param
12 * @param regs
13 */
ata_disk_handler(ul irq_num,ul param,struct pt_regs * regs)14 void ata_disk_handler(ul irq_num, ul param, struct pt_regs *regs)
15 {
16 struct ata_identify_device_data info;
17
18 kdebug("irq_num=%ld", irq_num);
19
20 // 从端口读入磁盘配置信息
21 io_insw(PORT_DISK0_DATA, &info, 256);
22 kdebug("General_Config=%#018lx", info.General_Config);
23 printk("Serial number:");
24 unsigned char buf[64];
25 int js=0;
26 //printk("%d", info.Serial_Number);
27
28 for(int i = 0;i<10;i++)
29 {
30 buf[js++]=(info.Serial_Number[i] & 0xff);
31 }
32 buf[js] = '\0';
33 printk("%s", buf);
34 printk("\n");
35
36
37
38 }
39
40 hardware_intr_controller ata_disk_intr_controller =
41 {
42 .enable = apic_ioapic_enable,
43 .disable = apic_ioapic_disable,
44 .install = apic_ioapic_install,
45 .uninstall = apic_ioapic_uninstall,
46 .ack = apic_ioapic_edge_ack,
47 };
48
49 /**
50 * @brief 初始化ATA磁盘驱动程序
51 *
52 */
ata_init()53 void ata_init()
54 {
55 entry.vector = 0x2e;
56 entry.deliver_mode = IO_APIC_FIXED;
57 entry.dest_mode = DEST_PHYSICAL;
58 entry.deliver_status = IDLE;
59 entry.polarity = POLARITY_HIGH;
60 entry.remote_IRR = IRR_RESET;
61 entry.trigger_mode = EDGE_TRIGGER;
62 entry.mask = MASKED;
63 entry.reserved = 0;
64
65 entry.destination.physical.reserved1 = 0;
66 entry.destination.physical.reserved2 = 0;
67 entry.destination.physical.phy_dest = 0; // 投递至BSP
68
69 irq_register(entry.vector, &entry, &ata_disk_handler, 0, &ata_disk_intr_controller, "ATA Disk 1");
70
71 io_out8(PORT_DISK0_STATUS_CTRL_REG, 0); // 使能中断请求
72
73 io_out8(PORT_DISK0_ERR_STATUS, 0);
74 io_out8(PORT_DISK0_SECTOR_CNT, 0);
75 io_out8(PORT_DISK0_LBA_7_0, 0);
76 io_out8(PORT_DISK0_LBA_15_8, 0);
77 io_out8(PORT_DISK0_LBA_23_16, 0);
78 io_out8(PORT_DISK0_DEVICE_CONFIGURE_REG, 0);
79
80 io_out8(PORT_DISK0_CONTROLLER_STATUS_CMD, 0xec); // 获取硬件设备识别信息
81 }