Skip to contentSkip to conversation

Raspberry Pi framebuffer, DMA and Windows support

PATCH Superseded Andrew Baumann 2 participants 12 messages Mar 3, 2016 – Mar 8, 2016

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Raspberry Pi framebuffer, DMA and Windows support

This patch series adds support for the AUX (second UART), framebuffer and DMA controller on Raspberry Pi 2, and enables booting Windows on this device. As with the previous series, it is heavily based on the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi 1.

After this series, it is possible to boot Windows by following the instructions at https://github.com/0xabu/qemu/wiki. You also boot Raspbian to the GUI using a command such as:

qemu-system-arm -M raspi2 -kernel raspbian-boot/kernel7.img -sd 2015-09-24-raspbian-jessie.img -append "rw earlyprintk loglevel=8 console=ttyAMA0 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootwait" -dtb raspbian-boot/bcm2709-rpi-2-b.dtb -serial stdio

I plan to add USB, and remaining timers / system devices in future patch series, along with support for pi1 (bcm2835). In the meantime, the complete code is available at https://github.com/0xabu/qemu

v2:
* added DMA controller
* revised per PMM's review feedback
* rebased on top of the patch for fixing ldl_phys/stl_phys in raspi devices, presently in target-arm.next

Cheers,
Andrew

Andrew Baumann (5):
bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry
pi
bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block
bcm2835_fb: add framebuffer device for Raspberry Pi
bcm2835_property: implement framebuffer control/configuration
properties
bcm2835_dma: add emulation of Raspberry Pi DMA controller

 hw/arm/bcm2835_peripherals.c         | 100 ++++++++-
 hw/arm/bcm2836.c                     |   2 +
 hw/arm/raspi.c                       |  12 +-
 hw/char/Makefile.objs                |   1 +
 hw/char/bcm2835_aux.c                | 316 ++++++++++++++++++++++++++
 hw/display/Makefile.objs             |   1 +
 hw/display/bcm2835_fb.c              | 424 +++++++++++++++++++++++++++++++++++
 hw/dma/Makefile.objs                 |   1 +
 hw/dma/bcm2835_dma.c                 | 408 +++++++++++++++++++++++++++++++++
 hw/misc/bcm2835_property.c           | 139 +++++++++++-
 include/hw/arm/bcm2835_peripherals.h |   6 +
 include/hw/char/bcm2835_aux.h        |  33 +++
 include/hw/display/bcm2835_fb.h      |  47 ++++
 include/hw/dma/bcm2835_dma.h         |  47 ++++
 include/hw/misc/bcm2835_property.h   |   5 +-
 15 files changed, 1529 insertions(+), 13 deletions(-)
 create mode 100644 hw/char/bcm2835_aux.c
 create mode 100644 hw/display/bcm2835_fb.c
 create mode 100644 hw/dma/bcm2835_dma.c
 create mode 100644 include/hw/char/bcm2835_aux.h
 create mode 100644 include/hw/display/bcm2835_fb.h
 create mode 100644 include/hw/dma/bcm2835_dma.h
Signature · 1 line
2.5.3
#1 lore raw

PATCH v2 1/5 bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry pi

---
 hw/arm/bcm2835_peripherals.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/arm/bcm2835_peripherals.c +7 -0
