mm: vcm: The Virtual Memory Manager for multiple IOMMUs
Subsystems (5)
v2 cover mm: vcm: The Virtual Memory Manager for multiple IOMMUs
Hello,
The VCM is a framework to deal with multiple IOMMUs in a system
with intuitive and abstract objects
These patches are the bugfix and enhanced version of previous RFC by Michal Nazarewicz.
(https://patchwork.kernel.org/patch/157451/)
It is introduced by Zach Pfeffer and implemented by Michal Nazarewicz.
These patches include entirely new implementation of VCM than the one submitted by Zach Pfeffer.
The prerequisites of these patches are the followings by Michal Nazarewicz:
https://patchwork.kernel.org/patch/340281/
https://patchwork.kernel.org/patch/414381/
https://patchwork.kernel.org/patch/414541/
In addition to the above patches,
the prerequisites of "[RFCv2,7/8] mm: vcm: vcm-cma: VCM CMA driver added" is CMA RFCv8 introduced by Michal Nazarewicz:
https://patchwork.kernel.org/patch/414351/
The VCM also works correctly without "[RFC,6/7] mm: vcm: vcm-cma: VCM CMA driver added"
The last patch, "[RFC,7/7] mm: vcm: Sample driver added" is not the one to be submitted but is an example to show how to use the VCM.
The VCM provides generic interfaces and objects to deal with IOMMUs in various architectures especially the ones that embed multiple IOMMUs including GART.
Chagelog:
v2: 1. Added reference counting on a reservation.
When vcm_reserve() creates a reservation, it sets the reference counter of the reservation to 1. The ownership of the reservation is only owned by the caller of vcm_reserve. If the caller passes the reservation to another callee functions, the callee functions must increment the reference counter with vcm_ref_reserve() to set the ownership of the reservation. To release the ownership, just call vcm_unreserve(). vcm_unreserve decrements the reference counter of the given reservation. vcm_unreserve() eventually unreserves the reservation when its reference counter becomes 0.
2. Applied the design changes of CMA by Michal Nazarewicz.
Since it is dramatically changed, vcm-cma also followed.
Patch list:
[RFCv2,1/8] mm: vcm: Virtual Contiguous Memory framework added [RFCv2,2/8] mm: vcm: reference counting on a reservation added [RFCv2,3/8] mm: vcm: physical memory allocator added [RFCv2,4/8] mm: vcm: VCM VMM driver added [RFCv2,5/8] mm: vcm: VCM MMU wrapper added [RFCv2,6/8] mm: vcm: VCM One-to-One wrapper added [RFCv2,7/8] mm: vcm: vcm-cma: VCM CMA driver added [RFCv2,8/8] mm: vcm: Sample driver added
Summery:
Documentation/00-INDEX | 2 + Documentation/virtual-contiguous-memory.txt | 940 +++++++++++++++++++++++++ include/linux/vcm-cma.h | 38 + include/linux/vcm-drv.h | 326 +++++++++ include/linux/vcm-sample.h | 30 + include/linux/vcm.h | 311 +++++++++ mm/Kconfig | 79 +++ mm/Makefile | 3 + mm/vcm-cma.c | 99 +++ mm/vcm-sample.c | 119 ++++ mm/vcm.c | 987 +++++++++++++++++++++++++++ 11 files changed, 2934 insertions(+), 0 deletions(-)
create mode 100644 Documentation/virtual-contiguous-memory.txt create mode 100644 include/linux/vcm-cma.h
create mode 100644 include/linux/vcm-drv.h
create mode 100644 include/linux/vcm-sample.h
create mode 100644 include/linux/vcm.h
create mode 100644 mm/vcm-cma.c
create mode 100644 mm/vcm-sample.c
create mode 100644 mm/vcm.c
RFC v2 1/8 mm: vcm: Virtual Contiguous Memory framework added
From: Michal Nazarewicz <[email protected]>
This commit adds the Virtual Contiguous Memory framework which provides an abstraction for virtual address space provided by various MMUs present on the platform.
The framework uses plugable MMU drivers for hardware MMUs and if drivers obeys some limitations it can be also used on platforms with no MMU.
For more information see
<Documentation/virtual-contiguous-memory.txt>.
--- Documentation/00-INDEX | 2 + Documentation/virtual-contiguous-memory.txt | 720 +++++++++++++++++++++++++++ include/linux/vcm-drv.h | 117 +++++ include/linux/vcm.h | 275 ++++++++++ mm/Kconfig | 15 + mm/Makefile | 1 + mm/vcm.c | 304 +++++++++++ 7 files changed, 1434 insertions(+), 0 deletions(-) create mode 100644 Documentation/virtual-contiguous-memory.txt create mode 100644 include/linux/vcm-drv.h create mode 100644 include/linux/vcm.h create mode 100644 mm/vcm.c
Documentation/00-INDEX +2 -0
@@ -342,6 +342,8 @@ video-output.txt - sysfs class driver interface to enable/disable a video output device. video4linux/ - directory with info regarding video/TV/radio cards and linux. +virtual-contiguous-memory.txt + - documentation on virtual contiguous memory manager framework. vm/ - directory with info on the Linux vm code. volatile-considered-harmful.txt
Documentation/virtual-contiguous-memory.txt new file +720 -0
720 lines not on this page · raw message
include/linux/vcm-drv.h new file +117 -0
117 lines not on this page · raw message
include/linux/vcm.h new file +275 -0
275 lines not on this page · raw message
mm/Kconfig +15 -0
@@ -338,6 +338,21 @@ config CMA_DEBUG This is mostly used during development. If unsure, say "n". +config VCM + bool "Virtual Contiguous Memory framework" + help + This enables the Virtual Contiguous Memory framework which + provides an abstraction for virtual address space provided by + various MMUs present on the platform. + + The framework uses plugable MMU drivers for hardware MMUs and + if drivers obeys some limitations it can be also used on + platforms with no MMU. + + For more information see + <Documentation/virtual-contiguous-memory.txt>. If unsure, say + "n". + # # UP and nommu archs use km based percpu allocator #
mm/Makefile +1 -0
@@ -43,3 +43,4 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o obj-$(CONFIG_CMA) += cma.o +obj-$(CONFIG_VCM) += vcm.o
mm/vcm.c new file +304 -0
304 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 2/8 mm: vcm: reference counting on a reservation added
This commits adds vcm_ref_reserve() and refcnt member into vcm_res structure. This feature is enabled by turnning on CONFIG_VCM_RES_REFCNT. This enables the users of the vcm framework not to care about the sequence of reserving and unreserving in complex scenarios.
--- Documentation/virtual-contiguous-memory.txt | 47 +++++++++++++++++++++++++++ include/linux/vcm.h | 23 +++++++++++++ mm/Kconfig | 7 ++++ mm/vcm.c | 17 ++++++++++ 4 files changed, 94 insertions(+), 0 deletions(-)
Documentation/virtual-contiguous-memory.txt +47 -0
@@ -275,6 +275,34 @@ To deactivate the VCM context vcm_deactivate() function is used: Both of those functions can be called several times if all calls to vcm_activate() are paired with a later call to vcm_deactivate(). +** Aquiring and releasing ownership of a reservation + +Once a device driver reserve a reservation, it may want to pass other device +drivers or attach the reservation in a data structre. Since the reservation +may be shared among many device drivers, the VCM context is needed to provide +a simple way to unreserve a reservation. + +Below 2 functions gives the ownership of a reservation to the caller: + + struct vcm_res *__must_check + vcm_reserve(struct vcm *vcm, resource_size_t size, unsigned flags); + + int __must_check vcm_ref_reserve(struct vcm_res *res); + +vcm_reserve() creates a new reservation, thus the first owner of the +reservation is set to the caller of vcm_reservation(). It then passes to a +function the reservation. The function that received the reservation calls +vcm_ref_reserve() to acquire the ownership of the given reservation. If the +function decides that it does not need the reservation any more, it calls +vcm_release() to release the ownership of the reservation. + + void vcm_unreserve(struct vcm_res *res); + +It is not required to determine if other functions and drivers still need to +access the reservation because this function just release the ownership of the +reservation. If vcm_unreserve() finds no one has the ownership of the given +reservation, only then does it unreserve (remove) the given reservation. + ** Device driver example The following is a simple, untested example of how platform and
@@ -706,6 +734,25 @@ automatically reflect new mappings on the hardware MMU. Neither of the operations are required and if missing, VCM will assume they are a no-operation and no warning will be generated. +*** Ownership of a reservation + +When to aquire the ownership of a reservation: + - When creating a new reservation (having the ownership automatically) + - When assigning a reservation to a member of data structure + - When a reservation is passed from the caller function + - When requiring to access a reservation (that is a global variable) + at first in its context. +The first one is done with vcm_reserve() and others with vcm_ref_reserve(). + +When to release the ownership of a reservation: + - When a reservation is no longer needed in its context. + - When returning from a function and the function received a reservation + from its caller and acquired the ownership of the reservation. + - When removing a reservation from a data structure that includes a pointer + to the reservation +It is not required as well unable to remove the reservation explicitly. The +last call to vcm_unreserve() will cause the reservation to be removed. + * Epilogue The initial version of the VCM framework was written by Zach Pfeffer
include/linux/vcm.h +23 -0
@@ -52,6 +52,9 @@ struct vcm {* @bound_size: number of bytes actually bound to the virtual address; * read only. * @res_size: size of the reserved address space in bytes; read only. +* @refcnt: reference count of a reservation to pass ownership of +* a reservation in a safe way; internal. +* Implemented only when CONFIG_VCM_RES_REFCNT is enabled. * @vcm: VCM context; internal, read only for MMU drivers. * @phys: pointer to physical memory bound to this reservation; NULL * if no physical memory is bound; read only.
@@ -65,6 +68,9 @@ struct vcm_res {dma_addr_t start;resource_size_t bound_size;resource_size_t res_size; +#ifdef CONFIG_VCM_RES_REFCNT +atomic_t refcnt; +#endif struct vcm *vcm;struct vcm_phys *phys;
@@ -180,6 +186,23 @@ struct vcm_res *__must_check vcm_reserve(struct vcm *vcm, resource_size_t size, unsigned flags);/** +* vcm_ref_reserve() - acquires the ownership of a reservation. +* @res: a valid reservation to access +* +* On success returns 0 and leads the same effect as vcm_reserve() in the +* context of the caller of this function. In other words, once a function +* acquire the ownership of a reservation with vcm_ref_reserve(), it must +* release the ownership with vcm_release() as soon as it does not need +* the reservation. +* +* On error returns -EINVAL. The only reason of the error is passing an invalid +* reservation like NULL or an unreserved reservation. +*/ +#ifdef CONFIG_VCM_RES_REFCNT +int __must_check vcm_ref_reserve (struct vcm_res *res); +#endif + +/** * vcm_unreserve() - destroyers a virtual address space reservation * @res: reservation to destroy. *
mm/Kconfig +7 -0
@@ -353,6 +353,13 @@ config VCM <Documentation/virtual-contiguous-memory.txt>. If unsure, say "n". +config VCM_RES_REFCNT + bool "Reference counting on reservations" + depends on VCM + help + This enables reference counting on a reservation to make sharing + and migrating the ownership of the reservation easier. + # # UP and nommu archs use km based percpu allocator #
mm/vcm.c +17 -0
@@ -156,10 +156,23 @@ vcm_reserve(struct vcm *vcm, resource_size_t size, unsigned flags)__vcm_alloc_and_reserve (vcm, size,NULL ,0 , &res, flags); +#ifdef CONFIG_VCM_RES_REFCNT +if (!IS_ERR (res)) +atomic_inc (&res->refcnt); +#endif +return res; }EXPORT_SYMBOL_GPL (vcm_reserve); +int __must_check vcm_ref_reserve (struct vcm_res *res) +{ +if (WARN_ON (!res) || (atomic_inc_return (&res->refcnt) <2 )) +return -EINVAL ; +return 0 ; +} +EXPORT_SYMBOL_GPL (vcm_ref_reserve); +struct vcm_res *__must_check vcm_map (struct vcm *vcm,struct vcm_phys *phys,unsigned flags) {
@@ -196,6 +209,10 @@ EXPORT_SYMBOL_GPL(vcm_map);void vcm_unreserve (struct vcm_res *res) {if (!WARN_ON (!res)) { +#ifdef CONFIG_VCM_RES_REFCNT +if (!atomic_dec_and_test (&res->refcnt)) +return ; +#endif if (WARN_ON (res->phys))vcm_unbind (res);if (!WARN_ON_ONCE (!res->vcm->driver->unreserve))
Signature · 1 line
1.6.2.5
RFC v2 3/8 mm: vcm: physical memory allocator added
From: Michal Nazarewicz <[email protected]>
This commits adds vcm_phys_alloc() function with some accompanying functions which allocates physical memory. This should be used from withing alloc or phys callback of a VCM driver if one does not want to provide its own allocator.
--- Documentation/virtual-contiguous-memory.txt | 31 ++++ include/linux/vcm-drv.h | 88 ++++++++++ mm/Kconfig | 9 + mm/vcm.c | 249 +++++++++++++++++++++++++++ 4 files changed, 377 insertions(+), 0 deletions(-)
Documentation/virtual-contiguous-memory.txt +31 -0
@@ -672,6 +672,37 @@ Both phys and alloc callbacks need to provide a free callbakc along with the vc_phys structure, which will, as one may imagine, free allocated space when user calls vcm_free(). +Unless VCM driver needs some special handling of physical memory, the +vcm_phys_alloc() function can be used: + + struct vcm_phys *__must_check + vcm_phys_alloc(resource_size_t size, unsigned flags, + const unsigned char *orders); + +The last argument of this function (orders) is an array of orders of +page sizes that function should try to allocate. This array must be +sorted from highest order to lowest and the last entry must be zero. + +For instance, an array { 8, 4, 0 } means that the function should try +and allocate 1MiB, 64KiB and 4KiB pages (this is assuming PAGE_SIZE is +4KiB which is true for all supported architectures). For example, if +requested size is 2MiB and 68 KiB, the function will try to allocate +two 1MiB pages, one 64KiB page and one 4KiB page. This may be useful +when the mapping is written to the MMU since the largest possible +pages will be used reducing the number of entries. + +The function allocates memory from DMA32 zone. If driver has some +other requirements (that is require different GFP flags) it can use +__vcm_phys_alloc() function which, besides arguments that +vcm_phys_alloc() accepts, take GFP flags as the last argument: + + struct vcm_phys *__must_check + __vcm_phys_alloc(resource_size_t size, unsigned flags, + const unsigned char *orders, gfp_t gfp); + +However, if those functions are used, VCM driver needs to select an +VCM_PHYS Kconfig option or oterwise they won't be available. + All those operations may assume that size is a non-zero and divisible by PAGE_SIZE.
include/linux/vcm-drv.h +88 -0
92 lines not on this page · raw message
mm/Kconfig +9 -0
@@ -360,6 +360,15 @@ config VCM_RES_REFCNT This enables reference counting on a reservation to make sharing and migrating the ownership of the reservation easier. +config VCM_PHYS + bool "VCM physical allocation wrappers" + depends on VCM && MODULES + help + This enables the vcm_phys family of functions provided for VCM + drivers. If a VCM driver is built that requires this option, it + will be automatically selected. You select it if you are going to + build external modules that will use this functionality. + # # UP and nommu archs use km based percpu allocator #
mm/vcm.c +249 -0
252 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 4/8 mm: vcm: VCM VMM driver added
From: Michal Nazarewicz <[email protected]>
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.
--- Documentation/virtual-contiguous-memory.txt | 22 +++++- include/linux/vcm.h | 13 +++ mm/vcm.c | 108 +++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 3 deletions(-)
Documentation/virtual-contiguous-memory.txt +19 -3
@@ -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 <[email protected]>. 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.
include/linux/vcm.h +13 -0
@@ -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
mm/vcm.c +108 -0
120 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 5/8 mm: vcm: VCM MMU wrapper added
From: Michal Nazarewicz <[email protected]>
This commits adds a VCM MMU wrapper which is meant to be a helper code for creating VCM drivers for real hardware MMUs.
--- Documentation/virtual-contiguous-memory.txt | 80 ++++++++++ include/linux/vcm-drv.h | 80 ++++++++++ mm/Kconfig | 11 ++ mm/vcm.c | 219 +++++++++++++++++++++++++++ 4 files changed, 390 insertions(+), 0 deletions(-)
Documentation/virtual-contiguous-memory.txt +80 -0
@@ -803,6 +803,86 @@ When to release the ownership of a reservation: It is not required as well unable to remove the reservation explicitly. The last call to vcm_unreserve() will cause the reservation to be removed. +** Writing a hardware MMU driver + +It may be undesirable to implement all of the operations that are +required to create a usable driver. In case of hardware MMUs a helper +wrapper driver has been created to make writing real drivers as simple +as possible. + +The wrapper implements most of the functionality of the driver leaving +only implementation of the actual talking to the hardware MMU in hands +of programmer. Reservations managements as general housekeeping is +already there. + +Note that to use the VCM MMU wrapper one needs to select the VCM_MMU +Kconfig option or otherwise the wrapper won't be available. + +*** Context creation + +Similarly to normal drivers, MMU driver needs to provide a context +creation function. Such a function must provide a vcm_mmu object and +initialise vcm.start, vcm.size and driver fields of the structure. +When this is done, vcm_mmu_init() should be called which will +initialise the rest of the fields and validate entered values: + + struct vcm *__must_check vcm_mmu_init(struct vcm_mmu *mmu); + +This is, in fact, very similar to the way standard driver is created. + +*** Orders + +One of the fields of the vcm_mmu_driver structure is orders. This is +an array of orders of pages supported by the hardware MMU. It must be +sorted from largest to smallest and zero terminated. + +The order is the logarithm with the base two of the size of supported +page size divided by PAGE_SIZE. For instance, { 8, 4, 0 } means that +MMU supports 1MiB, 64KiB and 4KiB pages. + +*** Operations + +The three operations that MMU wrapper driver uses are: + + void (*cleanup)(struct vcm *vcm); + + int (*activate)(struct vcm_res *res, struct vcm_phys *phys); + void (*deactivate)(struct vcm_res *res, struct vcm_phys *phys); + + int (*activate_page)(dma_addr_t vaddr, dma_addr_t paddr, + unsigned order, void *vcm), + int (*deactivate_page)(dma_addr_t vaddr, dma_addr_t paddr, + unsigned order, void *vcm), + +The first one frees all resources allocated by the context creation +function (including the structure itself). If this operation is not +given, kfree() will be called on vcm_mmu structure. + +The activate and deactivate operations are required and they are used +to update mappings in the MMU. Whenever binding is activated or +deactivated the respective operation is called. + +To divide mapping into physical pages, vcm_phys_walk() function can be +used: + + int vcm_phys_walk(dma_addr_t vaddr, const struct vcm_phys *phys, + const unsigned char *orders, + int (*callback)(dma_addr_t vaddr, dma_addr_t paddr, + unsigned order, void *priv), + int (*recovery)(dma_addr_t vaddr, dma_addr_t paddr, + unsigned order, void *priv), + void *priv); + +It start from given virtual address and tries to divide allocated +physical memory to as few pages as possible where order of each page +is one of the orders specified by orders argument. + +It may be easier to implement activate_page and deactivate_page +operations instead thought. They are called on each individual page +rather then the whole mapping. It basically incorporates call to the +vcm_phys_walk() function so driver does not need to call it +explicitly. + * Epilogue The initial version of the VCM framework was written by Zach Pfeffer
include/linux/vcm-drv.h +80 -0
86 lines not on this page · raw message
mm/Kconfig +11 -0
@@ -369,6 +369,17 @@ config VCM_PHYS will be automatically selected. You select it if you are going to build external modules that will use this functionality. +config VCM_MMU + bool "VCM MMU wrapper" + depends on VCM && MODULES + select VCM_PHYS + select GENERIC_ALLOCATOR + help + This enables the VCM MMU wrapper which helps creating VCM drivers + for IO MMUs. If a VCM driver is built that requires this option, it + will be automatically selected. You select it if you are going to + build external modules that will use this functionality. + # # UP and nommu archs use km based percpu allocator #
mm/vcm.c +219 -0
231 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 6/8 mm: vcm: VCM One-to-One wrapper added
From: Michal Nazarewicz <[email protected]>
This commits adds a VCM One-to-One wrapper which is meant to be a helper code for creating VCM drivers for "fake" MMUs, ie. situation where there is no real hardware MMU and memory must be contiguous physically and mapped directly to "virtual" address space.
--- Documentation/virtual-contiguous-memory.txt | 33 ++++++++++ include/linux/vcm-drv.h | 41 ++++++++++++ mm/Kconfig | 10 +++ mm/vcm.c | 90 +++++++++++++++++++++++++++ 4 files changed, 174 insertions(+), 0 deletions(-)
Documentation/virtual-contiguous-memory.txt +33 -0
@@ -883,6 +883,39 @@ rather then the whole mapping. It basically incorporates call to the vcm_phys_walk() function so driver does not need to call it explicitly. +** Writing a one-to-one VCM driver + +Similarly to a wrapper for a real hardware MMU a wrapper for +one-to-one VCM contexts has been created. It implements all of the +houskeeping operations and leaves only contiguous memory management +(that is allocating and freeing contiguous regions) to the VCM O2O +driver. + +As with other drivers, one-to-one driver needs to provide a context +creation function. It needs to allocate space for vcm_o2o structure +and initialise its vcm.start, vcm.end and driver fields. Calling +vcm_o2o_init() will fill the other fields and validate entered values: + + struct vcm *__must_check vcm_o2o_init(struct vcm_o2o *o2o); + +There are the following two operations used by the wrapper: + + void (*cleanup)(struct vcm *vcm); + struct vcm_phys *(*phys)(struct vcm *vcm, resource_size_t size, + unsigned flags); + +The cleanup operation cleans the context and frees all resources. If +not provided, kfree() is used. + +The phys operation is used in the same way as the core driver's phys +operation. The only difference is that it must return a physically +contiguous memory block -- ie. returned structure must have only one +part. On error, the operation must return an error-pointer. It is +required. + +Note that to use the VCM one-to-one wrapper one needs to select the +VCM_O2O Kconfig option or otherwise the wrapper won't be available. + * Epilogue The initial version of the VCM framework was written by Zach Pfeffer
include/linux/vcm-drv.h +41 -0
47 lines not on this page · raw message
mm/Kconfig +10 -0
@@ -380,6 +380,16 @@ config VCM_MMU will be automatically selected. You select it if you are going to build external modules that will use this functionality. +config VCM_O2O + bool "VCM O2O wrapper" + depends on VCM && MODULES + help + This enables the VCM one-to-one wrapper which helps creating VCM + drivers for devices without IO MMUs. If a VCM driver is built that + requires this option, it will be automatically selected. You select + it if you are going to build external modules that will use this + functionality. + # # UP and nommu archs use km based percpu allocator #
mm/vcm.c +90 -0
96 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 7/8 mm: vcm: vcm-cma: VCM CMA driver added
From: Michal Nazarewicz <[email protected]>
This commit adds a VCM driver that instead of using real hardware MMU emulates one and uses CMA for allocating contiguous memory chunks.
--- Documentation/virtual-contiguous-memory.txt | 12 +++- include/linux/vcm-cma.h | 38 ++++++++++ mm/Kconfig | 14 ++++ mm/Makefile | 1 + mm/vcm-cma.c | 99 +++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 1 deletions(-) create mode 100644 include/linux/vcm-cma.h create mode 100644 mm/vcm-cma.c
Documentation/virtual-contiguous-memory.txt +11 -1
@@ -552,7 +552,17 @@ well: If one uses vcm_unbind() then vcm_bind() on the same reservation, physical memory pair should also work. -There are no One-to-One drivers at this time. +*** VCM CMA + +VCM CMA driver is a One-to-One driver which uses CMA (see +[[file:contiguous-memory.txt][contiguous-memory.txt]]) to allocate physically contiguous memory. VCM +CMA context is created by calling: + + struct vcm *__must_check + vcm_cma_create(const char *regions, dma_addr_t alignment); + +Its first argument is the list of regions that CMA should try to +allocate memory from. The second argument is required alignment. * Writing a VCM driver
include/linux/vcm-cma.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Virtual Contiguous Memory driver for CMA header +* Copyright (c) 2010 by Samsung Electronics. +* Written by Michal Nazarewicz (m.nazarewicz at samsung.com) +* +* 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 optional) any later version of the license. +*/ + +/* +* See Documentation/virtual-contiguous-memory.txt for details. +*/ + +#ifndef __LINUX_VCM_CMA_H +#define __LINUX_VCM_CMA_H + +#include <linux/types.h> + +struct vcm ; + +/** +* vcm_cma_create() - creates a VCM context that fakes a hardware MMU +* @ctx: the cma context that is defined by the machine's implementation. +* from. +* @alignment: required alignment of allocations. +* +* This creates VCM context that can be used on platforms with no +* hardware MMU or for devices that aro conected to the bus directly. +* Because it does not represent real MMU it has some limitations: +* basically, vcm_alloc(), vcm_reserve() and vcm_bind() are likely to +* fail so vcm_make_binding() should be used instead. +*/ +struct vcm *__must_check +vcm_cma_create (struct cma *ctx,unsigned long alignment); + +#endif
mm/Kconfig +14 -0
@@ -390,6 +390,20 @@ config VCM_O2O it if you are going to build external modules that will use this functionality. +config VCM_CMA + bool "VCM CMA driver" + depends on VCM && CMA + select VCM_O2O + help + This enables VCM driver that instead of using a real hardware + MMU fakes one and uses a direct mapping. It provides a subset + of functionalities of a real MMU but if drivers limits their + use of VCM to only supported operations they can work on + both systems with and without MMU with no changes. + + For more information see + <Documentation/virtual-contiguous-memory.txt>. If unsure, say "n". + # # UP and nommu archs use km based percpu allocator #
mm/Makefile +1 -0
@@ -44,3 +44,4 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o obj-$(CONFIG_CMA) += cma.o obj-$(CONFIG_VCM) += vcm.o +obj-$(CONFIG_VCM_CMA) += vcm-cma.o
mm/vcm-cma.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC v2 8/8 mm: vcm: Sample driver added
This commit adds a sample Virtual Contiguous Memory framework driver. It handles no real hardware and is there only for demonstrating purposes.
* * * THIS COMMIT IS NOT FOR MERGING * * *
--- Documentation/virtual-contiguous-memory.txt | 3 + include/linux/vcm-sample.h | 30 +++++++ mm/Kconfig | 13 +++ mm/Makefile | 1 + mm/vcm-sample.c | 119 +++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 0 deletions(-) create mode 100644 include/linux/vcm-sample.h create mode 100644 mm/vcm-sample.c
Documentation/virtual-contiguous-memory.txt +3 -0
@@ -781,6 +781,9 @@ already there. Note that to use the VCM MMU wrapper one needs to select the VCM_MMU Kconfig option or otherwise the wrapper won't be available. +There is a sample driver provided which provides a template for real +drivers. It can be found in [[file:../mm/vcm-sample.c][mm/vcm-sample.c]] file. + *** Context creation Similarly to normal drivers, MMU driver needs to provide a context
include/linux/vcm-sample.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Virtual Contiguous Memory sample driver header file +* Copyright (c) 2010 by Samsung Electronics. +* Written by Michal Nazarewicz (m.nazarewicz at samsung.com) +* +* 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 optional) any later version of the license. +*/ + +/* +* See Documentation/virtual-contiguous-memory.txt for details. +*/ + +#ifndef __LINUX_VCM_SAMP_H +#define __LINUX_VCM_SAMP_H + +#include <linux/types.h> + +struct vcm ; + +/** +* vcm_samp_create() - creates a VCM context +* +* ... Documentation goes here ... +*/ +struct vcm *__must_check vcm_samp_create (/* ... */ ); + +#endif
mm/Kconfig +13 -0
@@ -430,6 +430,19 @@ config VCM_CMA For more information see <Documentation/virtual-contiguous-memory.txt>. If unsure, say "n". +config VCM_SAMP + bool "VCM sample driver" + depends on VCM + select VCM_MMU + help + This enables a sample driver for the VCM framework. This driver + does not handle any real harwdare. It's merely an template of + how for real drivers. + + For more information see + <Documentation/virtual-contiguous-memory.txt>. If unsure, say + "n". + # # UP and nommu archs use km based percpu allocator #
mm/Makefile +1 -0
@@ -46,3 +46,4 @@ obj-$(CONFIG_CMA) += cma.o obj-$(CONFIG_CMA_BEST_FIT) += cma-best-fit.o obj-$(CONFIG_VCM) += vcm.o obj-$(CONFIG_VCM_CMA) += vcm-cma.o +obj-$(CONFIG_VCM_SAMPLE) += vcm-sample.o
mm/vcm-sample.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.6.2.5