Skip to contentSkip to conversation

Allwinner A10 input/output peripherals

RFC PATCH In review Strahinja Jankovic 3 participants 11 messages Sep 5, 2023 – Sep 16, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Allwinner A10 input/output peripherals

This patch set adds minimal support for PS2 input and HDMI output for Allwinner A10 and Cubieboard.

For the display part, minimal emulation of HDMI, MALI GPU, Display Engine Backend and LCD controller is added.

For the PS2 both keyboard and mouse support is added and attached to the two PS2 contollers present in Allwinner A10.

Functionality has been tested with custom Yocto image.

This is sent as RFC for now, since there might be some use cases which have not been tested.

Strahinja Jankovic (5):
hw/display: Allwinner A10 HDMI controller emulation hw/display: Allwinner basic MALI GPU emulation hw/display: Allwinner A10 Display Engine Backend emulation hw/display: Allwinner A10 LCDC emulation hw/input: Add Allwinner-A10 PS2 emulation

 hw/arm/allwinner-a10.c                  |  51 ++++
 hw/display/allwinner-a10-debe.c         | 229 ++++++++++++++++
 hw/display/allwinner-a10-hdmi.c         | 214 +++++++++++++++
 hw/display/allwinner-a10-lcdc.c         | 275 +++++++++++++++++++
 hw/display/allwinner-gpu.c              | 212 +++++++++++++++
 hw/display/meson.build                  |   5 +
 hw/display/trace-events                 |  17 ++
 hw/input/allwinner-a10-ps2.c            | 345 ++++++++++++++++++++++++
 hw/input/meson.build                    |   2 +
 include/hw/arm/allwinner-a10.h          |  11 +
 include/hw/display/allwinner-a10-debe.h |  71 +++++
 include/hw/display/allwinner-a10-hdmi.h |  69 +++++
 include/hw/display/allwinner-a10-lcdc.h |  77 ++++++
 include/hw/display/allwinner-gpu.h      |  64 +++++
 include/hw/input/allwinner-a10-ps2.h    |  96 +++++++
 15 files changed, 1738 insertions(+)
 create mode 100644 hw/display/allwinner-a10-debe.c
 create mode 100644 hw/display/allwinner-a10-hdmi.c
 create mode 100644 hw/display/allwinner-a10-lcdc.c
 create mode 100644 hw/display/allwinner-gpu.c
 create mode 100644 hw/input/allwinner-a10-ps2.c
 create mode 100644 include/hw/display/allwinner-a10-debe.h
 create mode 100644 include/hw/display/allwinner-a10-hdmi.h
 create mode 100644 include/hw/display/allwinner-a10-lcdc.h
 create mode 100644 include/hw/display/allwinner-gpu.h
 create mode 100644 include/hw/input/allwinner-a10-ps2.h
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH 1/5 hw/display: Allwinner A10 HDMI controller emulation

This patch adds basic Allwinner A10 HDMI controller support. Emulated HDMI component will always show that a display is connected and provide default EDID info.

---
 hw/arm/allwinner-a10.c                  |   7 +
 hw/display/allwinner-a10-hdmi.c         | 214 ++++++++++++++++++++++++
 hw/display/meson.build                  |   2 +
 hw/display/trace-events                 |   4 +
 include/hw/arm/allwinner-a10.h          |   2 +
 include/hw/display/allwinner-a10-hdmi.h |  69 ++++++++
 6 files changed, 298 insertions(+)
 create mode 100644 hw/display/allwinner-a10-hdmi.c
 create mode 100644 include/hw/display/allwinner-a10-hdmi.h
hw/arm/allwinner-a10.c +7 -0
index b0ea3f7f66..2351d1a69b 100644
@@ -41,6 +41,7 @@
 #define AW_A10_WDT_BASE         0x01c20c90
 #define AW_A10_RTC_BASE         0x01c20d00
 #define AW_A10_I2C0_BASE        0x01c2ac00
+#define AW_A10_HDMI_BASE        0x01c16000
 
 void allwinner_a10_bootrom_setup(AwA10State *s, BlockBackend *blk)
 {
@@ -95,6 +96,8 @@ static void aw_a10_init(Object *obj)
     object_initialize_child(obj, "rtc", &s->rtc, TYPE_AW_RTC_SUN4I);
 
     object_initialize_child(obj, "wdt", &s->wdt, TYPE_AW_WDT_SUN4I);
+
+    object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
 }
 
 static void aw_a10_realize(DeviceState *dev, Error **errp)
@@ -210,6 +213,10 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     /* WDT */
     sysbus_realize(SYS_BUS_DEVICE(&s->wdt), &error_fatal);
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->wdt), 0, AW_A10_WDT_BASE, 1);
+
+    /* HDMI */
+    sysbus_realize(SYS_BUS_DEVICE(&s->hdmi), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->hdmi), 0, AW_A10_HDMI_BASE);
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
hw/display/allwinner-a10-hdmi.c new file +214 -0

214 lines not on this page · raw message

hw/display/meson.build +2 -0
index 413ba4ab24..0a36c3ed85 100644
@@ -38,6 +38,8 @@ system_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-fb.c'))
 
 system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c'))
 
+system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-hdmi.c')
+
 if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or
     config_all_devices.has_key('CONFIG_VGA_PCI') or
     config_all_devices.has_key('CONFIG_VMWARE_VGA') or
hw/display/trace-events +4 -0
index 2336a0ca15..8d0d33ce4d 100644
@@ -177,3 +177,7 @@ macfb_ctrl_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%"PRI
 macfb_sense_read(uint32_t value) "video sense: 0x%"PRIx32
 macfb_sense_write(uint32_t value) "video sense: 0x%"PRIx32
 macfb_update_mode(uint32_t width, uint32_t height, uint8_t depth) "setting mode to width %"PRId32 " height %"PRId32 " size %d"
+
+# allwinner-a10-hdmi.c
+allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
include/hw/arm/allwinner-a10.h +2 -0
index cd1465c613..db8cbeecfa 100644
@@ -12,6 +12,7 @@
 #include "hw/rtc/allwinner-rtc.h"
 #include "hw/misc/allwinner-a10-ccm.h"
 #include "hw/misc/allwinner-a10-dramc.h"
+#include "hw/display/allwinner-a10-hdmi.h"
 #include "hw/i2c/allwinner-i2c.h"
 #include "hw/watchdog/allwinner-wdt.h"
 #include "sysemu/block-backend.h"
@@ -43,6 +44,7 @@ struct AwA10State {
     AWI2CState i2c0;
     AwRtcState rtc;
     AwWdtState wdt;
+    AwA10HdmiState hdmi;
     MemoryRegion sram_a;
     EHCISysBusState ehci[AW_A10_NUM_USB];
     OHCISysBusState ohci[AW_A10_NUM_USB];
include/hw/display/allwinner-a10-hdmi.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [RFC Patch 1/5] hw/display: Allwinner A10 HDMI controller emulation

Hi Strahinja,

Quoted 56 lines · Strahinja Jankovic

This patch adds basic Allwinner A10 HDMI controller support. Emulated HDMI component will always show that a display is connected and provide default EDID info.

---
  hw/arm/allwinner-a10.c                  |   7 +
  hw/display/allwinner-a10-hdmi.c         | 214 ++++++++++++++++++++++++
  hw/display/meson.build                  |   2 +
  hw/display/trace-events                 |   4 +
  include/hw/arm/allwinner-a10.h          |   2 +
  include/hw/display/allwinner-a10-hdmi.h |  69 ++++++++
  6 files changed, 298 insertions(+)

create mode 100644 hw/display/allwinner-a10-hdmi.c create mode 100644 include/hw/display/allwinner-a10-hdmi.h

hw/display/allwinner-a10-hdmi.c new file +28 -0
new file mode 100644
index 0000000000..0f046e3cc7
 
 
+#define REG_INDEX(offset)    (offset / sizeof(uint32_t))
+
+static uint64_t allwinner_a10_hdmi_read(void *opaque, hwaddr offset,
+                                       unsigned size)
+{
+    AwA10HdmiState *s = AW_A10_HDMI(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+    uint32_t val = s->regs[idx];
+
+    switch (offset) {
+    case REG_HPD:
+        val = FIELD_HPD_HOTPLUG_DET_HIGH;
+        break;
 
 
+}
+
+static void allwinner_a10_hdmi_write(void *opaque, hwaddr offset,
+                                   uint64_t val, unsigned size)
+{
+    AwA10HdmiState *s = AW_A10_HDMI(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+
+    switch (offset) {
+    case REG_DDC_CTRL:
+        if (val & FIELD_DDC_CTRL_SW_RST) {
+            val &= ~FIELD_DDC_CTRL_SW_RST;
+        }
 
 
+    s->regs[idx] = (uint32_t) val;
+}

hw/display/allwinner-a10-hdmi.c line 152

Quoted 10 lines
hw/display/allwinner-a10-hdmi.c new file +10 -0
+
+static const MemoryRegionOps allwinner_a10_hdmi_ops = {
+    .read = allwinner_a10_hdmi_read,
+    .write = allwinner_a10_hdmi_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+    .impl.min_access_size = 1,

Per REG_INDEX() you have .impl.min/max = 4.

Otherwise your patch LGTM :)

Quoted 1 line

+};

#3 lore raw

RFC PATCH 2/5 hw/display: Allwinner basic MALI GPU emulation

In reply to Strahinja Jankovic

This patch adds minimal MALI GPU emulation needed so emulated system thinks GPU is working.

---
 hw/arm/allwinner-a10.c             |   7 +
 hw/display/allwinner-gpu.c         | 212 +++++++++++++++++++++++++++++
 hw/display/meson.build             |   3 +-
 hw/display/trace-events            |   4 +
 include/hw/arm/allwinner-a10.h     |   2 +
 include/hw/display/allwinner-gpu.h |  64 +++++++++
 6 files changed, 291 insertions(+), 1 deletion(-)
 create mode 100644 hw/display/allwinner-gpu.c
 create mode 100644 include/hw/display/allwinner-gpu.h
hw/arm/allwinner-a10.c +7 -0
index 2351d1a69b..75cd879d24 100644
@@ -42,6 +42,7 @@
 #define AW_A10_RTC_BASE         0x01c20d00
 #define AW_A10_I2C0_BASE        0x01c2ac00
 #define AW_A10_HDMI_BASE        0x01c16000
+#define AW_A10_GPU_BASE         0x01c40000
 
 void allwinner_a10_bootrom_setup(AwA10State *s, BlockBackend *blk)
 {
@@ -98,6 +99,8 @@ static void aw_a10_init(Object *obj)
     object_initialize_child(obj, "wdt", &s->wdt, TYPE_AW_WDT_SUN4I);
 
     object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
+
+    object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);
 }
 
 static void aw_a10_realize(DeviceState *dev, Error **errp)
@@ -217,6 +220,10 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     /* HDMI */
     sysbus_realize(SYS_BUS_DEVICE(&s->hdmi), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->hdmi), 0, AW_A10_HDMI_BASE);
+
+    /* MALI GPU */
+    sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
hw/display/allwinner-gpu.c new file +212 -0

212 lines not on this page · raw message

hw/display/meson.build +2 -1
index 0a36c3ed85..a5eb01fe2b 100644
@@ -38,7 +38,8 @@ system_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-fb.c'))
 
 system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c'))
 
-system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-hdmi.c')
+system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-hdmi.c',
+                                                           'allwinner-gpu.c'))
 
 if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or
     config_all_devices.has_key('CONFIG_VGA_PCI') or
