From 79b95d0045a1a1362bc14d54a3322ff96d59f426 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sun, 20 May 2018 17:59:08 -0700 Subject: [PATCH] Move FIS creation into make_command --- src/kernel/ahci/port.cpp | 25 +++++++++++-------------- src/kernel/ahci/port.h | 4 +++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/kernel/ahci/port.cpp b/src/kernel/ahci/port.cpp index 5316716..ef40970 100644 --- a/src/kernel/ahci/port.cpp +++ b/src/kernel/ahci/port.cpp @@ -204,7 +204,7 @@ port::stop_commands() } int -port::make_command(size_t length) +port::make_command(size_t length, fis_register_h2d **fis) { int slot = -1; uint32_t used_slots = @@ -238,10 +238,11 @@ port::make_command(size_t length) ent.flags = cmd_list_fis_size(sizeof(fis_register_h2d)); - fis_register_h2d *fis = reinterpret_cast(&cmdt.cmd_fis); - kutil::memset(fis, 0, sizeof(fis_register_h2d)); - fis->type = fis_type::register_h2d; - fis->pm_port = 0x80; // set command register flag + fis_register_h2d *cfis = reinterpret_cast(&cmdt.cmd_fis); + kutil::memset(cfis, 0, sizeof(fis_register_h2d)); + cfis->type = fis_type::register_h2d; + cfis->pm_port = 0x80; // set command register flag + *fis = cfis; size_t remaining = length; for (int i = 0; i < max_prd_count; ++i) { @@ -272,13 +273,13 @@ port::make_command(size_t length) int port::read_async(uint64_t offset, size_t length, void *dest) { - int slot = make_command(length); + fis_register_h2d *fis; + int slot = make_command(length, &fis); if (slot < 0) return 0; cmd_table &cmdt = m_cmd_table[slot]; - fis_register_h2d *fis = reinterpret_cast(&cmdt.cmd_fis); fis->command = ata_cmd::read_dma_ext; fis->device = 0x40; // ATA8-ACS p.175 @@ -336,22 +337,18 @@ port::read(uint64_t offset, size_t length, void *dest) int port::identify_async() { - int slot = make_command(512); + fis_register_h2d *fis; + int slot = make_command(512, &fis); if (slot < 0) return 0; - cmd_table &cmdt = m_cmd_table[slot]; - - fis_register_h2d *fis = reinterpret_cast(&cmdt.cmd_fis); - kutil::memset(fis, 0, sizeof(fis_register_h2d)); - fis->type = fis_type::register_h2d; - fis->pm_port = 0x80; // set command register flag fis->command = ata_cmd::identify; m_pending[slot].type = command_type::identify; m_pending[slot].offset = 0; m_pending[slot].count = 0; m_pending[slot].data = 0; + if(issue_command(slot)) return slot; else diff --git a/src/kernel/ahci/port.h b/src/kernel/ahci/port.h index 68dfc81..8d1885f 100644 --- a/src/kernel/ahci/port.h +++ b/src/kernel/ahci/port.h @@ -10,6 +10,7 @@ namespace ahci { struct cmd_list_entry; struct cmd_table; +struct fis_register_h2d; class hba; enum class sata_signature : uint32_t; enum class port_cmd : uint32_t; @@ -92,8 +93,9 @@ private: /// Initialize a command structure /// \arg length The number of bytes of data needed in the PRDs + /// \arg fis [out] The FIS for this command /// \returns The index of the command slot, or -1 if none available - int make_command(size_t length); + int make_command(size_t length, fis_register_h2d **fis); /// Send a constructed command to the hardware /// \arg slot The index of the command slot used