Patchwork [v3,09/39] cirrus: simplify linear framebuffer access functions

login
register
mail settings
Submitter Avi Kivity
Date Aug. 4, 2011, 1:06 p.m.
Message ID <1312463195-13605-10-git-send-email-avi@redhat.com>
Download mbox | patch
Permalink /patch/108482/
State New
Headers show

Comments

Avi Kivity - Aug. 4, 2011, 1:06 p.m.
Make use of the memory API's ability to satisfy multi-byte accesses via
multiple single-byte accesses.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 hw/cirrus_vga.c |   74 ++++++-------------------------------------------------
 1 files changed, 8 insertions(+), 66 deletions(-)
Anthony Liguori - Aug. 5, 2011, 2:11 p.m.
On 08/04/2011 08:06 AM, Avi Kivity wrote:
> Make use of the memory API's ability to satisfy multi-byte accesses via
> multiple single-byte accesses.
>
> Reviewed-by: Richard Henderson<rth@twiddle.net>
> Signed-off-by: Avi Kivity<avi@redhat.com>

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

Regards,

Anthony Liguori

> ---
>   hw/cirrus_vga.c |   74 ++++++-------------------------------------------------
>   1 files changed, 8 insertions(+), 66 deletions(-)
>
> diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
> index 3db15bf..15ccf4a 100644
> --- a/hw/cirrus_vga.c
> +++ b/hw/cirrus_vga.c
> @@ -2249,7 +2249,8 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
>    *
>    ***************************************/
>
> -static uint32_t cirrus_linear_readb(void *opaque, target_phys_addr_t addr)
> +static uint64_t cirrus_linear_read(void *opaque, target_phys_addr_t addr,
> +                                   unsigned size)
>   {
>       CirrusVGAState *s = opaque;
>       uint32_t ret;
> @@ -2277,28 +2278,8 @@ static uint32_t cirrus_linear_readb(void *opaque, target_phys_addr_t addr)
>       return ret;
>   }
>
> -static uint32_t cirrus_linear_readw(void *opaque, target_phys_addr_t addr)
> -{
> -    uint32_t v;
> -
> -    v = cirrus_linear_readb(opaque, addr);
> -    v |= cirrus_linear_readb(opaque, addr + 1)<<  8;
> -    return v;
> -}
> -
> -static uint32_t cirrus_linear_readl(void *opaque, target_phys_addr_t addr)
> -{
> -    uint32_t v;
> -
> -    v = cirrus_linear_readb(opaque, addr);
> -    v |= cirrus_linear_readb(opaque, addr + 1)<<  8;
> -    v |= cirrus_linear_readb(opaque, addr + 2)<<  16;
> -    v |= cirrus_linear_readb(opaque, addr + 3)<<  24;
> -    return v;
> -}
> -
> -static void cirrus_linear_writeb(void *opaque, target_phys_addr_t addr,
> -				 uint32_t val)
> +static void cirrus_linear_write(void *opaque, target_phys_addr_t addr,
> +                                uint64_t val, unsigned size)
>   {
>       CirrusVGAState *s = opaque;
>       unsigned mode;
> @@ -2338,49 +2319,6 @@ static void cirrus_linear_writeb(void *opaque, target_phys_addr_t addr,
>       }
>   }
>
> -static void cirrus_linear_writew(void *opaque, target_phys_addr_t addr,
> -				 uint32_t val)
> -{
> -    cirrus_linear_writeb(opaque, addr, val&  0xff);
> -    cirrus_linear_writeb(opaque, addr + 1, (val>>  8)&  0xff);
> -}
> -
> -static void cirrus_linear_writel(void *opaque, target_phys_addr_t addr,
> -				 uint32_t val)
> -{
> -    cirrus_linear_writeb(opaque, addr, val&  0xff);
> -    cirrus_linear_writeb(opaque, addr + 1, (val>>  8)&  0xff);
> -    cirrus_linear_writeb(opaque, addr + 2, (val>>  16)&  0xff);
> -    cirrus_linear_writeb(opaque, addr + 3, (val>>  24)&  0xff);
> -}
> -
> -
> -static uint64_t cirrus_linear_read(void *opaque, target_phys_addr_t addr,
> -                                   unsigned size)
> -{
> -    CirrusVGAState *s = opaque;
> -
> -    switch (size) {
> -    case 1: return cirrus_linear_readb(s, addr);
> -    case 2: return cirrus_linear_readw(s, addr);
> -    case 4: return cirrus_linear_readl(s, addr);
> -    default: abort();
> -    }
> -}
> -
> -static void cirrus_linear_write(void *opaque, target_phys_addr_t addr,
> -                                uint64_t data, unsigned size)
> -{
> -    CirrusVGAState *s = opaque;
> -
> -    switch (size) {
> -    case 1: return cirrus_linear_writeb(s, addr, data);
> -    case 2: return cirrus_linear_writew(s, addr, data);
> -    case 4: return cirrus_linear_writel(s, addr, data);
> -    default: abort();
> -    }
> -}
> -
>   /***************************************
>    *
>    *  system to screen memory access
> @@ -2860,6 +2798,10 @@ static const MemoryRegionOps cirrus_linear_io_ops = {
>       .read = cirrus_linear_read,
>       .write = cirrus_linear_write,
>       .endianness = DEVICE_LITTLE_ENDIAN,
> +    .impl = {
> +        .min_access_size = 1,
> +        .max_access_size = 1,
> +    },
>   };
>
>   static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)

Patch

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 3db15bf..15ccf4a 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2249,7 +2249,8 @@  static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
  *
  ***************************************/
 
