Patchwork [RFC,v2,5/5] qtest: Add MMIO support

login
register
mail settings
Submitter Andreas Färber
Date Feb. 6, 2013, 6:33 p.m.
Message ID <1360175610-8992-6-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/218720/
State New
Headers show

Comments

Andreas Färber - Feb. 6, 2013, 6:33 p.m.
Introduce [qtest_]{read,write}[bwlq]() libqtest functions and
corresponding QTest protocol commands to replace local versions in
libi2c-omap.c.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 qtest.c             |   53 +++++++++++++++++++++++++++++++++++++++++++++
 tests/libi2c-omap.c |   23 --------------------
 tests/libqtest.c    |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqtest.h    |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 4 Dateien geändert, 169 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
Anthony Liguori - Feb. 8, 2013, 9:37 p.m.
Andreas Färber <afaerber@suse.de> writes:

> Introduce [qtest_]{read,write}[bwlq]() libqtest functions and
> corresponding QTest protocol commands to replace local versions in
> libi2c-omap.c.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  qtest.c             |   53 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/libi2c-omap.c |   23 --------------------
>  tests/libqtest.c    |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/libqtest.h    |   56 +++++++++++++++++++++++++++++++++++++++++++++++
>  4 Dateien geändert, 169 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
>
> diff --git a/qtest.c b/qtest.c
> index 4663a38..9a2f9aa 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -277,6 +277,59 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)
>          }
>          qtest_send_prefix(chr);
>          qtest_send(chr, "OK 0x%04x\n", value);
> +    } else if (strcmp(words[0], "writeb") == 0 ||
> +               strcmp(words[0], "writew") == 0 ||
> +               strcmp(words[0], "writel") == 0 ||
> +               strcmp(words[0], "writeq") == 0) {
> +        uint64_t addr;
> +        uint64_t value;
> +
> +        g_assert(words[1] && words[2]);
> +        addr = strtoull(words[1], NULL, 0);
> +        value = strtoull(words[2], NULL, 0);
> +
> +        if (words[0][5] == 'b') {
> +            uint8_t data = value;
> +            cpu_physical_memory_write(addr, &data, 1);
> +        } else if (words[0][5] == 'w') {
> +            uint16_t data = value;
> +            cpu_physical_memory_write(addr, &data, 2);
> +        } else if (words[0][5] == 'l') {
> +            uint32_t data = value;
> +            cpu_physical_memory_write(addr, &data, 4);
> +        } else if (words[0][5] == 'q') {
> +            uint64_t data = value;
> +            cpu_physical_memory_write(addr, &data, 8);
> +        }
> +        qtest_send_prefix(chr);
> +        qtest_send(chr, "OK\n");
> +    } else if (strcmp(words[0], "readb") == 0 ||
> +        strcmp(words[0], "readw") == 0 ||
> +        strcmp(words[0], "readl") == 0 ||
> +        strcmp(words[0], "readq") == 0) {
> +        uint64_t addr;
> +        uint64_t value = UINT64_C(-1);
> +
> +        g_assert(words[1]);
> +        addr = strtoull(words[1], NULL, 0);
> +
> +        if (words[0][4] == 'b') {
> +            uint8_t data;
> +            cpu_physical_memory_read(addr, &data, 1);
> +            value = data;
> +        } else if (words[0][4] == 'w') {
> +            uint16_t data;
> +            cpu_physical_memory_read(addr, &data, 2);
> +            value = data;
> +        } else if (words[0][4] == 'l') {
> +            uint32_t data;
> +            cpu_physical_memory_read(addr, &data, 4);
> +            value = data;
> +        } else if (words[0][4] == 'q') {
> +            cpu_physical_memory_read(addr, &value, 8);
> +        }
> +        qtest_send_prefix(chr);
> +        qtest_send(chr, "OK 0x%016" PRIx64 "\n", value);
>      } else if (strcmp(words[0], "read") == 0) {
>          uint64_t addr, len, i;
>          uint8_t *data;
> diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c
> index b7b10b5..c52458c 100644
> --- a/tests/libi2c-omap.c
> +++ b/tests/libi2c-omap.c
> @@ -49,29 +49,6 @@ typedef struct OMAPI2C {
>  } OMAPI2C;
>  
>  
> -/* FIXME Use TBD readw qtest API */
> -static inline uint16_t readw(uint64_t addr)
> -{
> -    uint16_t data;
> -
> -    memread(addr, &data, 2);
> -    return le16_to_cpu(data);
> -}
> -
> -/* FIXME Use TBD writew qtest API */
> -static inline void writew(uint64_t addr, uint16_t data)
> -{
> -    data = cpu_to_le16(data);
> -    memwrite(addr, &data, 2);
> -}
> -
> -#ifdef __GNUC__
> -#undef memread
> -#undef memwrite
> -#pragma GCC poison memread
> -#pragma GCC poison memwrite
> -#endif
> -
>  static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
>  {
>      uint16_t data = addr;
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 762dec4..5a627d3 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -431,6 +431,66 @@ uint32_t qtest_inl(QTestState *s, uint16_t addr)
>      return qtest_in(s, "inl", addr);
>  }
>  
> +static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,
> +                        uint64_t value)
> +{
> +    qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value);
> +    qtest_rsp(s, 0);
> +}
> +
> +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
> +{
> +    qtest_write(s, "writeb", addr, value);
> +}
> +
> +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
> +{
> +    qtest_write(s, "writew", addr, value);
> +}
> +
> +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
> +{
> +    qtest_write(s, "writel", addr, value);
> +}
> +
> +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
> +{
> +    qtest_write(s, "writeq", addr, value);
> +}
> +
> +static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
> +{
> +    gchar **args;
> +    uint64_t value;
> +
> +    qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr);
> +    args = qtest_rsp(s, 2);
> +    value = strtoull(args[1], NULL, 0);
> +    g_strfreev(args);
> +
> +    return value;
> +}
> +
> +uint8_t qtest_readb(QTestState *s, uint64_t addr)
> +{
> +    return qtest_read(s, "readb", addr);
> +}
> +
> +uint16_t qtest_readw(QTestState *s, uint64_t addr)
> +{
> +    return qtest_read(s, "readw", addr);
> +}
> +
> +uint32_t qtest_readl(QTestState *s, uint64_t addr)
> +{
> +    return qtest_read(s, "readl", addr);
> +}
> +
> +uint64_t qtest_readq(QTestState *s, uint64_t addr)
> +{
> +    return qtest_read(s, "readq", addr);
> +}
> +
>  static int hex2nib(char ch)
>  {
>      if (ch >= '0' && ch <= '9') {
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index c8ade85..4cdaaef 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -135,6 +135,22 @@ uint16_t qtest_inw(QTestState *s, uint16_t addr);
>   */
>  uint32_t qtest_inl(QTestState *s, uint16_t addr);
>  
> +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
> +
> +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
> +
> +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
> +
> +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
> +
> +uint8_t qtest_readb(QTestState *s, uint64_t addr);
> +
> +uint16_t qtest_readw(QTestState *s, uint64_t addr);
> +
> +uint32_t qtest_readl(QTestState *s, uint64_t addr);
> +
> +uint64_t qtest_readq(QTestState *s, uint64_t addr);
> +
>  /**
>   * qtest_memread:
>   * @s: QTestState instance to operate on.
> @@ -303,6 +319,46 @@ void qtest_add_func(const char *str, void (*fn));
>   */
>  #define inl(addr) qtest_inl(global_qtest, addr)
>  
> +static inline void writeb(uint64_t addr, uint8_t value)
> +{
> +    qtest_writeb(global_qtest, addr, value);
> +}
> +
> +static inline void writew(uint64_t addr, uint16_t value)
> +{
> +    qtest_writew(global_qtest, addr, value);
> +}
> +
> +static inline void writel(uint64_t addr, uint32_t value)
> +{
> +    qtest_writel(global_qtest, addr, value);
> +}
> +
> +static inline void writeq(uint64_t addr, uint64_t value)
> +{
> +    qtest_writeq(global_qtest, addr, value);
> +}
> +
> +static inline uint8_t readb(uint64_t addr)
> +{
> +    return qtest_readb(global_qtest, addr);
> +}
> +
> +static inline uint16_t readw(uint64_t addr)
> +{
> +    return qtest_readw(global_qtest, addr);
> +}
> +
> +static inline uint32_t readl(uint64_t addr)
> +{
> +    return qtest_readl(global_qtest, addr);
> +}
> +
> +static inline uint64_t readq(uint64_t addr)
> +{
> +    return qtest_readq(global_qtest, addr);
> +}
> +
>  /**
>   * memread:
>   * @addr: Guest address to read from.
> -- 
> 1.7.10.4
Andreas Färber - Feb. 8, 2013, 9:40 p.m.
Am 08.02.2013 22:37, schrieb Anthony Liguori:
> Andreas Färber <afaerber@suse.de> writes:
> 
>> Introduce [qtest_]{read,write}[bwlq]() libqtest functions and
>> corresponding QTest protocol commands to replace local versions in
>> libi2c-omap.c.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
> 
> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Thanks, but it is broken for Big Endian just like memread/memwrite.
Please do not apply.

The v2 I came up with is compiling qtest.c per target, upcoming. That
will also help with implementing target-specific hypercall support.

Regards,
Andreas

> 
> Regards,
> 
> Anthony Liguori
> 
>> ---
>>  qtest.c             |   53 +++++++++++++++++++++++++++++++++++++++++++++
>>  tests/libi2c-omap.c |   23 --------------------
>>  tests/libqtest.c    |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>  tests/libqtest.h    |   56 +++++++++++++++++++++++++++++++++++++++++++++++
>>  4 Dateien geändert, 169 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
>>
>> diff --git a/qtest.c b/qtest.c
>> index 4663a38..9a2f9aa 100644
>> --- a/qtest.c
>> +++ b/qtest.c
>> @@ -277,6 +277,59 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)
>>          }
>>          qtest_send_prefix(chr);
>>          qtest_send(chr, "OK 0x%04x\n", value);
>> +    } else if (strcmp(words[0], "writeb") == 0 ||
>> +               strcmp(words[0], "writew") == 0 ||
>> +               strcmp(words[0], "writel") == 0 ||
>> +               strcmp(words[0], "writeq") == 0) {
>> +        uint64_t addr;
>> +        uint64_t value;
>> +
>> +        g_assert(words[1] && words[2]);
>> +        addr = strtoull(words[1], NULL, 0);
>> +        value = strtoull(words[2], NULL, 0);
>> +
>> +        if (words[0][5] == 'b') {
>> +            uint8_t data = value;
>> +            cpu_physical_memory_write(addr, &data, 1);
>> +        } else if (words[0][5] == 'w') {
>> +            uint16_t data = value;
>> +            cpu_physical_memory_write(addr, &data, 2);
>> +        } else if (words[0][5] == 'l') {
>> +            uint32_t data = value;
>> +            cpu_physical_memory_write(addr, &data, 4);
>> +        } else if (words[0][5] == 'q') {
>> +            uint64_t data = value;
>> +            cpu_physical_memory_write(addr, &data, 8);
>> +        }
>> +        qtest_send_prefix(chr);
>> +        qtest_send(chr, "OK\n");
>> +    } else if (strcmp(words[0], "readb") == 0 ||
>> +        strcmp(words[0], "readw") == 0 ||
>> +        strcmp(words[0], "readl") == 0 ||
>> +        strcmp(words[0], "readq") == 0) {
>> +        uint64_t addr;
>> +        uint64_t value = UINT64_C(-1);
>> +
>> +        g_assert(words[1]);
>> +        addr = strtoull(words[1], NULL, 0);
>> +
>> +        if (words[0][4] == 'b') {
>> +            uint8_t data;
>> +            cpu_physical_memory_read(addr, &data, 1);
>> +            value = data;
>> +        } else if (words[0][4] == 'w') {
>> +            uint16_t data;
>> +            cpu_physical_memory_read(addr, &data, 2);
>> +            value = data;
>> +        } else if (words[0][4] == 'l') {
>> +            uint32_t data;
>> +            cpu_physical_memory_read(addr, &data, 4);
>> +            value = data;
>> +        } else if (words[0][4] == 'q') {
>> +            cpu_physical_memory_read(addr, &value, 8);
>> +        }
>> +        qtest_send_prefix(chr);
>> +        qtest_send(chr, "OK 0x%016" PRIx64 "\n", value);
>>      } else if (strcmp(words[0], "read") == 0) {
>>          uint64_t addr, len, i;
>>          uint8_t *data;
>> diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c
>> index b7b10b5..c52458c 100644
>> --- a/tests/libi2c-omap.c
>> +++ b/tests/libi2c-omap.c
>> @@ -49,29 +49,6 @@ typedef struct OMAPI2C {
>>  } OMAPI2C;
>>  
>>  
>> -/* FIXME Use TBD readw qtest API */
>> -static inline uint16_t readw(uint64_t addr)
>> -{
>> -    uint16_t data;
>> -
>> -    memread(addr, &data, 2);
>> -    return le16_to_cpu(data);
>> -}
>> -
>> -/* FIXME Use TBD writew qtest API */
>> -static inline void writew(uint64_t addr, uint16_t data)
>> -{
>> -    data = cpu_to_le16(data);
>> -    memwrite(addr, &data, 2);
>> -}
>> -
>> -#ifdef __GNUC__
>> -#undef memread
>> -#undef memwrite
>> -#pragma GCC poison memread
>> -#pragma GCC poison memwrite
>> -#endif
>> -
>>  static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
>>  {
>>      uint16_t data = addr;
>> diff --git a/tests/libqtest.c b/tests/libqtest.c
>> index 762dec4..5a627d3 100644
>> --- a/tests/libqtest.c
>> +++ b/tests/libqtest.c
>> @@ -431,6 +431,66 @@ uint32_t qtest_inl(QTestState *s, uint16_t addr)
>>      return qtest_in(s, "inl", addr);
>>  }
>>  
>> +static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,
>> +                        uint64_t value)
>> +{
>> +    qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value);
>> +    qtest_rsp(s, 0);
>> +}
>> +
>> +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
>> +{
>> +    qtest_write(s, "writeb", addr, value);
>> +}
>> +
>> +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
>> +{
>> +    qtest_write(s, "writew", addr, value);
>> +}
>> +
>> +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
>> +{
>> +    qtest_write(s, "writel", addr, value);
>> +}
>> +
>> +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
>> +{
>> +    qtest_write(s, "writeq", addr, value);
>> +}
>> +
>> +static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
>> +{
>> +    gchar **args;
>> +    uint64_t value;
>> +
>> +    qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr);
>> +    args = qtest_rsp(s, 2);
>> +    value = strtoull(args[1], NULL, 0);
>> +    g_strfreev(args);
>> +
>> +    return value;
>> +}
>> +
>> +uint8_t qtest_readb(QTestState *s, uint64_t addr)
>> +{
>> +    return qtest_read(s, "readb", addr);
>> +}
>> +
>> +uint16_t qtest_readw(QTestState *s, uint64_t addr)
>> +{
>> +    return qtest_read(s, "readw", addr);
>> +}
>> +
>> +uint32_t qtest_readl(QTestState *s, uint64_t addr)
>> +{
>> +    return qtest_read(s, "readl", addr);
>> +}
>> +
>> +uint64_t qtest_readq(QTestState *s, uint64_t addr)
>> +{
>> +    return qtest_read(s, "readq", addr);
>> +}
>> +
>>  static int hex2nib(char ch)
>>  {
>>      if (ch >= '0' && ch <= '9') {
>> diff --git a/tests/libqtest.h b/tests/libqtest.h
>> index c8ade85..4cdaaef 100644
>> --- a/tests/libqtest.h
>> +++ b/tests/libqtest.h
>> @@ -135,6 +135,22 @@ uint16_t qtest_inw(QTestState *s, uint16_t addr);
>>   */
>>  uint32_t qtest_inl(QTestState *s, uint16_t addr);
>>  
>> +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
>> +
>> +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
>> +
>> +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
>> +
>> +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
>> +
>> +uint8_t qtest_readb(QTestState *s, uint64_t addr);
>> +
>> +uint16_t qtest_readw(QTestState *s, uint64_t addr);
>> +
>> +uint32_t qtest_readl(QTestState *s, uint64_t addr);
>> +
>> +uint64_t qtest_readq(QTestState *s, uint64_t addr);
>> +
>>  /**
>>   * qtest_memread:
>>   * @s: QTestState instance to operate on.
>> @@ -303,6 +319,46 @@ void qtest_add_func(const char *str, void (*fn));
>>   */
>>  #define inl(addr) qtest_inl(global_qtest, addr)
>>  
>> +static inline void writeb(uint64_t addr, uint8_t value)
>> +{
>> +    qtest_writeb(global_qtest, addr, value);
>> +}
>> +
>> +static inline void writew(uint64_t addr, uint16_t value)
>> +{
>> +    qtest_writew(global_qtest, addr, value);
>> +}
>> +
>> +static inline void writel(uint64_t addr, uint32_t value)
>> +{
>> +    qtest_writel(global_qtest, addr, value);
>> +}
>> +
>> +static inline void writeq(uint64_t addr, uint64_t value)
>> +{
>> +    qtest_writeq(global_qtest, addr, value);
>> +}
>> +
>> +static inline uint8_t readb(uint64_t addr)
>> +{
>> +    return qtest_readb(global_qtest, addr);
>> +}
>> +
>> +static inline uint16_t readw(uint64_t addr)
>> +{
>> +    return qtest_readw(global_qtest, addr);
>> +}
>> +
>> +static inline uint32_t readl(uint64_t addr)
>> +{
>> +    return qtest_readl(global_qtest, addr);
>> +}
>> +
>> +static inline uint64_t readq(uint64_t addr)
>> +{
>> +    return qtest_readq(global_qtest, addr);
>> +}
>> +
>>  /**
>>   * memread:
>>   * @addr: Guest address to read from.
>> -- 
>> 1.7.10.4

Patch

diff --git a/qtest.c b/qtest.c
index 4663a38..9a2f9aa 100644
--- a/qtest.c
+++ b/qtest.c
@@ -277,6 +277,59 @@  static void qtest_process_command(CharDriverState *chr, gchar **words)
         }
         qtest_send_prefix(chr);
         qtest_send(chr, "OK 0x%04x\n", value);
+    } else if (strcmp(words[0], "writeb") == 0 ||
+               strcmp(words[0], "writew") == 0 ||
+               strcmp(words[0], "writel") == 0 ||
+               strcmp(words[0], "writeq") == 0) {
+        uint64_t addr;
+        uint64_t value;
+
+        g_assert(words[1] && words[2]);
+        addr = strtoull(words[1], NULL, 0);
+        value = strtoull(words[2], NULL, 0);
+
+        if (words[0][5] == 'b') {
+            uint8_t data = value;
+            cpu_physical_memory_write(addr, &data, 1);
+        } else if (words[0][5] == 'w') {
+            uint16_t data = value;
+            cpu_physical_memory_write(addr, &data, 2);
+        } else if (words[0][5] == 'l') {
+            uint32_t data = value;
+            cpu_physical_memory_write(addr, &data, 4);
+        } else if (words[0][5] == 'q') {
+            uint64_t data = value;
+            cpu_physical_memory_write(addr, &data, 8);
+        }
+        qtest_send_prefix(chr);
+        qtest_send(chr, "OK\n");
+    } else if (strcmp(words[0], "readb") == 0 ||
+        strcmp(words[0], "readw") == 0 ||
+        strcmp(words[0], "readl") == 0 ||
+        strcmp(words[0], "readq") == 0) {
+        uint64_t addr;
+        uint64_t value = UINT64_C(-1);
+
+        g_assert(words[1]);
+        addr = strtoull(words[1], NULL, 0);
+
+        if (words[0][4] == 'b') {
+            uint8_t data;
+            cpu_physical_memory_read(addr, &data, 1);
+            value = data;
+        } else if (words[0][4] == 'w') {
+            uint16_t data;
+            cpu_physical_memory_read(addr, &data, 2);
+            value = data;
+        } else if (words[0][4] == 'l') {
+            uint32_t data;
+            cpu_physical_memory_read(addr, &data, 4);
+            value = data;
+        } else if (words[0][4] == 'q') {
+            cpu_physical_memory_read(addr, &value, 8);
+        }
+        qtest_send_prefix(chr);
+        qtest_send(chr, "OK 0x%016" PRIx64 "\n", value);
     } else if (strcmp(words[0], "read") == 0) {
         uint64_t addr, len, i;
         uint8_t *data;
diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c
index b7b10b5..c52458c 100644
--- a/tests/libi2c-omap.c
+++ b/tests/libi2c-omap.c
@@ -49,29 +49,6 @@  typedef struct OMAPI2C {
 } OMAPI2C;
 
 
-/* FIXME Use TBD readw qtest API */
-static inline uint16_t readw(uint64_t addr)
-{
-    uint16_t data;
-
-    memread(addr, &data, 2);
-    return le16_to_cpu(data);
-}
-
-/* FIXME Use TBD writew qtest API */
-static inline void writew(uint64_t addr, uint16_t data)
-{
-    data = cpu_to_le16(data);
-    memwrite(addr, &data, 2);
-}
-
-#ifdef __GNUC__
-#undef memread
-#undef memwrite
-#pragma GCC poison memread
-#pragma GCC poison memwrite
-#endif
-
 static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
 {
     uint16_t data = addr;
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 762dec4..5a627d3 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -431,6 +431,66 @@  uint32_t qtest_inl(QTestState *s, uint16_t addr)
     return qtest_in(s, "inl", addr);
 }
 
+static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,
+                        uint64_t value)
+{
+    qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value);
+    qtest_rsp(s, 0);
+}
+
+void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
+{
+    qtest_write(s, "writeb", addr, value);
+}
+
+void qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
+{
+    qtest_write(s, "writew", addr, value);
+}
+
+void qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
+{
+    qtest_write(s, "writel", addr, value);
+}
+
+void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
+{
+    qtest_write(s, "writeq", addr, value);
+}
+
+static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
+{
+    gchar **args;
+    uint64_t value;
+
+    qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr);
+    args = qtest_rsp(s, 2);
+    value = strtoull(args[1], NULL, 0);
+    g_strfreev(args);
+
+    return value;
+}
+
+uint8_t qtest_readb(QTestState *s, uint64_t addr)
+{
+    return qtest_read(s, "readb", addr);
+}
+
+uint16_t qtest_readw(QTestState *s, uint64_t addr)
+{
+    return qtest_read(s, "readw", addr);
+}
+
+uint32_t qtest_readl(QTestState *s, uint64_t addr)
+{
+    return qtest_read(s, "readl", addr);
+}
+
+uint64_t qtest_readq(QTestState *s, uint64_t addr)
+{
+    return qtest_read(s, "readq", addr);
+}
+
 static int hex2nib(char ch)
 {
     if (ch >= '0' && ch <= '9') {
diff --git a/tests/libqtest.h b/tests/libqtest.h
index c8ade85..4cdaaef 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -135,6 +135,22 @@  uint16_t qtest_inw(QTestState *s, uint16_t addr);
  */
 uint32_t qtest_inl(QTestState *s, uint16_t addr);
 
+void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
+
+void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
+
+void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
+
+void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
+
+uint8_t qtest_readb(QTestState *s, uint64_t addr);
+
+uint16_t qtest_readw(QTestState *s, uint64_t addr);
+
+uint32_t qtest_readl(QTestState *s, uint64_t addr);
+
+uint64_t qtest_readq(QTestState *s, uint64_t addr);
+
 /**
  * qtest_memread:
  * @s: QTestState instance to operate on.
@@ -303,6 +319,46 @@  void qtest_add_func(const char *str, void (*fn));
  */
 #define inl(addr) qtest_inl(global_qtest, addr)
 
+static inline void writeb(uint64_t addr, uint8_t value)
+{
+    qtest_writeb(global_qtest, addr, value);
+}
+
+static inline void writew(uint64_t addr, uint16_t value)
+{
+    qtest_writew(global_qtest, addr, value);
+}
+
+static inline void writel(uint64_t addr, uint32_t value)
+{
+    qtest_writel(global_qtest, addr, value);
+}
+
+static inline void writeq(uint64_t addr, uint64_t value)
+{
+    qtest_writeq(global_qtest, addr, value);
+}
+
+static inline uint8_t readb(uint64_t addr)
+{
+    return qtest_readb(global_qtest, addr);
+}
+
+static inline uint16_t readw(uint64_t addr)
+{
+    return qtest_readw(global_qtest, addr);
+}
+
+static inline uint32_t readl(uint64_t addr)
+{
+    return qtest_readl(global_qtest, addr);
+}
+
+static inline uint64_t readq(uint64_t addr)
+{
+    return qtest_readq(global_qtest, addr);
+}
+
 /**
  * memread:
  * @addr: Guest address to read from.