hw/display/trace-events +4 -0
index 8d0d33ce4d..d1c0f05e52 100644
@@ -181,3 +181,7 @@ macfb_update_mode(uint32_t width, uint32_t height, uint8_t depth) "setting mode
 # allwinner-a10-hdmi.c
 allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
 allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
+
+# allwinner-gpu.c
+allwinner_gpu_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_gpu_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
include/hw/arm/allwinner-a10.h +2 -0
index db8cbeecfa..8109656421 100644
@@ -13,6 +13,7 @@
 #include "hw/misc/allwinner-a10-ccm.h"
 #include "hw/misc/allwinner-a10-dramc.h"
 #include "hw/display/allwinner-a10-hdmi.h"
+#include "hw/display/allwinner-gpu.h"
 #include "hw/i2c/allwinner-i2c.h"
 #include "hw/watchdog/allwinner-wdt.h"
 #include "sysemu/block-backend.h"
@@ -44,6 +45,7 @@ struct AwA10State {
     AWI2CState i2c0;
     AwRtcState rtc;
     AwWdtState wdt;
+    AwGpuState gpu;
     AwA10HdmiState hdmi;
     MemoryRegion sram_a;
     EHCISysBusState ehci[AW_A10_NUM_USB];
include/hw/display/allwinner-gpu.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

RFC PATCH 3/5 hw/display: Allwinner A10 Display Engine Backend emulation

In reply to Strahinja Jankovic

This patch adds Display Engine Backend 0 (DEBE0) support. This peripheral will hold runtime configuration for the display size and framebuffer offset which will be used by other components.

---
 hw/arm/allwinner-a10.c                  |   9 +
 hw/display/allwinner-a10-debe.c         | 229 ++++++++++++++++++++++++
 hw/display/meson.build                  |   3 +-
 hw/display/trace-events                 |   4 +
 include/hw/arm/allwinner-a10.h          |   2 +
 include/hw/display/allwinner-a10-debe.h |  71 ++++++++
 6 files changed, 317 insertions(+), 1 deletion(-)
 create mode 100644 hw/display/allwinner-a10-debe.c
 create mode 100644 include/hw/display/allwinner-a10-debe.h
hw/arm/allwinner-a10.c +9 -0
index 75cd879d24..624e95af46 100644
@@ -43,6 +43,7 @@
 #define AW_A10_I2C0_BASE        0x01c2ac00
 #define AW_A10_HDMI_BASE        0x01c16000
 #define AW_A10_GPU_BASE         0x01c40000
+#define AW_A10_DE_BE0_BASE      0x01e60000
 
 void allwinner_a10_bootrom_setup(AwA10State *s, BlockBackend *blk)
 {
@@ -100,6 +101,8 @@ static void aw_a10_init(Object *obj)
 
     object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
 
+    object_initialize_child(obj, "de_be0", &s->de_be0, TYPE_AW_A10_DEBE);
+
     object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);
 }
 
@@ -221,6 +224,12 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_realize(SYS_BUS_DEVICE(&s->hdmi), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->hdmi), 0, AW_A10_HDMI_BASE);
 
+    /* Display Engine Backend */
+    object_property_set_uint(OBJECT(&s->de_be0), "ram-base",
+                             AW_A10_SDRAM_BASE, &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(&s->de_be0), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->de_be0), 0, AW_A10_DE_BE0_BASE);
+
     /* MALI GPU */
     sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
hw/display/allwinner-a10-debe.c new file +229 -0

229 lines not on this page · raw message

hw/display/meson.build +2 -1
index a5eb01fe2b..a3ef580b1c 100644
@@ -38,7 +38,8 @@ system_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('next-fb.c'))
 
 system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c'))
 
-system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-hdmi.c',
+system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-debe.c',
+                                                           'allwinner-a10-hdmi.c',
                                                            'allwinner-gpu.c'))
 
 if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or
hw/display/trace-events +4 -0
index d1c0f05e52..132b66fc81 100644
@@ -178,6 +178,10 @@ macfb_sense_read(uint32_t value) "video sense: 0x%"PRIx32
 macfb_sense_write(uint32_t value) "video sense: 0x%"PRIx32
 macfb_update_mode(uint32_t width, uint32_t height, uint8_t depth) "setting mode to width %"PRId32 " height %"PRId32 " size %d"
 
+# allwinner-a10-debe.c
+allwinner_a10_debe_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_debe_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
+
 # allwinner-a10-hdmi.c
 allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
 allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
include/hw/arm/allwinner-a10.h +2 -0
index 8109656421..2de7e402b2 100644
@@ -12,6 +12,7 @@
 #include "hw/rtc/allwinner-rtc.h"
 #include "hw/misc/allwinner-a10-ccm.h"
 #include "hw/misc/allwinner-a10-dramc.h"
+#include "hw/display/allwinner-a10-debe.h"
 #include "hw/display/allwinner-a10-hdmi.h"
 #include "hw/display/allwinner-gpu.h"
 #include "hw/i2c/allwinner-i2c.h"
@@ -45,6 +46,7 @@ struct AwA10State {
     AWI2CState i2c0;
     AwRtcState rtc;
     AwWdtState wdt;
+    AwA10DEBEState de_be0;
     AwGpuState gpu;
     AwA10HdmiState hdmi;
     MemoryRegion sram_a;
include/hw/display/allwinner-a10-debe.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

RFC PATCH 4/5 hw/display: Allwinner A10 LCDC emulation

In reply to Strahinja Jankovic

This patch adds support for Allwinner A10 LCD controller. Current emulation supports only RGB32 colorspace and interacts with DEBE0 to obtain framebuffer address and screen size.

---
 hw/arm/allwinner-a10.c                  |  10 +
 hw/display/allwinner-a10-lcdc.c         | 275 ++++++++++++++++++++++++
 hw/display/meson.build                  |   1 +
 hw/display/trace-events                 |   5 +
 include/hw/arm/allwinner-a10.h          |   2 +
 include/hw/display/allwinner-a10-lcdc.h |  77 +++++++
 6 files changed, 370 insertions(+)
 create mode 100644 hw/display/allwinner-a10-lcdc.c
 create mode 100644 include/hw/display/allwinner-a10-lcdc.h
hw/arm/allwinner-a10.c +10 -0
index 624e95af46..f93bc5266d 100644
@@ -41,6 +41,7 @@
 #define AW_A10_WDT_BASE         0x01c20c90
 #define AW_A10_RTC_BASE         0x01c20d00
 #define AW_A10_I2C0_BASE        0x01c2ac00
+#define AW_A10_LCDC0_BASE       0x01c0c000
 #define AW_A10_HDMI_BASE        0x01c16000
 #define AW_A10_GPU_BASE         0x01c40000
 #define AW_A10_DE_BE0_BASE      0x01e60000
@@ -101,6 +102,8 @@ static void aw_a10_init(Object *obj)
 
     object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
 
+    object_initialize_child(obj, "lcd0", &s->lcd0, TYPE_AW_A10_LCDC);
+
     object_initialize_child(obj, "de_be0", &s->de_be0, TYPE_AW_A10_DEBE);
 
     object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);
