Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: af49f52)
raw | patch | inline | side by side (parent: af49f52)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Mon, 19 Jan 2026 14:30:16 +0000 (22:30 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Mon, 19 Jan 2026 14:30:16 +0000 (22:30 +0800) |
| drivers/ahci.c | patch | blob | history | |
| drivers/sata.c | patch | blob | history | |
| drivers/sata.h | patch | blob | history |
diff --git a/drivers/ahci.c b/drivers/ahci.c
--- a/drivers/ahci.c
+++ b/drivers/ahci.c
hba->global_hba_control |= AHCI_ENABLE;
- hba->global_hba_control |= AHCI_INTERRUPT_ENABLE;
-
uint32_t cap = hba->capability;
int num_ports = (cap & 0x1F) + 1;
}
}
}
+
+ // TODO
+ // 开启ahci的global_hba_control的interrupt enable位
+ hba->global_hba_control |= AHCI_INTERRUPT_ENABLE;
}
void init_ahci() {
diff --git a/drivers/sata.c b/drivers/sata.c
--- a/drivers/sata.c
+++ b/drivers/sata.c
//
assert(sizeof(ahci_cmd_header_t) == 32);
ahci_cmd_header_t* cmd_list = (ahci_cmd_header_t*)sata->cmd_list_base_vaddr;
-#if 1
- for (int i = 0; i < 32; i++) {
- ahci_cmd_header_t* hdr = &cmd_list[i];
- printk(" cmd_list[%02d] base %08x prdt %04x:%d\n", i, hdr->cmd_table_base, hdr->prdtl, hdr->prdtl);
- hdr->cmd_table_base = 0;
- hdr->prdtl = 0;
- }
-#endif
sata->cmd_table_paddr = (paddr_t)page2pa(alloc_one_page(0));
sata->cmd_table_vaddr = (ahci_cmd_table_t*)ioremap(sata->cmd_table_paddr, PAGE_SIZE);
sata->cmd_table0 = cmd_table + 0;
sata->prdte0 = cmd_table[0].prdt + 0;
+ //
+ sata_identify(sata);
+}
+
+void sata_identify(sata_device_t* sata) {
+ assert(sata != NULL);
sata->prdte0->data_base = sata->data_paddr;
sata->prdte0->data_byte_count = (512 - 1) | 1;
- sata->prdte0->ioc = 1;
+ sata->prdte0->ioc = 0;
//
ahci_fis_reg_h2d_t* fis = (ahci_fis_reg_h2d_t*)sata->cmd_table0->cmd_fis;
// 清除中断状态
// 写1清0
+ ahci_port_t* port = sata->port;
+ assert(port != NULL);
port->interrupt_status = port->interrupt_status;
+ //
port->interrupt_enable = AHCI_INTERRUPT_ENABLE_DHRS;
- asm("sti");
+
//
port->cmd_issue = 1 << 0;
uint32_t timeout = 1000000;
while (timeout--) {
if (port->interrupt_status & 1) {
+ printk("SATA INTERRUPT STATUS: %08x\n", port->interrupt_status);
+ // 清除本次请求产生的中断
+ port->interrupt_status = 1;
break;
}
if (port->sata_error) {
sata_read_identify_string(identify, 27, 46, s);
printk("HD Model: %s\n", s);
-
- // while (!sata_irq_triggered) {
- // // asm("sti");
- // asm("pause");
- // }
-
- // 1. 等待端口空闲(确保上一条命令完全完成)
- while (port->cmd_issue & 1) {
- // 命令位仍被置位,等待清除
- }
- while (port->sata_active & 1) {
- // 等待active位清除
- }
-
- memset(fis, 0, sizeof(ahci_fis_reg_h2d_t));
- fis->fis_type = AHCI_FIS_TYPE_REG_H2D;
- fis->c = 1;
- fis->command = SATA_CMD_IDENTIFY;
- fis->device = SATA_DEVICE_LBA;
-
- sata->cmd_list0->cfl = sizeof(ahci_fis_reg_h2d_t) / sizeof(uint32_t);
- sata->cmd_list0->prdtl = 1;
- sata->cmd_list0->w = 0; // read
- sata->cmd_list0->a = 0; // ata device
- sata->cmd_list0->prd_byte_count = 0;
- // 清除中断状态
- // 写1清0
- port->interrupt_status = port->interrupt_status;
-
- port->interrupt_enable = AHCI_INTERRUPT_ENABLE_DHRS;
-
- //
- port->cmd_issue = 1 << 0;
}
sata_device_t sata_devices[MAX_SATA_DEVICES] = {0};
diff --git a/drivers/sata.h b/drivers/sata.h
--- a/drivers/sata.h
+++ b/drivers/sata.h
extern sata_device_t sata_devices[MAX_SATA_DEVICES];
void sata_read_identify_string(const uint16_t* identify, int bgn, int end, char* buf);
+
+void sata_identify(sata_device_t* sata);