Skip to content

Commit

Permalink
[kernel][driver][ata] Integrate SATA driver to ATA driver stack
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBrave committed Jul 29, 2022
1 parent 253c2d4 commit 0d14a8c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
35 changes: 32 additions & 3 deletions kernel/driver/ata/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ int ata_identify(struct ATADevice* dev, char* model) {
return -1;
}
} else if (dev->transport == ATA_TRANSPORT_SERIAL_ATA) {
panic("SATA not supported");
if (sata_exec_pio_in(&dev->sata, ATA_COMMAND_IDENTIFY, 0, 0, identify, 1)) {
kfree(identify);
return -1;
}
}

for (int i = 0; i < 20; i++) {
Expand Down Expand Up @@ -97,7 +100,22 @@ int ata_identify(struct ATADevice* dev, char* model) {
}
}
} else if (dev->transport == ATA_TRANSPORT_SERIAL_ATA) {
panic("SATA not supported");
dev->sata.ncq_queue_depth = (identify[75] & 0x1f) + 1;
if (identify[76] & (1 << 8)) {
dev->sata.support_ncq = 1;
}
if (identify[76] & (1 << 12)) {
dev->sata.support_ncq_priority_info = 1;
}
if (identify[77] & (1 << 4)) {
dev->sata.support_ncq_streaming = 1;
}
if (identify[77] & (1 << 5)) {
dev->sata.support_ncq_queue_mgmt_cmd = 1;
}
if (identify[77] & (1 << 6)) {
dev->sata.support_receive_send_fpdma_queued = 1;
}
}

kfree(identify);
Expand Down Expand Up @@ -180,7 +198,18 @@ void ata_register_ata_device(struct ATADevice* ata_dev) {
ata_dev->pata.drive);
}
} else if (ata_dev->transport == ATA_TRANSPORT_SERIAL_ATA) {
panic("SATA not supported");
if (ata_dev->sata.support_ncq) {
cprintf(
"[ata] SATA NCQ%s NCQPrio%s NCQStream%s NCQMgmtCmd%s NCQRXTXFPDMA%s QLen %d\n",
BOOL2SIGN(ata_dev->sata.support_ncq),
BOOL2SIGN(ata_dev->sata.support_ncq_priority_info),
BOOL2SIGN(ata_dev->sata.support_ncq_streaming),
BOOL2SIGN(ata_dev->sata.support_ncq_queue_mgmt_cmd),
BOOL2SIGN(ata_dev->sata.support_receive_send_fpdma_queued),
ata_dev->sata.ncq_queue_depth);
} else {
cprintf("[ata] SATA NCQ not supported\n");
}
}

hal_block_register_device("ata", ata_dev, &ata_block_driver);
Expand Down
5 changes: 5 additions & 0 deletions kernel/driver/ata/sata.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ void sata_register_controller(struct SATAController* sata_controller) {
switch (sata_port_get_signature(sata_controller, port)) {
case SATA_SIGNATURE_ATA:
cprintf("[ata] ATA device found on SATA controller port %d\n", port);
struct ATADevice* ata_dev = ata_device_alloc();
ata_dev->transport = ATA_TRANSPORT_SERIAL_ATA;
ata_dev->sata.controller = sata_controller;
ata_dev->sata.port = port;
ata_register_ata_device(ata_dev);
break;
case SATA_SIGNATURE_ATAPI:
cprintf("[ata] ATAPI device found on SATA controller port %d\n", port);
Expand Down

0 comments on commit 0d14a8c

Please sign in to comment.