@@ -230,6 +233,13 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_realize(SYS_BUS_DEVICE(&s->de_be0), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->de_be0), 0, AW_A10_DE_BE0_BASE);
 
+    /* LCD Controller */
+    object_property_set_link(OBJECT(&s->lcd0), "debe",
+                             OBJECT(&s->de_be0), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(&s->lcd0), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->lcd0), 0, AW_A10_LCDC0_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->lcd0), 0, qdev_get_gpio_in(dev, 44));
+
     /* MALI GPU */
     sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
hw/display/allwinner-a10-lcdc.c new file +275 -0

275 lines not on this page · raw message

hw/display/meson.build +1 -0
index a3ef580b1c..e233026fdd 100644
@@ -40,6 +40,7 @@ system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c'))
 
 system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-debe.c',
                                                            'allwinner-a10-hdmi.c',
+                                                           'allwinner-a10-lcdc.c',
                                                            'allwinner-gpu.c'))
 
 if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or
hw/display/trace-events +5 -0
index 132b66fc81..4b962d6eda 100644
@@ -186,6 +186,11 @@ allwinner_a10_debe_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRI
 allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
 allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
 
+# allwinner-a10-lcdc.c
+allwinner_a10_lcdc_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_lcdc_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_draw(uint32_t first, uint32_t last, uint32_t invalidate) "Draw: 0x%x, 0x%x, 0x%x"
+
 # allwinner-gpu.c
 allwinner_gpu_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
 allwinner_gpu_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
include/hw/arm/allwinner-a10.h +2 -0
index 2de7e402b2..c99ca6c1c4 100644
@@ -14,6 +14,7 @@
 #include "hw/misc/allwinner-a10-dramc.h"
 #include "hw/display/allwinner-a10-debe.h"
 #include "hw/display/allwinner-a10-hdmi.h"
+#include "hw/display/allwinner-a10-lcdc.h"
 #include "hw/display/allwinner-gpu.h"
 #include "hw/i2c/allwinner-i2c.h"
 #include "hw/watchdog/allwinner-wdt.h"
@@ -49,6 +50,7 @@ struct AwA10State {
     AwA10DEBEState de_be0;
     AwGpuState gpu;
     AwA10HdmiState hdmi;
+    AwA10LcdcState lcd0;
     MemoryRegion sram_a;
     EHCISysBusState ehci[AW_A10_NUM_USB];
     OHCISysBusState ohci[AW_A10_NUM_USB];
include/hw/display/allwinner-a10-lcdc.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

Re: [RFC Patch 4/5] hw/display: Allwinner A10 LCDC emulation

+Gerd & Marc-André for the ui/fb parts.

Quoted 38 lines · Strahinja Jankovic

This patch adds support for Allwinner A10 LCD controller. Current emulation supports only RGB32 colorspace and interacts with DEBE0 to obtain framebuffer address and screen size.

---
  hw/arm/allwinner-a10.c                  |  10 +
  hw/display/allwinner-a10-lcdc.c         | 275 ++++++++++++++++++++++++
  hw/display/meson.build                  |   1 +
  hw/display/trace-events                 |   5 +
  include/hw/arm/allwinner-a10.h          |   2 +
  include/hw/display/allwinner-a10-lcdc.h |  77 +++++++
  6 files changed, 370 insertions(+)

create mode 100644 hw/display/allwinner-a10-lcdc.c create mode 100644 include/hw/display/allwinner-a10-lcdc.h

hw/arm/allwinner-a10.c +3 -0
index 624e95af46..f93bc5266d 100644
@@ -41,6 +41,7 @@
  #define AW_A10_WDT_BASE         0x01c20c90
  #define AW_A10_RTC_BASE         0x01c20d00
  #define AW_A10_I2C0_BASE        0x01c2ac00
+#define AW_A10_LCDC0_BASE       0x01c0c000
  #define AW_A10_HDMI_BASE        0x01c16000
  #define AW_A10_GPU_BASE         0x01c40000
  #define AW_A10_DE_BE0_BASE      0x01e60000
@@ -101,6 +102,8 @@ static void aw_a10_init(Object *obj)
 
      object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
 
+    object_initialize_child(obj, "lcd0", &s->lcd0, TYPE_AW_A10_LCDC);
+
      object_initialize_child(obj, "de_be0", &s->de_be0, TYPE_AW_A10_DEBE);
 
      object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);

hw/arm/allwinner-a10.c static void aw_a10_realize(DeviceState *dev, Error **errp) · line 238

Quoted 6 lines
hw/arm/allwinner-a10.c +3 -0
@@ -230,6 +233,13 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
      sysbus_realize(SYS_BUS_DEVICE(&s->de_be0), &error_fatal);
      sysbus_mmio_map(SYS_BUS_DEVICE(&s->de_be0), 0, AW_A10_DE_BE0_BASE);
 
+    /* LCD Controller */
+    object_property_set_link(OBJECT(&s->lcd0), "debe",
+                             OBJECT(&s->de_be0), &error_fatal);

IIUC you have LCDC polling DEBE for size update then invalidate, shouldn't be the opposite, LCDC linked to DEBE and DEBE call the LCDC invalidate handler on resize?

Quoted 419 lines
hw/arm/allwinner-a10.c +4 -0
+    sysbus_realize(SYS_BUS_DEVICE(&s->lcd0), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->lcd0), 0, AW_A10_LCDC0_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->lcd0), 0, qdev_get_gpio_in(dev, 44));
+
      /* MALI GPU */
      sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
      sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
