ata.c 2.0 KB

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