-static uint32_t cirrus_linear_readb(void *opaque, target_phys_addr_t addr)
+static uint64_t cirrus_linear_read(void *opaque, target_phys_addr_t addr,
+                                   unsigned size)
 {
     CirrusVGAState *s = opaque;
     uint32_t ret;
@@ -2277,28 +2278,8 @@  static uint32_t cirrus_linear_readb(void *opaque, target_phys_addr_t addr)
     return ret;
 }
 
-static uint32_t cirrus_linear_readw(void *opaque, target_phys_addr_t addr)
-{
-    uint32_t v;
-
-    v = cirrus_linear_readb(opaque, addr);
-    v |= cirrus_linear_readb(opaque, addr + 1) << 8;
-    return v;
-}
-
-static uint32_t cirrus_linear_readl(void *opaque, target_phys_addr_t addr)
-{
-    uint32_t v;
-
-    v = cirrus_linear_readb(opaque, addr);
-    v |= cirrus_linear_readb(opaque, addr + 1) << 8;
-    v |= cirrus_linear_readb(opaque, addr + 2) << 16;
-    v |= cirrus_linear_readb(opaque, addr + 3) << 24;
-    return v;
-}
-
-static void cirrus_linear_writeb(void *opaque, target_phys_addr_t addr,
-				 uint32_t val)
+static void cirrus_linear_write(void *opaque, target_phys_addr_t addr,
+                                uint64_t val, unsigned size)
 {
     CirrusVGAState *s = opaque;
     unsigned mode;
@@ -2338,49 +2319,6 @@  static void cirrus_linear_writeb(void *opaque, target_phys_addr_t addr,
     }
 }
 
-static void cirrus_linear_writew(void *opaque, target_phys_addr_t addr,
-				 uint32_t val)
-{
-    cirrus_linear_writeb(opaque, addr, val & 0xff);
-    cirrus_linear_writeb(opaque, addr + 1, (val >> 8) & 0xff);
-}
-
-static void cirrus_linear_writel(void *opaque, target_phys_addr_t addr,
-				 uint32_t val)
-{
-    cirrus_linear_writeb(opaque, addr, val & 0xff);
-    cirrus_linear_writeb(opaque, addr + 1, (val >> 8) & 0xff);
-    cirrus_linear_writeb(opaque, addr + 2, (val >> 16) & 0xff);
-    cirrus_linear_writeb(opaque, addr + 3, (val >> 24) & 0xff);
-}
-
-
-static uint64_t cirrus_linear_read(void *opaque, target_phys_addr_t addr,
-                                   unsigned size)
-{
-    CirrusVGAState *s = opaque;
-
-    switch (size) {
-    case 1: return cirrus_linear_readb(s, addr);
-    case 2: return cirrus_linear_readw(s, addr);
-    case 4: return cirrus_linear_readl(s, addr);
-    default: abort();
-    }
-}
-
-static void cirrus_linear_write(void *opaque, target_phys_addr_t addr,
-                                uint64_t data, unsigned size)
-{
-    CirrusVGAState *s = opaque;
-
-    switch (size) {
-    case 1: return cirrus_linear_writeb(s, addr, data);
-    case 2: return cirrus_linear_writew(s, addr, data);
-    case 4: return cirrus_linear_writel(s, addr, data);
-    default: abort();
-    }
-}
-
 /***************************************
  *
  *  system to screen memory access
@@ -2860,6 +2798,10 @@  static const MemoryRegionOps cirrus_linear_io_ops = {
     .read = cirrus_linear_read,
     .write = cirrus_linear_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
 };
 
 static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)