index 6d66fa0..6ce9cd1 100644
@@ -171,6 +171,13 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    object_property_set_bool(OBJECT(&s->sdhci), true, "pending-insert-quirk",
+                             &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
     object_property_set_bool(OBJECT(&s->sdhci), true, "realized", &err);
     if (err) {
         error_propagate(errp, err);
Signature · 1 line
2.5.3
#2 lore raw

PATCH v2 2/5 bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block

In reply to Andrew Baumann

At present only the core UART functions (data path for tx/rx) are implemented, which is enough for UEFI to boot. The following features/registers are unimplemented:
* Line/modem control
* Scratch register
* Extra control
* Baudrate
* SPI interfaces

---

Notes:
v2:
* document unimplemented features, log unimplemented register accesses
* model read path as 8-bit
* drop incorrect event (break detection) functionality
* implement AUX_IRQ register
* model interrupt enables as a uint8 rather than 2 bools
* corrected bugs in implementation of IIR bits 0-2
* use chardev prop rather than qemu_char_get_next_serial(); the soc-level (bcm2835_peripherals) handling is still a little messy however, because uart0 is a pl011 device which still calls qemu_char_get_next_serial()

 hw/arm/bcm2835_peripherals.c         |  29 ++++
 hw/char/Makefile.objs                |   1 +
 hw/char/bcm2835_aux.c                | 316 +++++++++++++++++++++++++++++++++++
 include/hw/arm/bcm2835_peripherals.h |   2 +
 include/hw/char/bcm2835_aux.h        |  33 ++++
 5 files changed, 381 insertions(+)
 create mode 100644 hw/char/bcm2835_aux.c
 create mode 100644 include/hw/char/bcm2835_aux.h
hw/arm/bcm2835_peripherals.c +29 -0
index 6ce9cd1..375e341 100644
@@ -12,6 +12,8 @@
 #include "hw/arm/bcm2835_peripherals.h"
 #include "hw/misc/bcm2835_mbox_defs.h"
 #include "hw/arm/raspi_platform.h"
+#include "sysemu/char.h"
+#include "sysemu/sysemu.h" /* for serial_hds */
 
 /* Peripheral base address on the VC (GPU) system bus */
 #define BCM2835_VC_PERI_BASE 0x7e000000
@@ -48,6 +50,11 @@ static void bcm2835_peripherals_init(Object *obj)
     object_property_add_child(obj, "uart0", OBJECT(s->uart0), NULL);
     qdev_set_parent_bus(DEVICE(s->uart0), sysbus_get_default());
 
+    /* AUX / UART1 */
+    object_initialize(&s->aux, sizeof(s->aux), TYPE_BCM2835_AUX);
+    object_property_add_child(obj, "aux", OBJECT(&s->aux), NULL);
+    qdev_set_parent_bus(DEVICE(&s->aux), sysbus_get_default());
+
     /* Mailboxes */
     object_initialize(&s->mboxes, sizeof(s->mboxes), TYPE_BCM2835_MBOX);
     object_property_add_child(obj, "mbox", OBJECT(&s->mboxes), NULL);
@@ -79,6 +86,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
     MemoryRegion *ram;
     Error *err = NULL;
     uint32_t ram_size;
+    CharDriverState *chr;
     int n;
 
     obj = object_property_get_link(OBJECT(dev), "ram", &err);
@@ -131,6 +139,27 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
                                INTERRUPT_UART));
 
+    /* AUX / UART1 */
+    /* XXX: pl011 (uart0) uses qemu_char_get_next_serial(), so at this point it
+     * should have claimed the first serial device (if one exists) */
+    chr = serial_hds[1];
+    if (chr == NULL) {
+        chr = qemu_chr_new("bcm2835.uart1", "null", NULL);
+    }
+    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", chr);
+
+    object_property_set_bool(OBJECT(&s->aux), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    memory_region_add_subregion(&s->peri_mr, UART1_OFFSET,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->aux), 0));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->aux), 0,
+        qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
+                               INTERRUPT_AUX));
+
     /* Mailboxes */
     object_property_set_bool(OBJECT(&s->mboxes), true, "realized", &err);
     if (err) {
hw/char/Makefile.objs +1 -0
index 5931cc8..69a553c 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_SH4) += sh_serial.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
 obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
+obj-$(CONFIG_RASPI) += bcm2835_aux.o
 
 common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
 common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
hw/char/bcm2835_aux.c new file +316 -0

316 lines not on this page · raw message

include/hw/arm/bcm2835_peripherals.h +2 -0
index 5d888dc..889adf5 100644
@@ -14,6 +14,7 @@
 #include "qemu-common.h"
 #include "exec/address-spaces.h"
 #include "hw/sysbus.h"
+#include "hw/char/bcm2835_aux.h"
 #include "hw/intc/bcm2835_ic.h"
 #include "hw/misc/bcm2835_property.h"
 #include "hw/misc/bcm2835_mbox.h"
