From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: xen-devel@lists.xen.org
Cc: edgar.iglesias@xilinx.com, julien.grall@arm.com, sstabellini@kernel.org
Subject: [RFC for-4.8 5/6] xen/arm: Add an mmio-sram device
Date: Fri, 20 May 2016 17:51:27 +0200 [thread overview]
Message-ID: <1463759488-11900-6-git-send-email-edgar.iglesias@gmail.com> (raw)
In-Reply-To: <1463759488-11900-1-git-send-email-edgar.iglesias@gmail.com>
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
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@xilinx.com>
---
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@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
--
2.5.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-05-20 15:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 15:51 [RFC for-4.8 0/6] xen/arm: Add support for mapping mmio-sram nodes into dom0 Edgar E. Iglesias
2016-05-20 15:51 ` [RFC for-4.8 1/6] xen/arm: Add device_get_desc() Edgar E. Iglesias
2016-05-20 15:51 ` [RFC for-4.8 2/6] xen/arm: Add an optional map function to the device descriptor Edgar E. Iglesias
2016-05-20 15:51 ` [RFC for-4.8 3/6] xen/arm: Add a DEVICE_MEMORY class Edgar E. Iglesias
2016-05-20 15:51 ` [RFC for-4.8 4/6] xen/arm: Add helper functions to map RWX memory regions Edgar E. Iglesias
2016-05-23 15:36 ` Julien Grall
2016-05-24 14:14 ` Edgar E. Iglesias
2016-05-20 15:51 ` Edgar E. Iglesias [this message]
2016-05-20 15:51 ` [RFC for-4.8 6/6] xen/arm: Avoid multiple dev class lookups in handle_node Edgar E. Iglesias
2016-05-23 10:29 ` [RFC for-4.8 0/6] xen/arm: Add support for mapping mmio-sram nodes into dom0 Julien Grall
2016-05-23 11:56 ` Edgar E. Iglesias
2016-05-23 13:02 ` Julien Grall
2016-05-23 14:02 ` Edgar E. Iglesias
2016-05-23 15:13 ` Julien Grall
2016-05-23 15:42 ` Edgar E. Iglesias
2016-05-24 19:44 ` Julien Grall
2016-05-25 9:43 ` Stefano Stabellini
2016-05-25 9:52 ` Julien Grall
2016-05-25 10:00 ` Stefano Stabellini
2016-05-25 10:35 ` Edgar E. Iglesias
2016-05-25 13:29 ` Edgar E. Iglesias
2016-05-25 14:24 ` Julien Grall
2016-06-03 13:10 ` Edgar E. Iglesias
2016-05-25 9:31 ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463759488-11900-6-git-send-email-edgar.iglesias@gmail.com \
--to=edgar.iglesias@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).