hw/display/allwinner-a10-lcdc.c new file +275 -0
new file mode 100644
index 0000000000..8367ac32be
@@ -0,0 +1,275 @@
+/*
+ * Allwinner A10 LCD Control Module emulation
+ *
+ * Copyright (C) 2023 Strahinja Jankovic <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "hw/sysbus.h"
+#include "migration/vmstate.h"
+#include "qemu/log.h"
+#include "hw/qdev-properties.h"
+#include "qemu/module.h"
+#include "hw/display/allwinner-a10-lcdc.h"
+#include "hw/irq.h"
+#include "ui/pixel_ops.h"
+#include "trace.h"
+#include "sysemu/dma.h"
+#include "framebuffer.h"
+
+/* LCDC register offsets */
+enum {
+    REG_TCON_GCTL       = 0x0000, /* TCON Global control register */
+    REG_TCON_GINT0      = 0x0004, /* TCON Global interrupt register 0 */
+};
+
+/* TCON_GCTL register fields */
+#define REG_TCON_GCTL_EN        (1 << 31)
+
+/* TCON_GINT0 register fields */
+#define REG_TCON_GINT0_VB_INT_EN    (1 << 31)
+#define REG_TCON_GINT0_VB_INT_FLAG  (1 << 14)
+
+#define REG_INDEX(offset)    (offset / sizeof(uint32_t))
+
+static void allwinner_a10_lcdc_tick(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+
+    if (s->regs[REG_INDEX(REG_TCON_GINT0)] & REG_TCON_GINT0_VB_INT_EN) {
+        s->regs[REG_INDEX(REG_TCON_GINT0)] |= REG_TCON_GINT0_VB_INT_FLAG;
+        qemu_irq_raise(s->irq);
+    }
+}
+
+static uint64_t allwinner_a10_lcdc_read(void *opaque, hwaddr offset,
+                                       unsigned size)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+    uint32_t val = s->regs[idx];
+
+    switch (offset) {
+    case 0x800 ... AW_A10_LCDC_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
+                  __func__, (uint32_t)offset);
+        return 0;
+    default:
+        break;
+    }
+
+    trace_allwinner_a10_lcdc_read(offset, val);
+
+    return val;
+}
+
+static void allwinner_a10_lcdc_write(void *opaque, hwaddr offset,
+                                   uint64_t val, unsigned size)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+
+    switch (offset) {
+    case REG_TCON_GCTL:
+        s->is_enabled = !!REG_TCON_GCTL_EN;
+        break;
+    case REG_TCON_GINT0:
+        if (0 == (val & REG_TCON_GINT0_VB_INT_FLAG)) {
+            qemu_irq_lower(s->irq);
+        }
+        break;
+    case 0x800 ... AW_A10_LCDC_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
+                  __func__, (uint32_t)offset);
+        break;
+    default:
+        break;
+    }
+
+    trace_allwinner_a10_lcdc_write(offset, (uint32_t)val);
+
+    s->regs[idx] = (uint32_t) val;
+}
+
+static const MemoryRegionOps allwinner_a10_lcdc_ops = {
+    .read = allwinner_a10_lcdc_read,
+    .write = allwinner_a10_lcdc_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+    .impl.min_access_size = 1,
+};
+
+#define COPY_PIXEL(to, from) do { *(uint32_t *)to = from; to += 4; } while (0)
+
+static void draw_line(void *opaque, uint8_t *d, const uint8_t *src,
+                      int width, int deststep)
+{
+    uint32_t data;
+    unsigned int r, g, b;
+    while (width > 0) {
+        data = *(uint32_t *)src;
+        b = data & 0xff;
+        g = (data >> 8) & 0xff;
+        r = (data >> 16) & 0xff;
+        COPY_PIXEL(d, rgb_to_pixel32(r, g, b));
+        width--;
+        src += 4;
+    }
+}
+
+static void allwinner_a10_lcdc_invalidate_display(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    qemu_console_resize(s->con, s->debe->width, s->debe->height);
+    s->invalidate = 1;
+}
+
+static void allwinner_a10_lcdc_update_display(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    DisplaySurface *surface;
+    int step, width, height, linesize, first = 0, last;
+
+    if (!s->is_enabled || !s->debe->ready) {
+        return;
+    }
+
+    width = s->debe->width;
+    height = s->debe->height;
+    step = width * (s->debe->bpp >> 3);
+
+    if (s->debe->invalidate) {
+        allwinner_a10_lcdc_invalidate_display(opaque);
+        s->debe->invalidate = false;
+    }
+
+    surface = qemu_console_surface(s->con);
+    linesize = surface_stride(surface);
+
+    if (s->invalidate) {
+        framebuffer_update_memory_section(&s->fbsection,
+                                    sysbus_address_space(SYS_BUS_DEVICE(s)),
+                                    s->debe->framebuffer_offset,
+                                    height, step);
+    }
+
+    framebuffer_update_display(surface, &s->fbsection,
+                               width, height,
+                               step, linesize, 0,
+                               s->invalidate,
+                               draw_line, NULL,
+                               &first, &last);
+
+    trace_allwinner_a10_draw(first, last, s->invalidate);
+
+    if (first >= 0) {
+        dpy_gfx_update(s->con, 0, first, width, last - first + 1);
+    }
+    s->invalidate = 0;
+
+}
+
+static const GraphicHwOps allwinner_a10_lcdc_gfx_ops = {
+    .invalidate  = allwinner_a10_lcdc_invalidate_display,
+    .gfx_update  = allwinner_a10_lcdc_update_display,
+};
+
+static void allwinner_a10_lcdc_reset_enter(Object *obj, ResetType type)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(obj);
+    s->invalidate = 1;
+}
+
+static void allwinner_a10_lcdc_init(Object *obj)
+{
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+    AwA10LcdcState *s = AW_A10_LCDC(obj);
+
+    /* Memory mapping */
+    memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_a10_lcdc_ops, s,
+                          TYPE_AW_A10_LCDC, AW_A10_LCDC_IOSIZE);
+    sysbus_init_mmio(sbd, &s->iomem);
+    sysbus_init_irq(sbd, &s->irq);
+    s->invalidate = 1;
+    s->is_enabled = 0;
+}
+
+static void allwinner_a10_lcdc_realize(DeviceState *dev, Error **errp)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(dev);
+
+    s->timer = ptimer_init(allwinner_a10_lcdc_tick, s,
+                           PTIMER_POLICY_NO_IMMEDIATE_TRIGGER |
+                           PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
+                           PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
+
+    ptimer_transaction_begin(s->timer);
+    /* Set to 60Hz */
+    ptimer_set_freq(s->timer, 60);
+    ptimer_set_limit(s->timer, 0x1, 1);
+    ptimer_run(s->timer, 0);
+    ptimer_transaction_commit(s->timer);
+
+    s->invalidate = 1;
+    s->con = graphic_console_init(NULL, 0, &allwinner_a10_lcdc_gfx_ops, s);
+    qemu_console_resize(s->con, s->debe->width, s->debe->height);
+}
+
+static const VMStateDescription allwinner_a10_lcdc_vmstate = {
+    .name = "allwinner-a10_lcdc",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, AwA10LcdcState, AW_A10_LCDC_REGS_NUM),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property allwinner_a10_lcdc_properties[] = {
+    DEFINE_PROP_LINK("debe", AwA10LcdcState, debe,
+                     TYPE_AW_A10_DEBE, AwA10DEBEState *),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void allwinner_a10_lcdc_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
+    rc->phases.enter = allwinner_a10_lcdc_reset_enter;
+    dc->vmsd = &allwinner_a10_lcdc_vmstate;
+    dc->realize = allwinner_a10_lcdc_realize;
+    device_class_set_props(dc, allwinner_a10_lcdc_properties);
+}
+
+static const TypeInfo allwinner_a10_lcdc_info = {
+    .name          = TYPE_AW_A10_LCDC,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_init = allwinner_a10_lcdc_init,
+    .instance_size = sizeof(AwA10LcdcState),
+    .class_init    = allwinner_a10_lcdc_class_init,
+};
+
+static void allwinner_a10_lcdc_register(void)
+{
+    type_register_static(&allwinner_a10_lcdc_info);
+}
+
+type_init(allwinner_a10_lcdc_register)
hw/display/meson.build +1 -0
index a3ef580b1c..e233026fdd 100644
@@ -40,6 +40,7 @@ system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c'))
 
  system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-debe.c',
                                                             'allwinner-a10-hdmi.c',
+                                                           'allwinner-a10-lcdc.c',
                                                             'allwinner-gpu.c'))
 
  if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or
hw/display/trace-events +5 -0
index 132b66fc81..4b962d6eda 100644
@@ -186,6 +186,11 @@ allwinner_a10_debe_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRI
  allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
  allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
 
+# allwinner-a10-lcdc.c
+allwinner_a10_lcdc_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_lcdc_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
+allwinner_a10_draw(uint32_t first, uint32_t last, uint32_t invalidate) "Draw: 0x%x, 0x%x, 0x%x"
+
  # allwinner-gpu.c
  allwinner_gpu_read(uint64_t offset, uint64_t data) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64
  allwinner_gpu_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64
include/hw/arm/allwinner-a10.h +2 -0
index 2de7e402b2..c99ca6c1c4 100644
@@ -14,6 +14,7 @@
  #include "hw/misc/allwinner-a10-dramc.h"
  #include "hw/display/allwinner-a10-debe.h"
  #include "hw/display/allwinner-a10-hdmi.h"
+#include "hw/display/allwinner-a10-lcdc.h"
  #include "hw/display/allwinner-gpu.h"
  #include "hw/i2c/allwinner-i2c.h"
  #include "hw/watchdog/allwinner-wdt.h"
@@ -49,6 +50,7 @@ struct AwA10State {
      AwA10DEBEState de_be0;
      AwGpuState gpu;
      AwA10HdmiState hdmi;
+    AwA10LcdcState lcd0;
      MemoryRegion sram_a;
      EHCISysBusState ehci[AW_A10_NUM_USB];
      OHCISysBusState ohci[AW_A10_NUM_USB];
include/hw/display/allwinner-a10-lcdc.h new file +77 -0
new file mode 100644
index 0000000000..82f6d397fb
@@ -0,0 +1,77 @@
+/*
+ * Allwinner A10 LCD Control Module emulation
+ *
+ * Copyright (C) 2023 Strahinja Jankovic <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HW_DISPLAY_ALLWINNER_A10_LCDC_H
+#define HW_DISPLAY_ALLWINNER_A10_LCDC_H
+
+#include "qom/object.h"
+#include "hw/ptimer.h"
+#include "hw/sysbus.h"
+#include "ui/console.h"
+#include "hw/display/allwinner-a10-debe.h"
+
+/**
+ * @name Constants
+ * @{
+ */
+
+/** Size of register I/O address space used by LCDC device */
+#define AW_A10_LCDC_IOSIZE        (0x1000)
+
+/** Total number of known registers */
+#define AW_A10_LCDC_REGS_NUM      (AW_A10_LCDC_IOSIZE / sizeof(uint32_t))
+
+/** @} */
+
+/**
+ * @name Object model
+ * @{
+ */
+
+#define TYPE_AW_A10_LCDC    "allwinner-a10-lcdc"
+OBJECT_DECLARE_SIMPLE_TYPE(AwA10LcdcState, AW_A10_LCDC)
+
+/** @} */
+
+/**
+ * Allwinner A10 LCDC object instance state.
+ */
+struct AwA10LcdcState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+    qemu_irq irq;
+    struct ptimer_state *timer;
+    QemuConsole *con;
+
+    MemoryRegionSection fbsection;
+
+    int invalidate;
+    bool is_enabled;
+
+    AwA10DEBEState *debe;
+
+    /** Maps I/O registers in physical memory */
+    MemoryRegion iomem;
+
+    /** Array of hardware registers */
+    uint32_t regs[AW_A10_LCDC_REGS_NUM];
+};
+
+#endif /* HW_DISPLAY_ALLWINNER_A10_LCDC_H */
#7 lore raw

Re: [RFC Patch 4/5] hw/display: Allwinner A10 LCDC emulation

Hi Philippe,

Thank you for your comment.

Quoted 46 lines · Philippe Mathieu-Daudé

+Gerd & Marc-André for the ui/fb parts.

Quoted 29 lines · Strahinja Jankovic

This patch adds support for Allwinner A10 LCD controller. Current emulation supports only RGB32 colorspace and interacts with DEBE0 to obtain framebuffer address and screen size.

---
  hw/arm/allwinner-a10.c                  |  10 +
  hw/display/allwinner-a10-lcdc.c         | 275 ++++++++++++++++++++++++
  hw/display/meson.build                  |   1 +
  hw/display/trace-events                 |   5 +
  include/hw/arm/allwinner-a10.h          |   2 +
  include/hw/display/allwinner-a10-lcdc.h |  77 +++++++
  6 files changed, 370 insertions(+)