@@ -33,6 +34,7 @@ typedef struct BCM2835PeripheralState {
     qemu_irq irq, fiq;
 
     SysBusDevice *uart0;
+    BCM2835AuxState aux;
     BCM2835ICState ic;
     BCM2835PropertyState property;
     BCM2835MboxState mboxes;
include/hw/char/bcm2835_aux.h new file +33 -0
new file mode 100644
index 0000000..42f0ee7
@@ -0,0 +1,33 @@
+/*
+ * Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
+ * Written by Andrew Baumann
+ *
+ * This code is licensed under the GNU GPLv2 and later.
+ */
+
+#ifndef BCM2835_AUX_H
+#define BCM2835_AUX_H
+
+#include "hw/sysbus.h"
+#include "sysemu/char.h"
+
+#define TYPE_BCM2835_AUX "bcm2835-aux"
+#define BCM2835_AUX(obj) OBJECT_CHECK(BCM2835AuxState, (obj), TYPE_BCM2835_AUX)
+
+#define BCM2835_AUX_RX_FIFO_LEN 8
+
+typedef struct {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
+    MemoryRegion iomem;
+    CharDriverState *chr;
+    qemu_irq irq;
+
+    uint8_t read_fifo[BCM2835_AUX_RX_FIFO_LEN];
+    uint8_t read_pos, read_count;
+    uint8_t ier, iir;
+} BCM2835AuxState;
+
+#endif
Signature · 1 line
2.5.3
Reviewed-by on v2 2/5
#3 lore raw

Re: [Qemu-arm] [PATCH v2 2/5] bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block

Quoted 11 lines · Andrew Baumann

At present only the core UART functions (data path for tx/rx) are implemented, which is enough for UEFI to boot. The following features/registers are unimplemented:
* Line/modem control
* Scratch register
* Extra control
* Baudrate
* SPI interfaces

hw/arm/bcm2835_peripherals.c +0 -0
@@ -131,6 +139,27 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,

hw/arm/bcm2835_peripherals.c static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) · line 149

Quoted 10 lines
hw/arm/bcm2835_peripherals.c +8 -0
                                INTERRUPT_UART));
 
+    /* AUX / UART1 */
+    /* XXX: pl011 (uart0) uses qemu_char_get_next_serial(), so at this point it
+     * should have claimed the first serial device (if one exists) */
+    chr = serial_hds[1];
+    if (chr == NULL) {
+        chr = qemu_chr_new("bcm2835.uart1", "null", NULL);
+    }
+    qdev_prop_set_chr(DEVICE(&s->aux), "chardev", chr);

You should use qemu_char_get_next_serial() rather than directly looking in serial_hds[]. Otherwise

(Eventually what should happen is that we fix pl011 to take a chardev property, and then we can create aliases of those properties on the bcm2835 SoC object, and wire them up in the board level code. But that's a cleanup for another day.)

thanks
-- PMM

#4 lore raw

PATCH v2 3/5 bcm2835_fb: add framebuffer device for Raspberry Pi

In reply to Andrew Baumann

The framebuffer occupies the upper portion of memory (64MiB by default), but it can only be controlled/configured via a system mailbox or property channel (to be added by a subsequent patch).

---

Notes:
v2:
* avoid ldl_phys
* move code to increase default pi2 memory size back to the final patch

 hw/arm/bcm2835_peripherals.c         |  38 +++-
 hw/arm/bcm2836.c                     |   2 +
 hw/arm/raspi.c                       |   5 +-
 hw/display/Makefile.objs             |   1 +
 hw/display/bcm2835_fb.c              | 424 +++++++++++++++++++++++++++++++++++
 include/hw/arm/bcm2835_peripherals.h |   2 +
 include/hw/display/bcm2835_fb.h      |  47 ++++
 7 files changed, 517 insertions(+), 2 deletions(-)
 create mode 100644 hw/display/bcm2835_fb.c
 create mode 100644 include/hw/display/bcm2835_fb.h
hw/arm/bcm2835_peripherals.c +37 -1
index 375e341..552611a 100644
@@ -63,6 +63,16 @@ static void bcm2835_peripherals_init(Object *obj)
     object_property_add_const_link(OBJECT(&s->mboxes), "mbox-mr",
                                    OBJECT(&s->mbox_mr), &error_abort);
 
+    /* Framebuffer */
+    object_initialize(&s->fb, sizeof(s->fb), TYPE_BCM2835_FB);
+    object_property_add_child(obj, "fb", OBJECT(&s->fb), NULL);
+    object_property_add_alias(obj, "vcram-size", OBJECT(&s->fb), "vcram-size",
+                              &error_abort);
+    qdev_set_parent_bus(DEVICE(&s->fb), sysbus_get_default());
+
+    object_property_add_const_link(OBJECT(&s->fb), "dma-mr",
+                                   OBJECT(&s->gpu_bus_mr), &error_abort);
+
     /* Property channel */
     object_initialize(&s->property, sizeof(s->property), TYPE_BCM2835_PROPERTY);
     object_property_add_child(obj, "property", OBJECT(&s->property), NULL);
@@ -85,7 +95,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
     Object *obj;
     MemoryRegion *ram;
     Error *err = NULL;
-    uint32_t ram_size;
+    uint32_t ram_size, vcram_size;
     CharDriverState *chr;
     int n;
 
@@ -173,6 +183,32 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_ARM_IRQ,
                                INTERRUPT_ARM_MAILBOX));
 
