diff mbox

[13/19] libqos/ahci: add ahci command size setters

Message ID 1422643333-27926-14-git-send-email-jsnow@redhat.com
State New
Headers show

Commit Message

John Snow Jan. 30, 2015, 6:42 p.m. UTC
Adds setters for size, prd_size and both via set_sizes.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 tests/libqos/ahci.c | 22 ++++++++++++++++++++++
 tests/libqos/ahci.h |  5 +++++
 2 files changed, 27 insertions(+)

Comments

Paolo Bonzini Feb. 2, 2015, 10:35 a.m. UTC | #1
On 30/01/2015 19:42, John Snow wrote:
> +void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes,
> +                            unsigned prd_size)
> +{
> +    /* Each PRD can describe up to 4MiB, and must not be odd. */
> +    g_assert_cmphex(prd_size, <=, 4096 * 1024);
> +    g_assert_cmphex(prd_size & 0x01, ==, 0x00);
> +    cmd->prd_size = prd_size;
> +    cmd->xbytes = xbytes;
> +    cmd->fis.count = cpu_to_le16(cmd->xbytes / AHCI_SECTOR_SIZE);

Why do you need cpu_to_le16 here, instead of having it in the function
that writes the command to guest memory?

Paolo

> +    cmd->header.prdtl = size_to_prdtl(cmd->xbytes, cmd->prd_size);
> +}
> +
John Snow Feb. 2, 2015, 9:09 p.m. UTC | #2
On 02/02/2015 05:35 AM, Paolo Bonzini wrote:
>
>
> On 30/01/2015 19:42, John Snow wrote:
>> +void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes,
>> +                            unsigned prd_size)
>> +{
>> +    /* Each PRD can describe up to 4MiB, and must not be odd. */
>> +    g_assert_cmphex(prd_size, <=, 4096 * 1024);
>> +    g_assert_cmphex(prd_size & 0x01, ==, 0x00);
>> +    cmd->prd_size = prd_size;
>> +    cmd->xbytes = xbytes;
>> +    cmd->fis.count = cpu_to_le16(cmd->xbytes / AHCI_SECTOR_SIZE);
>
> Why do you need cpu_to_le16 here, instead of having it in the function
> that writes the command to guest memory?
>
> Paolo
>
>> +    cmd->header.prdtl = size_to_prdtl(cmd->xbytes, cmd->prd_size);
>> +}
>> +
>

In this case, only the command header had a utility written for it to 
flip the bits for me. This is part of the FIS, instead, which has no 
explicit flip-on-write mechanism inside of commit.

So, it's correct, but not terribly consistent.

I can write a fis write helper to make this more internally consistent 
about when we handle it for the user and when we don't.
Paolo Bonzini Feb. 3, 2015, 8:52 a.m. UTC | #3
On 02/02/2015 22:09, John Snow wrote:
> 
> In this case, only the command header had a utility written for it to
> flip the bits for me. This is part of the FIS, instead, which has no
> explicit flip-on-write mechanism inside of commit.
> 
> So, it's correct, but not terribly consistent.
> 
> I can write a fis write helper to make this more internally consistent
> about when we handle it for the user and when we don't.

Please do. :)

Paolo
diff mbox

Patch

diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
index 594c821..3375d54 100644
--- a/tests/libqos/ahci.c
+++ b/tests/libqos/ahci.c
@@ -648,6 +648,28 @@  void ahci_command_set_buffer(AHCICommand *cmd, uint64_t buffer)
     cmd->buffer = buffer;
 }
 
+void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes,
+                            unsigned prd_size)
+{
+    /* Each PRD can describe up to 4MiB, and must not be odd. */
+    g_assert_cmphex(prd_size, <=, 4096 * 1024);
+    g_assert_cmphex(prd_size & 0x01, ==, 0x00);
+    cmd->prd_size = prd_size;
+    cmd->xbytes = xbytes;
+    cmd->fis.count = cpu_to_le16(cmd->xbytes / AHCI_SECTOR_SIZE);
+    cmd->header.prdtl = size_to_prdtl(cmd->xbytes, cmd->prd_size);
+}
+
+void ahci_command_set_size(AHCICommand *cmd, uint64_t xbytes)
+{
+    ahci_command_set_sizes(cmd, xbytes, cmd->prd_size);
+}
+
+void ahci_command_set_prd_size(AHCICommand *cmd, unsigned prd_size)
+{
+    ahci_command_set_sizes(cmd, cmd->xbytes, prd_size);
+}
+
 void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t px)
 {
     uint16_t i, prdtl;
diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h
index 46b7bf3..1300967 100644
--- a/tests/libqos/ahci.h
+++ b/tests/libqos/ahci.h
@@ -531,6 +531,11 @@  void ahci_command_verify(AHCIQState *ahci, AHCICommand *cmd);
 void ahci_command_free(AHCICommand *cmd);
 /* Command adjustments */
 void ahci_command_set_buffer(AHCICommand *cmd, uint64_t buffer);
+void ahci_command_set_size(AHCICommand *cmd, uint64_t xbytes);
+void ahci_command_set_prd_size(AHCICommand *cmd, unsigned prd_size);
+void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes,
+                            unsigned prd_size);
 
 uint8_t ahci_command_slot(AHCICommand *cmd);
+
 #endif