create mode 100644 hw/display/allwinner-a10-lcdc.c create mode 100644 include/hw/display/allwinner-a10-lcdc.h

hw/arm/allwinner-a10.c +1 -0
index 624e95af46..f93bc5266d 100644
@@ -41,6 +41,7 @@
  #define AW_A10_WDT_BASE         0x01c20c90
  #define AW_A10_RTC_BASE         0x01c20d00
  #define AW_A10_I2C0_BASE        0x01c2ac00
+#define AW_A10_LCDC0_BASE       0x01c0c000
  #define AW_A10_HDMI_BASE        0x01c16000
  #define AW_A10_GPU_BASE         0x01c40000
  #define AW_A10_DE_BE0_BASE      0x01e60000

hw/arm/allwinner-a10.c static void aw_a10_init(Object *obj) · line 107

Quoted 6 lines
hw/arm/allwinner-a10.c +2 -0
@@ -101,6 +102,8 @@ static void aw_a10_init(Object *obj)
 
      object_initialize_child(obj, "hdmi", &s->hdmi, TYPE_AW_A10_HDMI);
 
+    object_initialize_child(obj, "lcd0", &s->lcd0, TYPE_AW_A10_LCDC);
+
      object_initialize_child(obj, "de_be0", &s->de_be0,

TYPE_AW_A10_DEBE);

hw/arm/allwinner-a10.c static void aw_a10_realize(DeviceState *dev, Error

Quoted 3 lines
hw/arm/allwinner-a10.c +0 -0
      object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);
@@ -230,6 +233,13 @@ static void aw_a10_realize(DeviceState *dev, Error

**errp)

Quoted 3 lines
hw/arm/allwinner-a10.c +0 -0
      sysbus_realize(SYS_BUS_DEVICE(&s->de_be0), &error_fatal);
      sysbus_mmio_map(SYS_BUS_DEVICE(&s->de_be0), 0, AW_A10_DE_BE0_BASE);
 
Quoted 8 lines

hw/arm/allwinner-a10.c static void aw_a10_realize(DeviceState *dev, Error **errp) · line 238

Quoted 3 lines
hw/arm/allwinner-a10.c +3 -0
+    /* LCD Controller */
+    object_property_set_link(OBJECT(&s->lcd0), "debe",
+                             OBJECT(&s->de_be0), &error_fatal);

IIUC you have LCDC polling DEBE for size update then invalidate, shouldn't be the opposite, LCDC linked to DEBE and DEBE call the LCDC invalidate handler on resize?

I think I understand what you meant. In this case, it was easier to do it this way, since this way only LCDC needs to store a pointer to DEBE, there is no need for storing the pointer the other way around as well. Also the update function should be called frequently, so that should not affect the performance.

If there is another way to implement this behavior, I am open to changing this implementation.

Best regards,
Strahinja

Quoted 452 lines

hw/arm/allwinner-a10.c static void aw_a10_realize(DeviceState *dev, Error **errp)

Quoted 3 lines
hw/arm/allwinner-a10.c +3 -0
+    sysbus_realize(SYS_BUS_DEVICE(&s->lcd0), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->lcd0), 0, AW_A10_LCDC0_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->lcd0), 0,

qdev_get_gpio_in(dev, 44));

Review

Quoted 5 lines
hw/arm/allwinner-a10.c +1 -0
+
      /* MALI GPU */
      sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
      sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
(quoted diff) +0 -0

b/hw/display/allwinner-a10-lcdc.c

hw/display/allwinner-a10-lcdc.c line 4

Quoted 9 lines

new file mode 100644
index 0000000000..8367ac32be

hw/display/allwinner-a10-lcdc.c new file +4 -0
@@ -0,0 +1,275 @@
+/*
+ * Allwinner A10 LCD Control Module emulation
+ *
+ * Copyright (C) 2023 Strahinja Jankovic <

[email protected]>

Quoted 41 lines
hw/display/allwinner-a10-lcdc.c new file +13 -0
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/

.
+ */

hw/display/allwinner-a10-lcdc.c new file +26 -0
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "hw/sysbus.h"
+#include "migration/vmstate.h"
+#include "qemu/log.h"
+#include "hw/qdev-properties.h"
+#include "qemu/module.h"
+#include "hw/display/allwinner-a10-lcdc.h"
+#include "hw/irq.h"
+#include "ui/pixel_ops.h"
+#include "trace.h"
+#include "sysemu/dma.h"
+#include "framebuffer.h"
+
+/* LCDC register offsets */
+enum {
+    REG_TCON_GCTL       = 0x0000, /* TCON Global control register */
+    REG_TCON_GINT0      = 0x0004, /* TCON Global interrupt register 0 */
+};
+
+/* TCON_GCTL register fields */
+#define REG_TCON_GCTL_EN        (1 << 31)
+
+/* TCON_GINT0 register fields */
+#define REG_TCON_GINT0_VB_INT_EN    (1 << 31)

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+#define REG_TCON_GINT0_VB_INT_FLAG  (1 << 14)
+
+#define REG_INDEX(offset)    (offset / sizeof(uint32_t))
+
+static void allwinner_a10_lcdc_tick(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+
+    if (s->regs[REG_INDEX(REG_TCON_GINT0)] & REG_TCON_GINT0_VB_INT_EN) {
+        s->regs[REG_INDEX(REG_TCON_GINT0)] |=

REG_TCON_GINT0_VB_INT_FLAG;

Quoted 4 lines
hw/display/allwinner-a10-lcdc.c new file +4 -0
+        qemu_irq_raise(s->irq);
+    }
+}
+

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+static uint64_t allwinner_a10_lcdc_read(void *opaque, hwaddr offset,
+                                       unsigned size)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+    uint32_t val = s->regs[idx];
+
+    switch (offset) {
+    case 0x800 ... AW_A10_LCDC_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset

0x%04x\n",

Quoted 18 lines
hw/display/allwinner-a10-lcdc.c new file +18 -0
+                  __func__, (uint32_t)offset);
+        return 0;
+    default:
+        break;
+    }
+
+    trace_allwinner_a10_lcdc_read(offset, val);
+
+    return val;
+}
+
+static void allwinner_a10_lcdc_write(void *opaque, hwaddr offset,
+                                   uint64_t val, unsigned size)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+
+    switch (offset) {

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+    case REG_TCON_GCTL:
+        s->is_enabled = !!REG_TCON_GCTL_EN;
+        break;
+    case REG_TCON_GINT0:
+        if (0 == (val & REG_TCON_GINT0_VB_INT_FLAG)) {
+            qemu_irq_lower(s->irq);
+        }
+        break;
+    case 0x800 ... AW_A10_LCDC_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset

0x%04x\n",

Quoted 13 lines
hw/display/allwinner-a10-lcdc.c new file +13 -0
+                  __func__, (uint32_t)offset);
+        break;
+    default:
+        break;
+    }
+
+    trace_allwinner_a10_lcdc_write(offset, (uint32_t)val);
+
+    s->regs[idx] = (uint32_t) val;
+}
+
+static const MemoryRegionOps allwinner_a10_lcdc_ops = {
+    .read = allwinner_a10_lcdc_read,

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+    .write = allwinner_a10_lcdc_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+    .impl.min_access_size = 1,
+};
+
+#define COPY_PIXEL(to, from) do { *(uint32_t *)to = from; to += 4; }

while (0)