+    /* Framebuffer */
+    vcram_size = (uint32_t)object_property_get_int(OBJECT(s), "vcram-size",
+                                                   &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_int(OBJECT(&s->fb), ram_size - vcram_size,
+                            "vcram-base", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_bool(OBJECT(&s->fb), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    memory_region_add_subregion(&s->mbox_mr, MBOX_CHAN_FB << MBOX_AS_CHAN_SHIFT,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->fb), 0));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->fb), 0,
+                       qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_FB));
+
     /* Property channel */
     object_property_set_int(OBJECT(&s->property), ram_size, "ram-size", &err);
     if (err) {
hw/arm/bcm2836.c +2 -0
index 0321439..89a6b35 100644
@@ -42,6 +42,8 @@ static void bcm2836_init(Object *obj)
                               &error_abort);
     object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals),
                               "board-rev", &error_abort);
+    object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals),
+                              "vcram-size", &error_abort);
     qdev_set_parent_bus(DEVICE(&s->peripherals), sysbus_get_default());
 }
 
hw/arm/raspi.c +4 -1
index 6582279..5498209 100644
@@ -113,6 +113,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
 static void raspi2_init(MachineState *machine)
 {
     RasPiState *s = g_new0(RasPiState, 1);
+    uint32_t vcram_size;
     DriveInfo *di;
     BlockBackend *blk;
     BusState *bus;
@@ -149,7 +150,9 @@ static void raspi2_init(MachineState *machine)
     qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
     object_property_set_bool(OBJECT(carddev), true, "realized", &error_fatal);
 
-    setup_boot(machine, 2, machine->ram_size);
+    vcram_size = object_property_get_int(OBJECT(&s->soc), "vcram-size",
+                                         &error_abort);
+    setup_boot(machine, 2, machine->ram_size - vcram_size);
 }
 
 static void raspi2_machine_init(MachineClass *mc)
hw/display/Makefile.objs +1 -0
index f0cf431..d99780e 100644
@@ -27,6 +27,7 @@ endif
 obj-$(CONFIG_OMAP) += omap_dss.o
 obj-$(CONFIG_OMAP) += omap_lcdc.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
+obj-$(CONFIG_RASPI) += bcm2835_fb.o
 obj-$(CONFIG_SM501) += sm501.o
 obj-$(CONFIG_TCX) += tcx.o
 obj-$(CONFIG_CG3) += cg3.o
hw/display/bcm2835_fb.c new file +424 -0

424 lines not on this page · raw message

include/hw/arm/bcm2835_peripherals.h +2 -0
index 889adf5..e19d360 100644
@@ -15,6 +15,7 @@
 #include "exec/address-spaces.h"
 #include "hw/sysbus.h"
 #include "hw/char/bcm2835_aux.h"
+#include "hw/display/bcm2835_fb.h"
 #include "hw/intc/bcm2835_ic.h"
 #include "hw/misc/bcm2835_property.h"
 #include "hw/misc/bcm2835_mbox.h"
