@@ -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
new file mode 100644
@@ -0,0 +1,92 @@
+/*
+ * xen/arch/arm/mmio-sram.c
+ *
+ * MMIO-SRAM
+ *
+ * Edgar E. Iglesias <edgar.iglesias@xilinx.com>
+ * 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