Quoted 39 lines
hw/display/allwinner-a10-lcdc.c new file +39 -0
+
+static void draw_line(void *opaque, uint8_t *d, const uint8_t *src,
+                      int width, int deststep)
+{
+    uint32_t data;
+    unsigned int r, g, b;
+    while (width > 0) {
+        data = *(uint32_t *)src;
+        b = data & 0xff;
+        g = (data >> 8) & 0xff;
+        r = (data >> 16) & 0xff;
+        COPY_PIXEL(d, rgb_to_pixel32(r, g, b));
+        width--;
+        src += 4;
+    }
+}
+
+static void allwinner_a10_lcdc_invalidate_display(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    qemu_console_resize(s->con, s->debe->width, s->debe->height);
+    s->invalidate = 1;
+}
+
+static void allwinner_a10_lcdc_update_display(void *opaque)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(opaque);
+    DisplaySurface *surface;
+    int step, width, height, linesize, first = 0, last;
+
+    if (!s->is_enabled || !s->debe->ready) {
+        return;
+    }
+
+    width = s->debe->width;
+    height = s->debe->height;
+    step = width * (s->debe->bpp >> 3);
+
+    if (s->debe->invalidate) {

hw/display/allwinner-a10-lcdc.c line 172

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+        allwinner_a10_lcdc_invalidate_display(opaque);
+        s->debe->invalidate = false;
+    }
+
+    surface = qemu_console_surface(s->con);
+    linesize = surface_stride(surface);
+
+    if (s->invalidate) {
+        framebuffer_update_memory_section(&s->fbsection,
+

sysbus_address_space(SYS_BUS_DEVICE(s)),

Quoted 28 lines
hw/display/allwinner-a10-lcdc.c new file +28 -0
+                                    s->debe->framebuffer_offset,
+                                    height, step);
+    }
+
+    framebuffer_update_display(surface, &s->fbsection,
+                               width, height,
+                               step, linesize, 0,
+                               s->invalidate,
+                               draw_line, NULL,
+                               &first, &last);
+
+    trace_allwinner_a10_draw(first, last, s->invalidate);
+
+    if (first >= 0) {
+        dpy_gfx_update(s->con, 0, first, width, last - first + 1);
+    }
+    s->invalidate = 0;
+
+}
+
+static const GraphicHwOps allwinner_a10_lcdc_gfx_ops = {
+    .invalidate  = allwinner_a10_lcdc_invalidate_display,
+    .gfx_update  = allwinner_a10_lcdc_update_display,
+};
+
+static void allwinner_a10_lcdc_reset_enter(Object *obj, ResetType type)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(obj);

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+    s->invalidate = 1;
+}
+
+static void allwinner_a10_lcdc_init(Object *obj)
+{
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+    AwA10LcdcState *s = AW_A10_LCDC(obj);
+
+    /* Memory mapping */
+    memory_region_init_io(&s->iomem, OBJECT(s),

&allwinner_a10_lcdc_ops, s,

Quoted 15 lines
hw/display/allwinner-a10-lcdc.c new file +15 -0
+                          TYPE_AW_A10_LCDC, AW_A10_LCDC_IOSIZE);
+    sysbus_init_mmio(sbd, &s->iomem);
+    sysbus_init_irq(sbd, &s->irq);
+    s->invalidate = 1;
+    s->is_enabled = 0;
+}
+
+static void allwinner_a10_lcdc_realize(DeviceState *dev, Error **errp)
+{
+    AwA10LcdcState *s = AW_A10_LCDC(dev);
+
+    s->timer = ptimer_init(allwinner_a10_lcdc_tick, s,
+                           PTIMER_POLICY_NO_IMMEDIATE_TRIGGER |
+                           PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
+                           PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);

hw/display/allwinner-a10-lcdc.c

Quoted 10 lines
hw/display/allwinner-a10-lcdc.c new file +10 -0
+
+    ptimer_transaction_begin(s->timer);
+    /* Set to 60Hz */
+    ptimer_set_freq(s->timer, 60);
+    ptimer_set_limit(s->timer, 0x1, 1);
+    ptimer_run(s->timer, 0);
+    ptimer_transaction_commit(s->timer);
+
+    s->invalidate = 1;
+    s->con = graphic_console_init(NULL, 0, &allwinner_a10_lcdc_gfx_ops,

s);

hw/display/allwinner-a10-lcdc.c

Quoted 9 lines
hw/display/allwinner-a10-lcdc.c new file +9 -0
+    qemu_console_resize(s->con, s->debe->width, s->debe->height);
+}
+
+static const VMStateDescription allwinner_a10_lcdc_vmstate = {
+    .name = "allwinner-a10_lcdc",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, AwA10LcdcState,

AW_A10_LCDC_REGS_NUM),

hw/display/allwinner-a10-lcdc.c

Quoted 11 lines
hw/display/allwinner-a10-lcdc.c new file +11 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property allwinner_a10_lcdc_properties[] = {
+    DEFINE_PROP_LINK("debe", AwA10LcdcState, debe,
+                     TYPE_AW_A10_DEBE, AwA10DEBEState *),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void allwinner_a10_lcdc_class_init(ObjectClass *klass, void

*data)

hw/display/meson.build system_ss.add(when: 'CONFIG_VGA', if_true:

Quoted 29 lines
hw/display/allwinner-a10-lcdc.c new file +24 -0
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
+    rc->phases.enter = allwinner_a10_lcdc_reset_enter;
+    dc->vmsd = &allwinner_a10_lcdc_vmstate;
+    dc->realize = allwinner_a10_lcdc_realize;
+    device_class_set_props(dc, allwinner_a10_lcdc_properties);
+}
+
+static const TypeInfo allwinner_a10_lcdc_info = {
+    .name          = TYPE_AW_A10_LCDC,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_init = allwinner_a10_lcdc_init,
+    .instance_size = sizeof(AwA10LcdcState),
+    .class_init    = allwinner_a10_lcdc_class_init,
+};
+
+static void allwinner_a10_lcdc_register(void)
+{
+    type_register_static(&allwinner_a10_lcdc_info);
+}
+
+type_init(allwinner_a10_lcdc_register)
hw/display/meson.build +0 -0
index a3ef580b1c..e233026fdd 100644
@@ -40,6 +40,7 @@ system_ss.add(when: 'CONFIG_VGA', if_true:

files('vga.c'))

hw/display/meson.build system_ss.add(when: 'CONFIG_VGA', if_true: · line 40

Quoted 2 lines
hw/display/meson.build +0 -0
  system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true:

files('allwinner-a10-debe.c',

Quoted 1 line

'allwinner-a10-hdmi.c',

Quoted 1 line

+

'allwinner-a10-lcdc.c',

Quoted 1 line

'allwinner-gpu.c'))

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t

Quoted 7 lines

if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or

hw/display/trace-events +0 -0
index 132b66fc81..4b962d6eda 100644
@@ -186,6 +186,11 @@ allwinner_a10_debe_write(uint64_t offset, uint64_t

data) "Write: offset 0x%" PRI

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 186

Quoted 1 line
hw/display/trace-events +0 -0
  allwinner_a10_hdmi_read(uint64_t offset, uint64_t data) "Read: offset

0x%" PRIx64 " data 0x%" PRIx64

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 187

Quoted 1 line
hw/display/trace-events +0 -0
  allwinner_a10_hdmi_write(uint64_t offset, uint64_t data) "Write:

offset 0x%" PRIx64 " data 0x%" PRIx64

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 189

Quoted 3 lines
hw/display/trace-events +2 -0
+# allwinner-a10-lcdc.c
+allwinner_a10_lcdc_read(uint64_t offset, uint64_t data) "Read: offset

0x%" PRIx64 " data 0x%" PRIx64

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 190

Quoted 1 line
hw/display/trace-events +1 -0
+allwinner_a10_lcdc_write(uint64_t offset, uint64_t data) "Write: offset

0x%" PRIx64 " data 0x%" PRIx64

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 191

Quoted 1 line
hw/display/trace-events +1 -0
+allwinner_a10_draw(uint32_t first, uint32_t last, uint32_t invalidate)

"Draw: 0x%x, 0x%x, 0x%x"

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t data) "Write: offset 0x%" PRI

Quoted 3 lines
hw/display/trace-events +1 -0
+
  # allwinner-gpu.c
  allwinner_gpu_read(uint64_t offset, uint64_t data) "Read: offset 0x%"

PRIx64 " data 0x%" PRIx64

hw/display/trace-events allwinner_a10_debe_write(uint64_t offset, uint64_t · line 195

Quoted 1 line
hw/display/trace-events +0 -0
  allwinner_gpu_write(uint64_t offset, uint64_t data) "Write: offset

0x%" PRIx64 " data 0x%" PRIx64

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/hw/arm/allwinner-a10.h

Review

Quoted 20 lines

index 2de7e402b2..c99ca6c1c4 100644

include/hw/arm/allwinner-a10.h +2 -0
@@ -14,6 +14,7 @@
  #include "hw/misc/allwinner-a10-dramc.h"
  #include "hw/display/allwinner-a10-debe.h"
  #include "hw/display/allwinner-a10-hdmi.h"
+#include "hw/display/allwinner-a10-lcdc.h"
  #include "hw/display/allwinner-gpu.h"
  #include "hw/i2c/allwinner-i2c.h"
  #include "hw/watchdog/allwinner-wdt.h"
@@ -49,6 +50,7 @@ struct AwA10State {
      AwA10DEBEState de_be0;
      AwGpuState gpu;
      AwA10HdmiState hdmi;
+    AwA10LcdcState lcd0;
      MemoryRegion sram_a;
      EHCISysBusState ehci[AW_A10_NUM_USB];
      OHCISysBusState ohci[AW_A10_NUM_USB];
(quoted diff) +0 -0

b/include/hw/display/allwinner-a10-lcdc.h

include/hw/display/allwinner-a10-lcdc.h line 4

Quoted 9 lines

new file mode 100644
index 0000000000..82f6d397fb

include/hw/display/allwinner-a10-lcdc.h new file +4 -0
@@ -0,0 +1,77 @@
+/*
+ * Allwinner A10 LCD Control Module emulation
+ *
+ * Copyright (C) 2023 Strahinja Jankovic <

[email protected]>

Quoted 25 lines
include/hw/display/allwinner-a10-lcdc.h new file +13 -0
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/

.
+ */

include/hw/display/allwinner-a10-lcdc.h new file +10 -0
+
+#ifndef HW_DISPLAY_ALLWINNER_A10_LCDC_H
+#define HW_DISPLAY_ALLWINNER_A10_LCDC_H
+
+#include "qom/object.h"
+#include "hw/ptimer.h"
+#include "hw/sysbus.h"
+#include "ui/console.h"
+#include "hw/display/allwinner-a10-debe.h"
+

include/hw/display/allwinner-a10-lcdc.h

Quoted 10 lines
include/hw/display/allwinner-a10-lcdc.h new file +10 -0
+/**
+ * @name Constants
+ * @{
+ */
+
+/** Size of register I/O address space used by LCDC device */
+#define AW_A10_LCDC_IOSIZE        (0x1000)
+
+/** Total number of known registers */
+#define AW_A10_LCDC_REGS_NUM      (AW_A10_LCDC_IOSIZE /

sizeof(uint32_t))

Quoted 39 lines
include/hw/display/allwinner-a10-lcdc.h new file +39 -0
+
+/** @} */
+
+/**
+ * @name Object model
+ * @{
+ */
+
+#define TYPE_AW_A10_LCDC    "allwinner-a10-lcdc"
+OBJECT_DECLARE_SIMPLE_TYPE(AwA10LcdcState, AW_A10_LCDC)
+
+/** @} */
+
+/**
+ * Allwinner A10 LCDC object instance state.
+ */
+struct AwA10LcdcState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+    qemu_irq irq;
+    struct ptimer_state *timer;
+    QemuConsole *con;
+
+    MemoryRegionSection fbsection;
+
+    int invalidate;
+    bool is_enabled;
+
+    AwA10DEBEState *debe;
+
+    /** Maps I/O registers in physical memory */
+    MemoryRegion iomem;
+
+    /** Array of hardware registers */
+    uint32_t regs[AW_A10_LCDC_REGS_NUM];
+};
+
+#endif /* HW_DISPLAY_ALLWINNER_A10_LCDC_H */
#8 lore raw