@@ -35,6 +36,7 @@ typedef struct BCM2835PeripheralState {
 
     SysBusDevice *uart0;
     BCM2835AuxState aux;
+    BCM2835FBState fb;
     BCM2835ICState ic;
     BCM2835PropertyState property;
     BCM2835MboxState mboxes;
include/hw/display/bcm2835_fb.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.5.3
Reviewed-by on v2 3/5
#5 lore raw

Re: [Qemu-arm] [PATCH v2 3/5] bcm2835_fb: add framebuffer device for Raspberry Pi

Quoted 5 lines · Andrew Baumann

The framebuffer occupies the upper portion of memory (64MiB by default), but it can only be controlled/configured via a system mailbox or property channel (to be added by a subsequent patch).

thanks
-- PMM

#6 lore raw

PATCH v2 4/5 bcm2835_property: implement framebuffer control/configuration properties

In reply to Andrew Baumann

The property channel driver now interfaces with the framebuffer device to query and set framebuffer parameters. As a result of this, the "get ARM RAM size" query now correctly returns the video RAM base address (not total RAM size), and the ram-size property is no longer relevant here.

---

Notes:
v2:
* avoid ldl/stl_phys
* move code to increase default pi2 memory size from preceding patch here (it was incorrect without the property channel implementation changes)

 hw/arm/bcm2835_peripherals.c       |   8 +--
 hw/arm/raspi.c                     |   7 +-
 hw/misc/bcm2835_property.c         | 139 ++++++++++++++++++++++++++++++++++++-
 include/hw/misc/bcm2835_property.h |   5 +-
 4 files changed, 144 insertions(+), 15 deletions(-)
hw/arm/bcm2835_peripherals.c +2 -6
index 552611a..9b9de99 100644
@@ -80,6 +80,8 @@ static void bcm2835_peripherals_init(Object *obj)
                               "board-rev", &error_abort);
     qdev_set_parent_bus(DEVICE(&s->property), sysbus_get_default());
 
+    object_property_add_const_link(OBJECT(&s->property), "fb",
+                                   OBJECT(&s->fb), &error_abort);
     object_property_add_const_link(OBJECT(&s->property), "dma-mr",
                                    OBJECT(&s->gpu_bus_mr), &error_abort);
 
@@ -210,12 +212,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_FB));
 
     /* Property channel */
