From: KyongHo Cho <pullip.cho@samsung.com>
To: KyongHo Cho <pullip.cho@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>,
Kukjin Kim <kgene.kim@samsung.com>,
Inho Lee <ilho215.lee@samsung.com>,
Inki Dae <inki.dae@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ankita Garg <ankita@in.ibm.com>,
Daniel Walker <dwalker@codeaurora.org>,
Johan MOSSBERG <johan.xx.mossberg@stericsson.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Mel Gorman <mel@csn.ul.ie>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-mm@kvack.org, linux-samsung-soc@vger.kernel.org,
Michal Nazarewicz <m.nazarewicz@samsung.com>
Subject: [RFCv2,4/8] mm: vcm: VCM VMM driver added
Date: Fri, 17 Dec 2010 12:56:23 +0900 [thread overview]
Message-ID: <1292558187-17348-5-git-send-email-pullip.cho@samsung.com> (raw)
In-Reply-To: <1292558187-17348-4-git-send-email-pullip.cho@samsung.com>
From: Michal Nazarewicz <m.nazarewicz@samsung.com>
This commit adds a VCM VMM driver that handles kernl virtual
address space mappings. The VCM context is available as a static
object vcm_vmm. It is mostly just a wrapper around vmap()
function.
Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com>
---
Documentation/virtual-contiguous-memory.txt | 22 +++++-
include/linux/vcm.h | 13 +++
mm/vcm.c | 108 +++++++++++++++++++++++++++
3 files changed, 140 insertions(+), 3 deletions(-)
diff --git a/Documentation/virtual-contiguous-memory.txt b/Documentation/virtual-contiguous-memory.txt
index 10a0638..c830b69 100644
--- a/Documentation/virtual-contiguous-memory.txt
+++ b/Documentation/virtual-contiguous-memory.txt
@@ -510,6 +510,25 @@ state.
The following VCM drivers are provided:
+** Virtual Memory Manager driver
+
+Virtual Memory Manager driver is available as vcm_vmm and lets one map
+VCM managed physical memory into kernel space. The calls that this
+driver supports are:
+
+ vcm_make_binding()
+ vcm_destroy_binding()
+
+ vcm_alloc()
+
+ vcm_map()
+ vcm_unmap()
+
+vcm_map() is likely to work with physical memory allocated in context
+of other drivers as well (the only requirement is that "page" field of
+struct vcm_phys_part will be set for all physically contiguous parts
+and that each part's size will be multiply of PAGE_SIZE).
+
** Real hardware drivers
There are no real hardware drivers at this time.
@@ -793,6 +812,3 @@ rewritten by Michal Nazarewicz <m.nazarewicz@samsung.com>.
The new version is still lacking a few important features. Most
notably, no real hardware MMU has been implemented yet. This may be
ported from original Zach's proposal.
-
-Also, support for VMM is lacking. This is another thing that can be
-ported from Zach's proposal.
diff --git a/include/linux/vcm.h b/include/linux/vcm.h
index 3d54f18..800b5a0 100644
--- a/include/linux/vcm.h
+++ b/include/linux/vcm.h
@@ -295,4 +295,17 @@ int __must_check vcm_activate(struct vcm *vcm);
*/
void vcm_deactivate(struct vcm *vcm);
+/**
+ * vcm_vmm - VMM context
+ *
+ * Context for manipulating kernel virtual mappings. Reserve as well
+ * as rebinding is not supported by this driver. Also, all mappings
+ * are always active (till unbound) regardless of calls to
+ * vcm_activate().
+ *
+ * After mapping, the start field of struct vcm_res should be cast to
+ * pointer to void and interpreted as a valid kernel space pointer.
+ */
+extern struct vcm vcm_vmm[1];
+
#endif
diff --git a/mm/vcm.c b/mm/vcm.c
index 6804114..cd9f4ee 100644
--- a/mm/vcm.c
+++ b/mm/vcm.c
@@ -16,6 +16,7 @@
#include <linux/vcm-drv.h>
#include <linux/module.h>
#include <linux/mm.h>
+#include <linux/vmalloc.h>
#include <linux/err.h>
#include <linux/slab.h>
@@ -305,6 +306,113 @@ void vcm_deactivate(struct vcm *vcm)
EXPORT_SYMBOL_GPL(vcm_deactivate);
+/****************************** VCM VMM driver ******************************/
+
+static void vcm_vmm_cleanup(struct vcm *vcm)
+{
+ /* This should never be called. vcm_vmm is a static object. */
+ BUG_ON(1);
+}
+
+static struct vcm_phys *
+vcm_vmm_phys(struct vcm *vcm, resource_size_t size, unsigned flags)
+{
+ static const unsigned char orders[] = { 0 };
+ return vcm_phys_alloc(size, flags, orders);
+}
+
+static void vcm_vmm_unreserve(struct vcm_res *res)
+{
+ kfree(res);
+}
+
+struct vcm_res *vcm_vmm_map(struct vcm *vcm, struct vcm_phys *phys,
+ unsigned flags)
+{
+ /*
+ * Original implementation written by Cho KyongHo
+ * (pullip.cho@samsung.com). Later rewritten by mina86.
+ */
+ struct vcm_phys_part *part;
+ struct page **pages, **p;
+ struct vcm_res *res;
+ int ret = -ENOMEM;
+ unsigned i;
+
+ pages = kmalloc((phys->size >> PAGE_SHIFT) * sizeof *pages, GFP_KERNEL);
+ if (!pages)
+ return ERR_PTR(-ENOMEM);
+ p = pages;
+
+ res = kmalloc(sizeof *res, GFP_KERNEL);
+ if (!res)
+ goto error_pages;
+
+ i = phys->count;
+ part = phys->parts;
+ do {
+ unsigned j = part->size >> PAGE_SHIFT;
+ struct page *page = part->page;
+ if (!page)
+ goto error_notsupp;
+ do {
+ *p++ = page++;
+ } while (--j);
+ } while (++part, --i);
+
+ res->start = (dma_addr_t)vmap(pages, p - pages, VM_ALLOC, PAGE_KERNEL);
+ if (!res->start)
+ goto error_res;
+
+ kfree(pages);
+ res->res_size = phys->size;
+ return res;
+
+error_notsupp:
+ ret = -EOPNOTSUPP;
+error_res:
+ kfree(res);
+error_pages:
+ kfree(pages);
+ return ERR_PTR(ret);
+}
+
+static void vcm_vmm_unbind(struct vcm_res *res)
+{
+ vunmap((void *)res->start);
+}
+
+static int vcm_vmm_activate(struct vcm *vcm)
+{
+ /* no operation, all bindings are immediately active */
+ return 0;
+}
+
+static void vcm_vmm_deactivate(struct vcm *vcm)
+{
+ /*
+ * no operation, all bindings are immediately active and
+ * cannot be deactivated unless unbound.
+ */
+}
+
+struct vcm vcm_vmm[1] = { {
+ .start = 0,
+ .size = ~(resource_size_t)0,
+ /* prevent activate/deactivate from being called */
+ .activations = ATOMIC_INIT(1),
+ .driver = &(const struct vcm_driver) {
+ .cleanup = vcm_vmm_cleanup,
+ .phys = vcm_vmm_phys,
+ .unbind = vcm_vmm_unbind,
+ .unreserve = vcm_vmm_unreserve,
+ .activate = vcm_vmm_activate,
+ .deactivate = vcm_vmm_deactivate,
+ }
+} };
+EXPORT_SYMBOL_GPL(vcm_vmm);
+
+
/****************************** VCM Drivers API *****************************/
struct vcm *__must_check vcm_init(struct vcm *vcm)
--
1.6.2.5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-12-17 4:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-17 3:56 [RFCv2,0/8] mm: vcm: The Virtual Memory Manager for multiple IOMMUs KyongHo Cho
2010-12-17 3:56 ` [RFCv2,1/8] mm: vcm: Virtual Contiguous Memory framework added KyongHo Cho
2010-12-17 3:56 ` [RFCv2,2/8] mm: vcm: reference counting on a reservation added KyongHo Cho
2010-12-17 3:56 ` [RFCv2,3/8] mm: vcm: physical memory allocator added KyongHo Cho
2010-12-17 3:56 ` KyongHo Cho [this message]
2010-12-17 3:56 ` [RFCv2,5/8] mm: vcm: VCM MMU wrapper added KyongHo Cho
2010-12-17 3:56 ` [RFCv2,6/8] mm: vcm: VCM One-to-One " KyongHo Cho
2010-12-17 3:56 ` [RFCv2,7/8] mm: vcm: vcm-cma: VCM CMA driver added KyongHo Cho
2010-12-17 3:56 ` [RFCv2,8/8] mm: vcm: Sample " KyongHo Cho
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=1292558187-17348-5-git-send-email-pullip.cho@samsung.com \
--to=pullip.cho@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=ankita@in.ibm.com \
--cc=dwalker@codeaurora.org \
--cc=ilho215.lee@samsung.com \
--cc=inki.dae@samsung.com \
--cc=johan.xx.mossberg@stericsson.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kgene.kim@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.nazarewicz@samsung.com \
--cc=m.szyprowski@samsung.com \
--cc=mel@csn.ul.ie \
/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