RFC PATCH 5/5 hw/input: Add Allwinner-A10 PS2 emulation

In reply to Strahinja Jankovic

Add emulation for PS2-0 and PS2-1 for keyboard/mouse.

---
 hw/arm/allwinner-a10.c               |  18 ++
 hw/input/allwinner-a10-ps2.c         | 345 +++++++++++++++++++++++++++
 hw/input/meson.build                 |   2 +
 include/hw/arm/allwinner-a10.h       |   3 +
 include/hw/input/allwinner-a10-ps2.h |  96 ++++++++
 5 files changed, 464 insertions(+)
 create mode 100644 hw/input/allwinner-a10-ps2.c
 create mode 100644 include/hw/input/allwinner-a10-ps2.h
hw/arm/allwinner-a10.c +18 -0
index f93bc5266d..3d25dbb4e3 100644
@@ -40,6 +40,8 @@
 #define AW_A10_SATA_BASE        0x01c18000
 #define AW_A10_WDT_BASE         0x01c20c90
 #define AW_A10_RTC_BASE         0x01c20d00
+#define AW_A10_PS2_0_BASE       0x01c2a000
+#define AW_A10_PS2_1_BASE       0x01c2a400
 #define AW_A10_I2C0_BASE        0x01c2ac00
 #define AW_A10_LCDC0_BASE       0x01c0c000
 #define AW_A10_HDMI_BASE        0x01c16000
@@ -107,6 +109,12 @@ static void aw_a10_init(Object *obj)
     object_initialize_child(obj, "de_be0", &s->de_be0, TYPE_AW_A10_DEBE);
 
     object_initialize_child(obj, "mali400", &s->gpu, TYPE_AW_GPU);
+
+    object_initialize_child(obj, "keyboard", &s->kbd,
+                            TYPE_AW_A10_PS2_KBD_DEVICE);
+
+    object_initialize_child(obj, "mouse", &s->mouse,
+                            TYPE_AW_A10_PS2_MOUSE_DEVICE);
 }
 
 static void aw_a10_realize(DeviceState *dev, Error **errp)
@@ -243,6 +251,16 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     /* MALI GPU */
     sysbus_realize(SYS_BUS_DEVICE(&s->gpu), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpu), 0, AW_A10_GPU_BASE);
+
+    /* PS2-0 - keyboard */
+    sysbus_realize(SYS_BUS_DEVICE(&s->kbd), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->kbd), 0, AW_A10_PS2_0_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->kbd), 0, qdev_get_gpio_in(dev, 62));
+
+    /* PS2-1 - mouse */
+    sysbus_realize(SYS_BUS_DEVICE(&s->mouse), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->mouse), 0, AW_A10_PS2_1_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->mouse), 0, qdev_get_gpio_in(dev, 63));
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
hw/input/allwinner-a10-ps2.c new file +345 -0

345 lines not on this page · raw message

hw/input/meson.build +2 -0
index c0d4482180..b7bf4d9c9a 100644
@@ -16,3 +16,5 @@ system_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.
 system_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_keypad.c'))
 system_ss.add(when: 'CONFIG_TSC210X', if_true: files('tsc210x.c'))
 system_ss.add(when: 'CONFIG_LASIPS2', if_true: files('lasips2.c'))
+
+system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('allwinner-a10-ps2.c'))
include/hw/arm/allwinner-a10.h +3 -0
index c99ca6c1c4..163cc3af2b 100644
@@ -17,6 +17,7 @@
 #include "hw/display/allwinner-a10-lcdc.h"
 #include "hw/display/allwinner-gpu.h"
 #include "hw/i2c/allwinner-i2c.h"
+#include "hw/input/allwinner-a10-ps2.h"
 #include "hw/watchdog/allwinner-wdt.h"
 #include "sysemu/block-backend.h"
 
@@ -51,6 +52,8 @@ struct AwA10State {
     AwGpuState gpu;
     AwA10HdmiState hdmi;
     AwA10LcdcState lcd0;
+    AwA10PS2KbdState kbd;
+    AwA10PS2MouseState mouse;
     MemoryRegion sram_a;
     EHCISysBusState ehci[AW_A10_NUM_USB];
     OHCISysBusState ohci[AW_A10_NUM_USB];
include/hw/input/allwinner-a10-ps2.h new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

Re: [RFC Patch 5/5] hw/input: Add Allwinner-A10 PS2 emulation

hw/input/allwinner-a10-ps2.c line 72

Quoted 12 lines · Strahinja Jankovic

Add emulation for PS2-0 and PS2-1 for keyboard/mouse.

hw/input/allwinner-a10-ps2.c new file +5 -0
+static int allwinner_a10_ps2_fctl_is_irq(AwA10PS2State *s)
+{
+    return (s->regs[REG_INDEX(REG_FCTL)] & FIELD_REG_FCTL_TXRDY_IEN) ||
+        (s->pending &&
+         (s->regs[REG_INDEX(REG_FCTL)] & FIELD_REG_FCTL_RXRDY_IEN));

It looks a little odd that you need a separate s->pending bool here. Sometimes hardware does odd things, but the most usual situation is that the pending status of an interrupt is directly reflected in a register bit somewhere, and "is the interrupt high" logic is then just "is the pending bit set and is the enable bit set". Often the bit positions are deliberately the same in the two registers and then "is an interrupt set" is something like
if (s->regs[REG_INDEX(REG_FCTL)] & s->regs[REG_INDEX(REG_FSTS)] &
(TXRDY_IEN | RXRDY_IEN))

Quoted 22 lines
hw/input/allwinner-a10-ps2.c new file +22 -0
+}
+
+static void allwinner_a10_ps2_update_irq(AwA10PS2State *s)
+{
+    int level = (s->regs[REG_INDEX(REG_GCTL)] & FIELD_REG_GCTL_INT_EN) &&
+        allwinner_a10_ps2_fctl_is_irq(s);
+
+    qemu_set_irq(s->irq, level);
+}
+
+static void allwinner_a10_ps2_set_irq(void *opaque, int n, int level)
+{
+    AwA10PS2State *s = (AwA10PS2State *)opaque;
+
+    s->pending = level;
+    allwinner_a10_ps2_update_irq(s);
+}
+
+static uint64_t allwinner_a10_ps2_read(void *opaque, hwaddr offset,
+                                       unsigned size)
+{
+    AwA10PS2State *s = AW_A10_PS2(opaque);

hw/input/allwinner-a10-ps2.c line 104

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+    const uint32_t idx = REG_INDEX(offset);
+
+    switch (offset) {
+    case REG_FSTS:
+        {
+            uint32_t stat = FIELD_REG_FSTS_TX_RDY;
+            if (s->pending) {
+                stat |= FIELD_REG_FSTS_RX_LEVEL1 | FIELD_REG_FSTS_RX_RDY;
+            }
+            return stat;

The logic here also suggests that the code would be simpler if you keep the TX_RDY and RX_RDY state directly in this register value, rather than hardcoding TX_RDY to always-set and keeping RX_RDY in a separate pending field.

hw/input/allwinner-a10-ps2.c line 111

Quoted 7 lines
hw/input/allwinner-a10-ps2.c new file +7 -0
+        }
+        break;
+    case REG_DATA:
+        if (s->pending) {
+            s->last = ps2_read_data(s->ps2dev);
+        }
+        return s->last;

You could keep the last returned data in s->regs[REG_IDX(REG_DATA)] and avoid having to have an extra s->last field in the state struct.

Quoted 33 lines
hw/input/allwinner-a10-ps2.c new file +33 -0
+    case REG_GCTL:
+        {
+            if (allwinner_a10_ps2_fctl_is_irq(s)) {
+                s->regs[idx] |= FIELD_REG_GCTL_INT_FLAG;
+            } else {
+                s->regs[idx] &= FIELD_REG_GCTL_INT_FLAG;
+            }
+        }
+        break;
+    case REG_LCTL:
+    case REG_LSTS:
+    case REG_FCTL:
+    case REG_CLKDR:
+        break;
+    case 0x1C ... AW_A10_PS2_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
+                      __func__, (uint32_t)offset);
+        return 0;
+    default:
+        qemu_log_mask(LOG_UNIMP, "%s: unimplemented read offset 0x%04x\n",
+                      __func__, (uint32_t)offset);
+        return 0;
+    }
+
+    return s->regs[idx];
+}
+
+static void allwinner_a10_ps2_write(void *opaque, hwaddr offset,
+                                   uint64_t val, unsigned size)
+{
+    AwA10PS2State *s = AW_A10_PS2(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+

hw/input/allwinner-a10-ps2.c line 154

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+    s->regs[idx] = (uint32_t) val;
+
+    switch (offset) {
+    case REG_GCTL:
+        allwinner_a10_ps2_update_irq(s);
+        s->regs[idx] &= ~FIELD_REG_GCTL_SOFT_RST;
+        break;
+    case REG_DATA:
+        /* ??? This should toggle the TX interrupt line.  */
+        /* ??? This means kbd/mouse can block each other.  */

I don't understand this comment. It looks like it was cut-and-pasted from another device where it was originally written in 2005 (and I don't understand it there either). We should either understand what we mean here, or else not have the comment at all...

Quoted 12 lines
hw/input/allwinner-a10-ps2.c new file +12 -0
+        if (s->is_mouse) {
+            ps2_write_mouse(PS2_MOUSE_DEVICE(s->ps2dev), val);
+        } else {
+            ps2_write_keyboard(PS2_KBD_DEVICE(s->ps2dev), val);
+        }
+        break;
+    case REG_LCTL:
+    case REG_LSTS:
+    case REG_FCTL:
+    case REG_FSTS:
+    case REG_CLKDR:
+        break;

hw/input/allwinner-a10-ps2.c line 176

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+    case 0x1C ... AW_A10_PS2_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
+                      __func__, (uint32_t)offset);
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "%s: unimplemented write offset 0x%04x\n",
+                      __func__, (uint32_t)offset);
+        break;
+    }
+}