-    object_property_set_int(OBJECT(&s->property), ram_size, "ram-size", &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-
     object_property_set_bool(OBJECT(&s->property), true, "realized", &err);
     if (err) {
         error_propagate(errp, err);
hw/arm/raspi.c +1 -6
index 5498209..83fe809 100644
@@ -164,11 +164,6 @@ static void raspi2_machine_init(MachineClass *mc)
     mc->no_floppy = 1;
     mc->no_cdrom = 1;
     mc->max_cpus = BCM2836_NCPUS;
-
-    /* XXX: Temporary restriction in RAM size from the full 1GB. Since
-     * we do not yet support the framebuffer / GPU, we need to limit
-     * RAM usable by the OS to sit below the peripherals.
-     */
-    mc->default_ram_size = 0x3F000000; /* BCM2836_PERI_BASE */
+    mc->default_ram_size = 1024 * 1024 * 1024;
 };
 DEFINE_MACHINE("raspi2", raspi2_machine_init)
hw/misc/bcm2835_property.c +137 -2

175 lines not on this page · raw message

include/hw/misc/bcm2835_property.h +4 -1
index df889ea..edcab60 100644
@@ -9,6 +9,7 @@
 #include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 #include "net/net.h"
+#include "hw/display/bcm2835_fb.h"
 
 #define TYPE_BCM2835_PROPERTY "bcm2835-property"
 #define BCM2835_PROPERTY(obj) \
@@ -18,13 +19,15 @@ typedef struct {
     /*< private >*/
     SysBusDevice busdev;
     /*< public >*/
+
     MemoryRegion *dma_mr;
     AddressSpace dma_as;
     MemoryRegion iomem;
     qemu_irq mbox_irq;
+    BCM2835FBState *fbdev;
+
     MACAddr macaddr;
     uint32_t board_rev;
-    uint32_t ram_size;
     uint32_t addr;
     bool pending;
 } BCM2835PropertyState;
Signature · 1 line
2.5.3
Reviewed-by on v2 4/5
#7 lore raw

Re: [Qemu-arm] [PATCH v2 4/5] bcm2835_property: implement framebuffer control/configuration properties

Quoted 7 lines · Andrew Baumann

The property channel driver now interfaces with the framebuffer device to query and set framebuffer parameters. As a result of this, the "get ARM RAM size" query now correctly returns the video RAM base address (not total RAM size), and the ram-size property is no longer relevant here.

thanks
-- PMM

#8 lore raw

PATCH v2 5/5 bcm2835_dma: add emulation of Raspberry Pi DMA controller

In reply to Andrew Baumann

At present, all DMA transfers complete inline (so a looping descriptor queue will lock up the device). We also do not model pause/abort, arbitrarion/priority, or debug features.

---

Notes:
v2:
* avoid ldl_phys/stl_phys
* compute address of channel structure only after asserting its validity
* correctly implement per-channel reset and abort bits
* set channel paused bit when completing DMA

 hw/arm/bcm2835_peripherals.c         |  26 +++
 hw/dma/Makefile.objs                 |   1 +
 hw/dma/bcm2835_dma.c                 | 408 +++++++++++++++++++++++++++++++++++
 include/hw/arm/bcm2835_peripherals.h |   2 +
 include/hw/dma/bcm2835_dma.h         |  47 ++++
 5 files changed, 484 insertions(+)
 create mode 100644 hw/dma/bcm2835_dma.c
 create mode 100644 include/hw/dma/bcm2835_dma.h
hw/arm/bcm2835_peripherals.c +26 -0
index 9b9de99..eeb4934 100644
@@ -89,6 +89,14 @@ static void bcm2835_peripherals_init(Object *obj)
     object_initialize(&s->sdhci, sizeof(s->sdhci), TYPE_SYSBUS_SDHCI);
     object_property_add_child(obj, "sdhci", OBJECT(&s->sdhci), NULL);
     qdev_set_parent_bus(DEVICE(&s->sdhci), sysbus_get_default());
+
+    /* DMA Channels */
+    object_initialize(&s->dma, sizeof(s->dma), TYPE_BCM2835_DMA);
+    object_property_add_child(obj, "dma", OBJECT(&s->dma), NULL);
+    qdev_set_parent_bus(DEVICE(&s->dma), sysbus_get_default());
+
+    object_property_add_const_link(OBJECT(&s->dma), "dma-mr",
+                                   OBJECT(&s->gpu_bus_mr), &error_abort);
 }
 
 static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
@@ -257,6 +265,24 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    /* DMA Channels */
+    object_property_set_bool(OBJECT(&s->dma), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    memory_region_add_subregion(&s->peri_mr, DMA_OFFSET,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 0));
+    memory_region_add_subregion(&s->peri_mr, DMA15_OFFSET,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 1));
+
+    for (n = 0; n <= 12; n++) {
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), n,
+                           qdev_get_gpio_in_named(DEVICE(&s->ic),
+                                                  BCM2835_IC_GPU_IRQ,
+                                                  INTERRUPT_DMA0 + n));
+    }
 }
 
 static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data)
hw/dma/Makefile.objs +1 -0
index 0e65ed0..a1abbcf 100644
@@ -11,3 +11,4 @@ common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o
 
 obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
+obj-$(CONFIG_RASPI) += bcm2835_dma.o
hw/dma/bcm2835_dma.c new file +408 -0

408 lines not on this page · raw message

include/hw/arm/bcm2835_peripherals.h +2 -0
index e19d360..e12ae37 100644
@@ -16,6 +16,7 @@
 #include "hw/sysbus.h"
 #include "hw/char/bcm2835_aux.h"
 #include "hw/display/bcm2835_fb.h"
+#include "hw/dma/bcm2835_dma.h"
 #include "hw/intc/bcm2835_ic.h"
 #include "hw/misc/bcm2835_property.h"
 #include "hw/misc/bcm2835_mbox.h"
