[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC for-4.8 5/6] xen/arm: Add an mmio-sram device



From: "Edgar E. Iglesias" <edgar.iglesias@xxxxxxxxxx>

Add an mmio-sram device. This device takes care of mapping
mmio-sram regions as MEMORY as opposed to the generic DT
mappings as DEVICE.

We only map the outer regions as children of mmio-sram nodes
describe allocations within it that really only mean something
to the guest.

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xxxxxxxxxx>
---
 xen/arch/arm/Makefile    |  1 +
 xen/arch/arm/mmio-sram.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100644 xen/arch/arm/mmio-sram.c

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index ead0cc0..224c9ae 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -18,6 +18,7 @@ obj-y += io.o
 obj-y += irq.o
 obj-y += kernel.o
 obj-y += mm.o
+obj-y += mmio-sram.o
 obj-y += p2m.o
 obj-y += percpu.o
 obj-y += guestcopy.o
diff --git a/xen/arch/arm/mmio-sram.c b/xen/arch/arm/mmio-sram.c
new file mode 100644
index 0000000..e0dbf7c
--- /dev/null
+++ b/xen/arch/arm/mmio-sram.c
@@ -0,0 +1,92 @@
+/*
+ * xen/arch/arm/mmio-sram.c
+ *
+ * MMIO-SRAM
+ *
+ * Edgar E. Iglesias <edgar.iglesias@xxxxxxxxxx>
+ * Copyright (c) 2016 Xilinx Inc.
+ *
+ * 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.
+ */
+
+#include <xen/config.h>
+#include <xen/lib.h>
+#include <xen/init.h>
+#include <xen/mm.h>
+#include <xen/iocap.h>
+#include <xen/sched.h>
+#include <xen/errno.h>
+#include <xen/list.h>
+#include <xen/device_tree.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/sizes.h>
+#include <asm/domain.h>
+#include <asm/platform.h>
+#include <asm/device.h>
+
+// #define DEBUG_DT
+
+#ifdef DEBUG_DT
+# define DPRINT(fmt, args...) printk(XENLOG_DEBUG fmt, ##args)
+#else
+# define DPRINT(fmt, args...) do {} while ( 0 )
+#endif
+
+static int sram_map(struct domain *d, struct dt_device_node *dev)
+{
+       unsigned int naddr;
+       u64 addr, size;
+       int res = 0;
+       int i;
+
+       naddr = dt_number_of_address(dev);
+
+       /* Give perms to access the region.  */
+       res = iomem_permit_access(d, paddr_to_pfn(addr),
+                                 paddr_to_pfn(PAGE_ALIGN(addr + size - 1)));
+
+       /*
+        * Map the memory regions.
+        *
+        * We only map the outer regions. Child regions represent
+        * sub allocations that really are the guest's business.
+        */
+       for (i = 0; i < naddr; i++)
+       {
+               res = dt_device_get_address(dev, i, &addr, &size);
+               if (res) {
+                       printk(XENLOG_ERR
+                               "Unable to retrieve address %u for %s\n",
+                               i, dt_node_full_name(dev));
+                       return res;
+               }
+
+               DPRINT("  - MEMORY: %s %010"PRIx64" - %010"PRIx64"\n",
+                      dt_node_full_name(dev), addr, addr + size);
+               res = map_regions_rwx_cache(d, paddr_to_pfn(addr & PAGE_MASK),
+                                           DIV_ROUND_UP(size, PAGE_SIZE),
+                                           paddr_to_pfn(addr & PAGE_MASK));
+               if (res)
+                       return res;
+       }
+       return res;
+}
+
+static const struct dt_device_match sram_dt_match[] __initconst =
+{
+       DT_MATCH_COMPATIBLE("mmio-sram"),
+       { /* sentinel */ },
+};
+
+DT_DEVICE_START(sram, "MMIO-SRAM", DEVICE_MEMORY)
+       .dt_match = sram_dt_match,
+       .map = sram_map,
+DT_DEVICE_END
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.