thanks
-- PMM

#10 lore raw

Re: [RFC Patch 5/5] hw/input: Add Allwinner-A10 PS2 emulation

Hi Peter,

Thank you for your comments.

I used the PL050 component as a starting point, but I did not clean things up well after I saw it working. I will clean it up before sending the new patch version.

Quoted 9 lines · Peter Maydell
Quoted 4 lines · Strahinja Jankovic

Add emulation for PS2-0 and PS2-1 for keyboard/mouse.

Quoted 17 lines

hw/input/allwinner-a10-ps2.c line 72

Quoted 5 lines
hw/input/allwinner-a10-ps2.c new file +5 -0
+static int allwinner_a10_ps2_fctl_is_irq(AwA10PS2State *s)
+{
+    return (s->regs[REG_INDEX(REG_FCTL)] & FIELD_REG_FCTL_TXRDY_IEN) ||
+        (s->pending &&
+         (s->regs[REG_INDEX(REG_FCTL)] & FIELD_REG_FCTL_RXRDY_IEN));

It looks a little odd that you need a separate s->pending bool here. Sometimes hardware does odd things, but the most usual situation is that the pending status of an interrupt is directly reflected in a register bit somewhere, and "is the interrupt high" logic is then just "is the pending bit set and is the enable bit set". Often the bit positions are deliberately the same in the two registers and then "is an interrupt set" is something like
if (s->regs[REG_INDEX(REG_FCTL)] & s->regs[REG_INDEX(REG_FSTS)] &
(TXRDY_IEN | RXRDY_IEN))

Yes, that makes sense. I will try to improve this.

Quoted 33 lines

hw/input/allwinner-a10-ps2.c

Quoted 6 lines
hw/input/allwinner-a10-ps2.c new file +5 -0
+}
+
+static void allwinner_a10_ps2_update_irq(AwA10PS2State *s)
+{
+    int level = (s->regs[REG_INDEX(REG_GCTL)] & FIELD_REG_GCTL_INT_EN)

&&

Quoted 15 lines
hw/input/allwinner-a10-ps2.c new file +15 -0
+        allwinner_a10_ps2_fctl_is_irq(s);
+
+    qemu_set_irq(s->irq, level);
+}
+
+static void allwinner_a10_ps2_set_irq(void *opaque, int n, int level)
+{
+    AwA10PS2State *s = (AwA10PS2State *)opaque;
+
+    s->pending = level;
+    allwinner_a10_ps2_update_irq(s);
+}
+
+static uint64_t allwinner_a10_ps2_read(void *opaque, hwaddr offset,
+                                       unsigned size)

hw/input/allwinner-a10-ps2.c

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+{
+    AwA10PS2State *s = AW_A10_PS2(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+
+    switch (offset) {
+    case REG_FSTS:
+        {
+            uint32_t stat = FIELD_REG_FSTS_TX_RDY;
+            if (s->pending) {
+                stat |= FIELD_REG_FSTS_RX_LEVEL1 |

FIELD_REG_FSTS_RX_RDY;

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+            }
+            return stat;

The logic here also suggests that the code would be simpler if you keep the TX_RDY and RX_RDY state directly in this register value, rather than hardcoding TX_RDY to always-set and keeping RX_RDY in a separate pending field.

That makes sense, I'll fix it.

Quoted 8 lines

hw/input/allwinner-a10-ps2.c line 111

Quoted 7 lines
hw/input/allwinner-a10-ps2.c new file +7 -0
+        }
+        break;
+    case REG_DATA:
+        if (s->pending) {
+            s->last = ps2_read_data(s->ps2dev);
+        }
+        return s->last;
Quoted 4 lines

You could keep the last returned data in s->regs[REG_IDX(REG_DATA)] and avoid having to have an extra s->last field in the state struct.

Ok.

Quoted 42 lines
Quoted 6 lines
hw/input/allwinner-a10-ps2.c new file +6 -0
+    case REG_GCTL:
+        {
+            if (allwinner_a10_ps2_fctl_is_irq(s)) {
+                s->regs[idx] |= FIELD_REG_GCTL_INT_FLAG;
+            } else {
+                s->regs[idx] &= FIELD_REG_GCTL_INT_FLAG;

hw/input/allwinner-a10-ps2.c

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+            }
+        }
+        break;
+    case REG_LCTL:
+    case REG_LSTS:
+    case REG_FCTL:
+    case REG_CLKDR:
+        break;
+    case 0x1C ... AW_A10_PS2_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset

0x%04x\n",

hw/input/allwinner-a10-ps2.c

Quoted 4 lines
hw/input/allwinner-a10-ps2.c new file +4 -0
+                      __func__, (uint32_t)offset);
+        return 0;
+    default:
+        qemu_log_mask(LOG_UNIMP, "%s: unimplemented read offset

0x%04x\n",

Quoted 20 lines
hw/input/allwinner-a10-ps2.c new file +20 -0
+                      __func__, (uint32_t)offset);
+        return 0;
+    }
+
+    return s->regs[idx];
+}
+
+static void allwinner_a10_ps2_write(void *opaque, hwaddr offset,
+                                   uint64_t val, unsigned size)
+{
+    AwA10PS2State *s = AW_A10_PS2(opaque);
+    const uint32_t idx = REG_INDEX(offset);
+
+    s->regs[idx] = (uint32_t) val;
+
+    switch (offset) {
+    case REG_GCTL:
+        allwinner_a10_ps2_update_irq(s);
+        s->regs[idx] &= ~FIELD_REG_GCTL_SOFT_RST;
+        break;
Quoted 10 lines

hw/input/allwinner-a10-ps2.c line 154

Quoted 3 lines
hw/input/allwinner-a10-ps2.c new file +3 -0
+    case REG_DATA:
+        /* ??? This should toggle the TX interrupt line.  */
+        /* ??? This means kbd/mouse can block each other.  */

I don't understand this comment. It looks like it was cut-and-pasted from another device where it was originally written in 2005 (and I don't understand it there either). We should either understand what we mean here, or else not have the comment at all...

Yes, unfortunately I missed this one before sending it out...

Quoted 19 lines
Quoted 4 lines
hw/input/allwinner-a10-ps2.c new file +4 -0
+        if (s->is_mouse) {
+            ps2_write_mouse(PS2_MOUSE_DEVICE(s->ps2dev), val);
+        } else {
+            ps2_write_keyboard(PS2_KBD_DEVICE(s->ps2dev), val);

hw/input/allwinner-a10-ps2.c

Quoted 10 lines
hw/input/allwinner-a10-ps2.c new file +10 -0
+        }
+        break;
+    case REG_LCTL:
+    case REG_LSTS:
+    case REG_FCTL:
+    case REG_FSTS:
+    case REG_CLKDR:
+        break;
+    case 0x1C ... AW_A10_PS2_IOSIZE:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset

0x%04x\n",

hw/input/allwinner-a10-ps2.c

Quoted 4 lines
hw/input/allwinner-a10-ps2.c new file +4 -0
+                      __func__, (uint32_t)offset);
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "%s: unimplemented write offset
Quoted 9 lines

0x%04x\n",

hw/input/allwinner-a10-ps2.c line 175

Quoted 4 lines
hw/input/allwinner-a10-ps2.c new file +4 -0
+                      __func__, (uint32_t)offset);
+        break;
+    }
+}

thanks
-- PMM

Thanks!

Best regards,
Strahinja