@@ -37,6 +38,7 @@ typedef struct BCM2835PeripheralState {
     SysBusDevice *uart0;
     BCM2835AuxState aux;
     BCM2835FBState fb;
+    BCM2835DMAState dma;
     BCM2835ICState ic;
     BCM2835PropertyState property;
     BCM2835MboxState mboxes;
include/hw/dma/bcm2835_dma.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.5.3
Reviewed-by on v2 5/5
#9 lore raw

Re: [Qemu-arm] [PATCH v2 5/5] bcm2835_dma: add emulation of Raspberry Pi DMA controller

Quoted 6 lines · Andrew Baumann

At present, all DMA transfers complete inline (so a looping descriptor queue will lock up the device). We also do not model pause/abort, arbitrarion/priority, or debug features.

---

Can you add Gregory's Signed-off-by (and authorship from?) to whichever patches are appropriate when you resend (as per discussion on the earlier version of this patch)?

thanks
-- PMM

#10 lore raw

Re: [Qemu-arm] [PATCH v2 5/5] bcm2835_dma: add emulation of Raspberry Pi DMA controller

Quoted 9 lines

From: Peter Maydell [mailto:[email protected]]
Sent: Monday, 7 March 2016 8:37 PM

Quoted 4 lines · Andrew Baumann

At present, all DMA transfers complete inline (so a looping descriptor queue will lock up the device). We also do not model pause/abort, arbitrarion/priority, or debug features.

Quoted 8 lines
Quoted 2 lines

---

Can you add Gregory's Signed-off-by (and authorship from?) to whichever patches are appropriate when you resend (as per discussion on the earlier version of this patch)?

Yes, happily. But what's the best way to capture this when the code we're committing is a mixture of code from Gregory and Stefan (via a manual patch into Stefan's ar7 repo, so much of that history is lost to me) that I've then extended and refactored? I know what I added (e.g. aux), but for the files with joint authorship (fb, dma) should we just put Gregory as the author on those patches with a signed-off-by from me? Can I also add a signed-off-by on behalf of Gregory, or does he need to do it?

Forgive the newbie questions, but I'm new to this process and want to get it right :)

Note that we didn't do this for the previous patch series. Mea culpa. If there's a good way to go back and correct history, I'm happy to help.

Thanks,
Andrew

#11 lore raw

Re: [Qemu-arm] [PATCH v2 5/5] bcm2835_dma: add emulation of Raspberry Pi DMA controller

Quoted 18 lines · Andrew Baumann
Quoted 9 lines

From: Peter Maydell [mailto:[email protected]]
Sent: Monday, 7 March 2016 8:37 PM

Quoted 4 lines · Andrew Baumann

At present, all DMA transfers complete inline (so a looping descriptor queue will lock up the device). We also do not model pause/abort, arbitrarion/priority, or debug features.

Quoted 8 lines
Quoted 2 lines

---

Can you add Gregory's Signed-off-by (and authorship from?) to whichever patches are appropriate when you resend (as per discussion on the earlier version of this patch)?

Quoted 7 lines

Yes, happily. But what's the best way to capture this when the code we're committing is a mixture of code from Gregory and Stefan (via a manual patch into Stefan's ar7 repo, so much of that history is lost to me) that I've then extended and refactored? I know what I added (e.g. aux), but for the files with joint authorship (fb, dma) should we just put Gregory as the author on those patches with a signed-off-by from me? Can I also add a signed-off-by on behalf of Gregory, or does he need to do it?

Gregory said an s-o-by from him was OK in the mail thread, so that's sufficient for you to be able to add it.

The usual approach for multiple authors is that you have the author be the original or major author, and then the signed-off-by section looks like:

[XYZ: changed foo, bar, baz]

which preserves credit for the original author's work and also a record of what changes have been made by the next person in the chain.

If you search in 'git log' for "[PMM" you'll find a bunch of examples of when I've done it in the past, eg commit f0c02d15b57da6.

(Overall there are two aspects to the signoff lines:
a: the legal aspect, where you're agreeing to the stuff in the Developer's Certificate of Origin; one of the options in there is "this code is under an acceptable license that allows me to contribute it", so taking some out-of-tree open source code from somebody else, fixing it up and sending it in with just your signoff is perfectly fine from the strict legal/traceability point of view.

b: credit for work done. This is a social/interpersonal question, so there aren't any hard and fast rules, but generally I find the best approach is to ask the original authors for their preferences[*], let them know in advance about what you're planning and err on the side of giving them authorship and other credit rather than yourself, while also being clear about what you've done that they should not be blamed for.
[*] Occasionally somebody actually prefers not to be credited via signoff because they feel they're now a long way removed from what it was.
)

thanks
-- PMM