Introduce vpl011 support to guests started from Xen: it provides a
simple way to print output from a guest, as most guests come with a
pl011 driver. It is also able to provide a working console with
interrupt support.

Signed-off-by: Stefano Stabellini <stefa...@xilinx.com>
---
 xen/arch/arm/domain_build.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index b4f560f..ff65057 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1470,6 +1470,70 @@ static int make_timer_domU_node(const struct domain *d, 
void *fdt)
     return res;
 }
 
+static void set_interrupt(gic_interrupt_t *interrupt, unsigned int irq,
+                          unsigned int cpumask, unsigned int level)
+{
+    __be32 *cells = (__be32 *) interrupt;
+    int is_ppi = (irq < 32);
+
+    irq -= (is_ppi) ? 16: 32; /* PPIs start at 16, SPIs at 32 */
+
+    /* See linux Documentation/devictree/bindings/arm/gic.txt */
+    dt_set_cell(&cells, 1, is_ppi); /* is a PPI? */
+    dt_set_cell(&cells, 1, irq);
+    dt_set_cell(&cells, 1, (cpumask << 8) | level);
+}
+
+#ifdef CONFIG_SBSA_VUART_CONSOLE
+static int make_vpl011_uart_node(const struct domain *d, void *fdt,
+                                 int addrcells, int sizecells)
+{
+    int res;
+    gic_interrupt_t intr;
+    int reg_size = addrcells + sizecells;
+    int nr_cells = reg_size;
+    __be32 reg[nr_cells];
+    __be32 *cells;
+
+    res = fdt_begin_node(fdt, "sbsa-pl011");
+    if (res)
+        return res;
+
+    res = fdt_property_string(fdt, "compatible", "arm,sbsa-uart");
+    if (res)
+        return res;
+
+    cells = &reg[0];
+    dt_child_set_range(&cells, addrcells, sizecells, GUEST_PL011_BASE,
+            GUEST_PL011_SIZE);
+    if (res)
+        return res;
+    res = fdt_property(fdt, "reg", reg, sizeof(reg));
+    if (res)
+        return res;
+
+    set_interrupt(&intr, GUEST_VPL011_SPI, 0xf, DT_IRQ_TYPE_LEVEL_HIGH);
+
+    res = fdt_property(fdt, "interrupts", intr, sizeof (intr));
+    if (res)
+        return res;
+
+    res = fdt_property_cell(fdt, "interrupt-parent",
+                            PHANDLE_GIC);
+    if (res)
+        return res;
+
+    /* Use a default baud rate of 115200. */
+    fdt_property_u32(fdt, "current-speed", 115200);
+
+    res = fdt_end_node(fdt);
+    if (res)
+        return res;
+
+    return 0;
+}
+#endif
+
 #define DOMU_DTB_SIZE 4096
 static int prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
 {
@@ -1531,6 +1595,12 @@ static int prepare_dtb_domU(struct domain *d, struct 
kernel_info *kinfo)
     if ( ret )
         goto err;
 
+#ifdef CONFIG_SBSA_VUART_CONSOLE
+    ret = make_vpl011_uart_node(d, kinfo->fdt, addrcells, sizecells);
+    if ( ret )
+        goto err;
+#endif
+
     ret = fdt_end_node(kinfo->fdt);
     if ( ret < 0 )
         goto err;
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to