+void
+achi_register_ops(struct hba_port* port);
+
+unsigned int
+ahci_get_port_usage()
+{
+ return hba.ports_bmp;
+}
+
+struct hba_port*
+ahci_get_port(unsigned int index)
+{
+ if (index >= 32) {
+ return 0;
+ }
+ return hba.ports[index];
+}
+
+void
+__hba_reset_port(hba_reg_t* port_reg)
+{
+ // 根据:SATA-AHCI spec section 10.4.2 描述的端口重置流程
+ port_reg[HBA_RPxCMD] &= ~HBA_PxCMD_ST;
+ port_reg[HBA_RPxCMD] &= ~HBA_PxCMD_FRE;
+ int cnt = wait_until_expire(!(port_reg[HBA_RPxCMD] & HBA_PxCMD_CR), 500000);
+ if (cnt) {
+ return;
+ }
+ // 如果port未响应,则继续执行重置
+ port_reg[HBA_RPxSCTL] = (port_reg[HBA_RPxSCTL] & ~0xf) | 1;
+ io_delay(100000); //等待至少一毫秒,差不多就行了
+ port_reg[HBA_RPxSCTL] &= ~0xf;
+}
+