diff mbox series

[2/3] display/edid: add region helper.

Message ID 20180912123700.7708-2-kraxel@redhat.com
State New
Headers show
Series None | expand

Commit Message

Gerd Hoffmann Sept. 12, 2018, 12:36 p.m. UTC
Create a io region for an EDID data block.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/hw/display/edid.h |  4 ++++
 hw/display/edid-region.c  | 33 +++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs  |  1 +
 3 files changed, 38 insertions(+)
 create mode 100644 hw/display/edid-region.c

Comments

Philippe Mathieu-Daudé Sept. 13, 2018, 9:05 p.m. UTC | #1
On 9/12/18 2:36 PM, Gerd Hoffmann wrote:
> Create a io region for an EDID data block.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  include/hw/display/edid.h |  4 ++++
>  hw/display/edid-region.c  | 33 +++++++++++++++++++++++++++++++++
>  hw/display/Makefile.objs  |  1 +
>  3 files changed, 38 insertions(+)
>  create mode 100644 hw/display/edid-region.c
> 
> diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h
> index 63b60015c3..c39d5cd77b 100644
> --- a/include/hw/display/edid.h
> +++ b/include/hw/display/edid.h
> @@ -1,6 +1,8 @@
>  #ifndef EDID_H
>  #define EDID_H
>  
> +#include "hw/hw.h"
> +
>  typedef struct qemu_edid_info {
>      const char *vendor;
>      const char *name;
> @@ -14,5 +16,7 @@ typedef struct qemu_edid_info {
>  
>  void qemu_edid_generate(uint8_t *edid, size_t size,
>                          qemu_edid_info *info);
> +void qemu_edid_region_io(MemoryRegion *region, Object *owner,
> +                         uint8_t *edid, size_t size);
>  
>  #endif /* EDID_H */
> diff --git a/hw/display/edid-region.c b/hw/display/edid-region.c
> new file mode 100644
> index 0000000000..9a15734d3a
> --- /dev/null
> +++ b/hw/display/edid-region.c
> @@ -0,0 +1,33 @@
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "hw/display/edid.h"
> +
> +static uint64_t edid_region_read(void *ptr, hwaddr addr, unsigned size)
> +{
> +    uint8_t *edid = ptr;
> +
> +    return edid[addr];
> +}
> +
> +static void edid_region_write(void *ptr, hwaddr addr,
> +                             uint64_t val, unsigned size)
> +{
> +    /* read only */
> +}
> +
> +static const MemoryRegionOps edid_region_ops = {
> +    .read = edid_region_read,
> +    .write = edid_region_write,
> +    .valid.min_access_size = 1,
> +    .valid.max_access_size = 4,
> +    .impl.min_access_size = 1,
> +    .impl.max_access_size = 1,
> +    .endianness = DEVICE_LITTLE_ENDIAN,
> +};
> +
> +void qemu_edid_region_io(MemoryRegion *region, Object *owner,
> +                         uint8_t *edid, size_t size)
> +{
> +    memory_region_init_io(region, owner, &edid_region_ops,
> +                          edid, "edid", size);
> +}
> diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
> index 492404c09e..780a76b9f0 100644
> --- a/hw/display/Makefile.objs
> +++ b/hw/display/Makefile.objs
> @@ -15,6 +15,7 @@ common-obj-$(CONFIG_XEN) += xenfb.o
>  
>  common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
>  common-obj-$(CONFIG_VGA_PCI) += bochs-display.o
> +common-obj-$(CONFIG_VGA_PCI) += edid-region.o
>  common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
>  common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
>  common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
>
diff mbox series

Patch

diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h
index 63b60015c3..c39d5cd77b 100644
--- a/include/hw/display/edid.h
+++ b/include/hw/display/edid.h
@@ -1,6 +1,8 @@ 
 #ifndef EDID_H
 #define EDID_H
 
+#include "hw/hw.h"
+
 typedef struct qemu_edid_info {
     const char *vendor;
     const char *name;
@@ -14,5 +16,7 @@  typedef struct qemu_edid_info {
 
 void qemu_edid_generate(uint8_t *edid, size_t size,
                         qemu_edid_info *info);
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size);
 
 #endif /* EDID_H */
diff --git a/hw/display/edid-region.c b/hw/display/edid-region.c
new file mode 100644
index 0000000000..9a15734d3a
--- /dev/null
+++ b/hw/display/edid-region.c
@@ -0,0 +1,33 @@ 
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/display/edid.h"
+
+static uint64_t edid_region_read(void *ptr, hwaddr addr, unsigned size)
+{
+    uint8_t *edid = ptr;
+
+    return edid[addr];
+}
+
+static void edid_region_write(void *ptr, hwaddr addr,
+                             uint64_t val, unsigned size)
+{
+    /* read only */
+}
+
+static const MemoryRegionOps edid_region_ops = {
+    .read = edid_region_read,
+    .write = edid_region_write,
+    .valid.min_access_size = 1,
+    .valid.max_access_size = 4,
+    .impl.min_access_size = 1,
+    .impl.max_access_size = 1,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size)
+{
+    memory_region_init_io(region, owner, &edid_region_ops,
+                          edid, "edid", size);
+}
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 492404c09e..780a76b9f0 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -15,6 +15,7 @@  common-obj-$(CONFIG_XEN) += xenfb.o
 
 common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
 common-obj-$(CONFIG_VGA_PCI) += bochs-display.o
+common-obj-$(CONFIG_VGA_PCI) += edid-region.o
 common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
 common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
 common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o