Skip to contentSkip to conversation

Raspberry Pi framebuffer, DMA and Windows support

PATCH Applied Andrew Baumann 3 participants 11 messages Mar 8, 2016 – Mar 17, 2016

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

v3 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

v3:
* tweaked instantiation of uart1 char device
* identified Gregory as primary author of framebuffer and DMA emulation

Cheers,
Andrew

Andrew Baumann (2):
bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry
pi
bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block

Grégory ESTRADE (3):
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         | 103 ++++++++-
 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, 1532 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.7.0
#1 lore raw

PATCH v3 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.7.0
#2 lore raw

PATCH v3 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:
v3:
* use qemu_char_get_next_serial() to configure the chardev prop in bcm2835_peripherals, rather than reaching into serial_hds[] directly

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         |  32 ++++
 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, 384 insertions(+)
 create mode 100644 hw/char/bcm2835_aux.c
 create mode 100644 include/hw/char/bcm2835_aux.h
hw/arm/bcm2835_peripherals.c +32 -0
index 6ce9cd1..d6453cc 100644
@@ -12,6 +12,7 @@
 #include "hw/arm/bcm2835_peripherals.h"
 #include "hw/misc/bcm2835_mbox_defs.h"
 #include "hw/arm/raspi_platform.h"
+#include "sysemu/char.h"
 
 /* Peripheral base address on the VC (GPU) system bus */
 #define BCM2835_VC_PERI_BASE 0x7e000000
@@ -48,6 +49,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 +85,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 +138,29 @@ 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 */
+    /* TODO: don't call qemu_char_get_next_serial() here, instead set
+     * chardev properties for each uart at the board level, once pl011
+     * (uart0) has been updated to avoid qemu_char_get_next_serial()
+     */
+    chr = qemu_char_get_next_serial();
+    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) {
@@ -203,6 +233,8 @@ static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
 
     dc->realize = bcm2835_peripherals_realize;
+    /* Reason: realize() method uses qemu_char_get_next_serial() */
+    dc->cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bcm2835_peripherals_type_info = {
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.7.0
#3 lore raw

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

In reply to Andrew Baumann

From: Grégory ESTRADE <[email protected]>

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).

[AB: added Windows (BGR) support and cleanup/refactoring for upstream submission]

---

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 d6453cc..c2fe6b7 100644
@@ -62,6 +62,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);
@@ -84,7 +94,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;
 
@@ -174,6 +184,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.7.0
#4 lore raw

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

In reply to Andrew Baumann

From: Grégory ESTRADE <[email protected]>

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.

[AB: cleanup/refactoring for upstream submission]

---

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 c2fe6b7..4d74a18 100644
@@ -79,6 +79,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);
 
@@ -211,12 +213,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.7.0
#5 lore raw

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

In reply to Andrew Baumann

From: Grégory ESTRADE <[email protected]>

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.

[AB: implement 2D mode, cleanup/refactoring for upstream submission]

---

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 4d74a18..8099a8a 100644
@@ -88,6 +88,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)
@@ -258,6 +266,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.7.0
#6 lore raw
In reply to Andrew Baumann
Quoted 10 lines · Andrew Baumann

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:

Quoted 8 lines

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

Thanks, applied to target-arm.next.

-- PMM

#7 lore raw
In reply to Andrew Baumann
Quoted 6 lines · Andrew Baumann

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.

Quoted 8 lines

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

So I tried something like this, and the kernel gives a WARNING with a backtrace, and then hangs:

