Move FIS creation into make_command

This commit is contained in:
Justin C. Miller
2018-05-20 17:59:08 -07:00
parent 1e66e5cd82
commit 79b95d0045
2 changed files with 14 additions and 15 deletions

View File

@@ -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<fis_register_h2d *>(&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<fis_register_h2d *>(&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<fis_register_h2d *>(&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<fis_register_h2d *>(&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

View File

@@ -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