ahci: factor out FIS decomposition from handle_cmd
In order to make handle_cmd more readable at the macro level, the details of how to decompose particular types of FIS packets are left to helper functions. In our case, the only type of FIS packet we currently expect to see is a Register H2D FIS packet, but the gory details of its decomposition are of no particular interest in handle_cmd. This patch keeps the receipt of FIS packets and the decomposition thereof separated to two different functions. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1415058979-16604-6-git-send-email-jsnow@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
102e56254d
commit
107f0d4677
129
hw/ide/ahci.c
129
hw/ide/ahci.c
|
@ -946,76 +946,25 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
|
|||
}
|
||||
}
|
||||
|
||||
static int handle_cmd(AHCIState *s, int port, int slot)
|
||||
static void handle_reg_h2d_fis(AHCIState *s, int port,
|
||||
int slot, uint8_t *cmd_fis)
|
||||
{
|
||||
IDEState *ide_state;
|
||||
uint32_t opts;
|
||||
uint64_t tbl_addr;
|
||||
AHCICmdHdr *cmd;
|
||||
uint8_t *cmd_fis;
|
||||
dma_addr_t cmd_len;
|
||||
|
||||
if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) {
|
||||
/* Engine currently busy, try again later */
|
||||
DPRINTF(port, "engine busy\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!s->dev[port].lst) {
|
||||
DPRINTF(port, "error: lst not given but cmd handled");
|
||||
return -1;
|
||||
}
|
||||
cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot];
|
||||
/* remember current slot handle for later */
|
||||
s->dev[port].cur_cmd = cmd;
|
||||
|
||||
/* The device we are working for */
|
||||
ide_state = &s->dev[port].port.ifs[0];
|
||||
if (!ide_state->blk) {
|
||||
DPRINTF(port, "error: guest accessed unused port");
|
||||
return -1;
|
||||
}
|
||||
|
||||
opts = le32_to_cpu(cmd->opts);
|
||||
tbl_addr = le64_to_cpu(cmd->tbl_addr);
|
||||
cmd_len = 0x80;
|
||||
cmd_fis = dma_memory_map(s->as, tbl_addr, &cmd_len,
|
||||
DMA_DIRECTION_FROM_DEVICE);
|
||||
if (!cmd_fis) {
|
||||
DPRINTF(port, "error: guest passed us an invalid cmd fis\n");
|
||||
return -1;
|
||||
} else if (cmd_len != 0x80) {
|
||||
ahci_trigger_irq(s, &s->dev[port], PORT_IRQ_HBUS_ERR);
|
||||
DPRINTF(port, "error: dma_memory_map failed: "
|
||||
"(len(%02"PRIx64") != 0x80)\n",
|
||||
cmd_len);
|
||||
goto out;
|
||||
}
|
||||
debug_print_fis(cmd_fis, 0x80);
|
||||
|
||||
switch (cmd_fis[0]) {
|
||||
case SATA_FIS_TYPE_REGISTER_H2D:
|
||||
break;
|
||||
default:
|
||||
DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x "
|
||||
"cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1],
|
||||
cmd_fis[2]);
|
||||
goto out;
|
||||
break;
|
||||
}
|
||||
IDEState *ide_state = &s->dev[port].port.ifs[0];
|
||||
AHCICmdHdr *cmd = s->dev[port].cur_cmd;
|
||||
uint32_t opts = le32_to_cpu(cmd->opts);
|
||||
|
||||
if (cmd_fis[1] & 0x0F) {
|
||||
DPRINTF(port, "Port Multiplier not supported."
|
||||
" cmd_fis[0]=%02x cmd_fis[1]=%02x cmd_fis[2]=%02x\n",
|
||||
cmd_fis[0], cmd_fis[1], cmd_fis[2]);
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd_fis[1] & 0x70) {
|
||||
DPRINTF(port, "Reserved flags set in H2D Register FIS."
|
||||
" cmd_fis[0]=%02x cmd_fis[1]=%02x cmd_fis[2]=%02x\n",
|
||||
cmd_fis[0], cmd_fis[1], cmd_fis[2]);
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(cmd_fis[1] & SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER)) {
|
||||
|
@ -1031,14 +980,13 @@ static int handle_cmd(AHCIState *s, int port, int slot)
|
|||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
else if (cmd_fis[1] & SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER) {
|
||||
|
||||
/* Check for NCQ command */
|
||||
if (is_ncq(cmd_fis[2])) {
|
||||
process_ncq_command(s, port, cmd_fis, slot);
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Decompose the FIS:
|
||||
|
@ -1066,8 +1014,7 @@ static int handle_cmd(AHCIState *s, int port, int slot)
|
|||
/* 15: Only valid when UPDATE_COMMAND not set. */
|
||||
|
||||
/* Copy the ACMD field (ATAPI packet, if any) from the AHCI command
|
||||
* table to ide_state->io_buffer
|
||||
*/
|
||||
* table to ide_state->io_buffer */
|
||||
if (opts & AHCI_CMD_ATAPI) {
|
||||
memcpy(ide_state->io_buffer, &cmd_fis[AHCI_COMMAND_TABLE_ACMD], 0x10);
|
||||
debug_print_fis(ide_state->io_buffer, 0x10);
|
||||
|
@ -1082,6 +1029,62 @@ static int handle_cmd(AHCIState *s, int port, int slot)
|
|||
|
||||
/* We're ready to process the command in FIS byte 2. */
|
||||
ide_exec_cmd(&s->dev[port].port, cmd_fis[2]);
|
||||
}
|
||||
|
||||
static int handle_cmd(AHCIState *s, int port, int slot)
|
||||
{
|
||||
IDEState *ide_state;
|
||||
uint64_t tbl_addr;
|
||||
AHCICmdHdr *cmd;
|
||||
uint8_t *cmd_fis;
|
||||
dma_addr_t cmd_len;
|
||||
|
||||
if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) {
|
||||
/* Engine currently busy, try again later */
|
||||
DPRINTF(port, "engine busy\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!s->dev[port].lst) {
|
||||
DPRINTF(port, "error: lst not given but cmd handled");
|
||||
return -1;
|
||||
}
|
||||
cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot];
|
||||
/* remember current slot handle for later */
|
||||
s->dev[port].cur_cmd = cmd;
|
||||
|
||||
/* The device we are working for */
|
||||
ide_state = &s->dev[port].port.ifs[0];
|
||||
if (!ide_state->blk) {
|
||||
DPRINTF(port, "error: guest accessed unused port");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tbl_addr = le64_to_cpu(cmd->tbl_addr);
|
||||
cmd_len = 0x80;
|
||||
cmd_fis = dma_memory_map(s->as, tbl_addr, &cmd_len,
|
||||
DMA_DIRECTION_FROM_DEVICE);
|
||||
if (!cmd_fis) {
|
||||
DPRINTF(port, "error: guest passed us an invalid cmd fis\n");
|
||||
return -1;
|
||||
} else if (cmd_len != 0x80) {
|
||||
ahci_trigger_irq(s, &s->dev[port], PORT_IRQ_HBUS_ERR);
|
||||
DPRINTF(port, "error: dma_memory_map failed: "
|
||||
"(len(%02"PRIx64") != 0x80)\n",
|
||||
cmd_len);
|
||||
goto out;
|
||||
}
|
||||
debug_print_fis(cmd_fis, 0x80);
|
||||
|
||||
switch (cmd_fis[0]) {
|
||||
case SATA_FIS_TYPE_REGISTER_H2D:
|
||||
handle_reg_h2d_fis(s, port, slot, cmd_fis);
|
||||
break;
|
||||
default:
|
||||
DPRINTF(port, "unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x "
|
||||
"cmd_fis[2]=%02x\n", cmd_fis[0], cmd_fis[1],
|
||||
cmd_fis[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
|
|
Loading…
Reference in a new issue