[    5.413943] VFP support v0.3: implementor 41 architecture 4 part 30
variant f rev 0
[    5.976888] pinctrl core: initialized pinctrl subsystem
[    6.171197] NET: Registered protocol family 16
[    6.286799] DMA: preallocated 4096 KiB pool for atomic coherent allocations
[    6.366889] cpuidle: using governor ladder
[    6.391665] cpuidle: using governor menu
[    6.401604] bcm2709.uart_clock = 3000000
[    6.478063] ------------[ cut here ]------------
[    6.481052] WARNING: CPU: 0 PID: 1 at
/build/buildd/linux-3.18.0/arch/arm/mach-bcm2709/armctrl.c:148
armctrl_xlate+0x188/0x274()
[    6.484474] Modules linked in:
[    6.489783] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
3.18.0-20-rpi2 #21-Ubuntu
[    6.502781] [<80016ab0>] (unwind_backtrace) from [<800129d0>]
(show_stack+0x10/0x14)
[    6.506355] [<800129d0>] (show_stack) from [<805fee10>]
(dump_stack+0x9c/0xd4)
[    6.508946] [<805fee10>] (dump_stack) from [<80026ed8>]
(warn_slowpath_common+0x70/0x8c)
[    6.511251] [<80026ed8>] (warn_slowpath_common) from [<80026f90>]
(warn_slowpath_null+0x1c/0x24)
[    6.512797] [<80026f90>] (warn_slowpath_null) from [<80022044>]
(armctrl_xlate+0x188/0x274)
[    6.514558] [<80022044>] (armctrl_xlate) from [<8007399c>]
(irq_create_of_mapping+0x64/0x110)
[    6.517173] [<8007399c>] (irq_create_of_mapping) from [<804c4ef4>]
(irq_of_parse_and_map+0x24/0x2c)
[    6.518741] [<804c4ef4>] (irq_of_parse_and_map) from [<804c4f14>]
(of_irq_to_resource+0x18/0xb8)
[    6.520209] [<804c4f14>] (of_irq_to_resource) from [<804c4ff0>]
(of_irq_to_resource_table+0x3c/0x54)
[    6.523598] [<804c4ff0>] (of_irq_to_resource_table) from
[<804c25b8>] (of_device_alloc+0xd8/0x180)
[    6.528838] [<804c25b8>] (of_device_alloc) from [<804c26a8>]
(of_platform_device_create_pdata+0x48/0x98)
[    6.535352] [<804c26a8>] (of_platform_device_create_pdata) from
[<804c27f0>] (of_platform_bus_create+0xec/0x3ac)
[    6.539440] [<804c27f0>] (of_platform_bus_create) from [<804c2860>]
(of_platform_bus_create+0x15c/0x3ac)
[    6.541217] [<804c2860>] (of_platform_bus_create) from [<804c2c28>]
(of_platform_populate+0x5c/0xa0)
[    6.542770] [<804c2c28>] (of_platform_populate) from [<8088cad8>]
(bcm2709_init+0x64/0x3fc)
[    6.546211] [<8088cad8>] (bcm2709_init) from [<80888870>]
(customize_machine+0x20/0x40)
[    6.547711] [<80888870>] (customize_machine) from [<800088bc>]
(do_one_initcall+0xd8/0x208)
[    6.549200] [<800088bc>] (do_one_initcall) from [<80885ef4>]
(kernel_init_freeable+0x1fc/0x29c)
[    6.551771] [<80885ef4>] (kernel_init_freeable) from [<805f9298>]
(kernel_init+0x8/0xf0)
[    6.553319] [<805f9298>] (kernel_init) from [<8000efe8>]
(ret_from_fork+0x14/0x2c)
[    6.556670] ---[ end trace 088ba587f0a009cc ]---
[    6.649948] No ATAGs?
[    6.658029] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4
watchpoint registers.
[    6.660393] hw-breakpoint: maximum watchpoint size is 8 bytes.
[    6.664206] mailbox: Broadcom VideoCore Mailbox driver
[    6.693912] bcm2708_vcio: mailbox at f300b880
[    6.703745] bcm_power: Broadcom power driver
[    6.707642] bcm_power_open() -> 0
[    6.708671] bcm_power_request(0, 8)

Does that look familiar? (My first guess is just that it wants some bit of hardware we haven't got a device model for yet. I haven't tried to investigate at all yet.)

thanks
-- PMM

#8 lore raw
Quoted 90 lines

From: Peter Maydell [mailto:[email protected]]
Sent: Wednesday, 16 March 2016 9:54 AM

Quoted 6 lines · Andrew Baumann

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.

Quoted 7 lines

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"

Quoted 1 line

-dtb raspbian-boot/bcm2709-rpi-2-b.dtb -serial stdio

So I tried something like this, and the kernel gives a WARNING with a backtrace, and then hangs:

[    5.413943] VFP support v0.3: implementor 41 architecture 4 part 30
variant f rev 0
[    5.976888] pinctrl core: initialized pinctrl subsystem
[    6.171197] NET: Registered protocol family 16
[    6.286799] DMA: preallocated 4096 KiB pool for atomic coherent allocations
[    6.366889] cpuidle: using governor ladder
[    6.391665] cpuidle: using governor menu
[    6.401604] bcm2709.uart_clock = 3000000
[    6.478063] ------------[ cut here ]------------
[    6.481052] WARNING: CPU: 0 PID: 1 at
/build/buildd/linux-3.18.0/arch/arm/mach-bcm2709/armctrl.c:148
armctrl_xlate+0x188/0x274()
[    6.484474] Modules linked in:
[    6.489783] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
3.18.0-20-rpi2 #21-Ubuntu
[    6.502781] [<80016ab0>] (unwind_backtrace) from [<800129d0>]
(show_stack+0x10/0x14)
[    6.506355] [<800129d0>] (show_stack) from [<805fee10>]
(dump_stack+0x9c/0xd4)
[    6.508946] [<805fee10>] (dump_stack) from [<80026ed8>]
(warn_slowpath_common+0x70/0x8c)
[    6.511251] [<80026ed8>] (warn_slowpath_common) from [<80026f90>]
(warn_slowpath_null+0x1c/0x24)
[    6.512797] [<80026f90>] (warn_slowpath_null) from [<80022044>]
(armctrl_xlate+0x188/0x274)
[    6.514558] [<80022044>] (armctrl_xlate) from [<8007399c>]
(irq_create_of_mapping+0x64/0x110)
[    6.517173] [<8007399c>] (irq_create_of_mapping) from [<804c4ef4>]
(irq_of_parse_and_map+0x24/0x2c)
[    6.518741] [<804c4ef4>] (irq_of_parse_and_map) from [<804c4f14>]
(of_irq_to_resource+0x18/0xb8)
[    6.520209] [<804c4f14>] (of_irq_to_resource) from [<804c4ff0>]
(of_irq_to_resource_table+0x3c/0x54)
[    6.523598] [<804c4ff0>] (of_irq_to_resource_table) from
[<804c25b8>] (of_device_alloc+0xd8/0x180)
[    6.528838] [<804c25b8>] (of_device_alloc) from [<804c26a8>]
(of_platform_device_create_pdata+0x48/0x98)
[    6.535352] [<804c26a8>] (of_platform_device_create_pdata) from
[<804c27f0>] (of_platform_bus_create+0xec/0x3ac)
[    6.539440] [<804c27f0>] (of_platform_bus_create) from [<804c2860>]
(of_platform_bus_create+0x15c/0x3ac)
[    6.541217] [<804c2860>] (of_platform_bus_create) from [<804c2c28>]
(of_platform_populate+0x5c/0xa0)
[    6.542770] [<804c2c28>] (of_platform_populate) from [<8088cad8>]
(bcm2709_init+0x64/0x3fc)
[    6.546211] [<8088cad8>] (bcm2709_init) from [<80888870>]
(customize_machine+0x20/0x40)
[    6.547711] [<80888870>] (customize_machine) from [<800088bc>]
(do_one_initcall+0xd8/0x208)
[    6.549200] [<800088bc>] (do_one_initcall) from [<80885ef4>]
(kernel_init_freeable+0x1fc/0x29c)
[    6.551771] [<80885ef4>] (kernel_init_freeable) from [<805f9298>]
(kernel_init+0x8/0xf0)
[    6.553319] [<805f9298>] (kernel_init) from [<8000efe8>]
(ret_from_fork+0x14/0x2c)
[    6.556670] ---[ end trace 088ba587f0a009cc ]---
[    6.649948] No ATAGs?
[    6.658029] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4
watchpoint registers.
[    6.660393] hw-breakpoint: maximum watchpoint size is 8 bytes.
[    6.664206] mailbox: Broadcom VideoCore Mailbox driver
[    6.693912] bcm2708_vcio: mailbox at f300b880
[    6.703745] bcm_power: Broadcom power driver
[    6.707642] bcm_power_open() -> 0
[    6.708671] bcm_power_request(0, 8)
Quoted 3 lines

Does that look familiar? (My first guess is just that it wants some bit of hardware we haven't got a device model for yet. I haven't tried to investigate at all yet.)

I haven't seen that, probably because I was doing all my testing with an older release (2015-09-24). There appear to be two problems. The warning is something related to the interrupt controller, but it's hard to tell exactly what's wrong there because the function in question (armctl_xlate) doesn't appear to do any hardware access. The bcm_power_request wedge should be expected for anything that tries to interact with power management, because we don't model that device yet (the older Pi2 kernels didn't touch it).

However, I don't seem to be able to repro this. What exactly were you booting? On the current Raspbian (2016-02-26-raspbian-jessie-lite), I run into a different bug, with stalled MMC commands:

[    9.167683] mmc0: command never completed.
[    9.172133] mmc0:>cmd op 52 arg 0xc00 flags 0x195 - resp 00000000 00000000 00000000 00000000, err 0
[    9.180379] mmc0: =========== REGISTER DUMP ===========
[    9.187193] mmc0: SDCMD  0x00008034
[    9.190113] mmc0: SDARG  0x00000c00
[    9.192952] mmc0: SDTOUT 0x00f00000
[    9.196064] mmc0: SDCDIV 0x0000026f
[    9.199091] mmc0: SDRSP0 0x00000000
[    9.201915] mmc0: SDRSP1 0x00000000
[    9.204915] mmc0: SDRSP2 0x00000000
[    9.207672] mmc0: SDRSP3 0x00000000
[    9.210453] mmc0: SDHSTS 0x000007f8
[    9.213612] mmc0: SDVDD  0x00000001
[    9.216977] mmc0: SDEDM  0x00010800
[    9.219728] mmc0: SDHCFG 0x0000040a
[    9.222666] mmc0: SDHBCT 0x00000000
[    9.228116] mmc0: SDHBLC 0x00000000
[    9.230866] mmc0: ===========================================

Cheers,
Andrew

#10 lore raw
In reply to Andrew Baumann

Hi,

Quoted 10 lines
[    9.167683] mmc0: command never completed.
[    9.172133] mmc0:>cmd op 52 arg 0xc00 flags 0x195 - resp 00000000 00000000 00000000 00000000, err 0
[    9.180379] mmc0: =========== REGISTER DUMP ===========
[    9.187193] mmc0: SDCMD  0x00008034
[    9.190113] mmc0: SDARG  0x00000c00
[    9.192952] mmc0: SDTOUT 0x00f00000
[    9.196064] mmc0: SDCDIV 0x0000026f
[    9.199091] mmc0: SDRSP0 0x00000000
[    9.201915] mmc0: SDRSP1 0x00000000
[    9.204915] mmc0: SDRSP2 0x00000000
Quoted 8 lines
[    9.207672] mmc0: SDRSP3 0x00000000
[    9.210453] mmc0: SDHSTS 0x000007f8
[    9.213612] mmc0: SDVDD  0x00000001
[    9.216977] mmc0: SDEDM  0x00010800
[    9.219728] mmc0: SDHCFG 0x0000040a
[    9.222666] mmc0: SDHBCT 0x00000000
[    9.228116] mmc0: SDHBLC 0x00000000
[    9.230866] mmc0: ===========================================

Saw that one too (4.4 kernel).

Also I had to remove the rng from the device tree to come that far in the first place, otherwise the kernel hangs earlier when trying to initialize the rng.

cheers,
Gerd