staging: ion: Add a default struct device for cma heap
PATCH 1/1 staging: ion: Add a default struct device for cma heap
When trying to use several cma heaps on our platforms, we met a memory issue due to that the several cma_heaps are sharing the same "struct device *".
As in current code base, the normal cma heap creating process is, one platform device is created during boot, and it will sequentially create cma heaps (usually passing its own struct device * as a parameter)
For the multiple cma heaps case, there will be one "struct cma" created for each cma heap, and this "struct cma *" is saved in dev->cma_area. So the single platform device can't meet the requirement here.
So this patch add one default device for a cma heap to avoid sharing the same "struct device", thus fix the issue. And it doesn't break existing code by only using that default device when no "struct device *" is passed in.
Also, since the cma framework has been cleaned up, this patch also add a platform data member to pass the "struct cma*" to ion_cma_heap_create().
--- drivers/staging/android/ion/ion.h | 4 ++++ drivers/staging/android/ion/ion_cma_heap.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/staging/android/ion/ion.h +4 -0
@@ -45,6 +45,9 @@ struct ion_buffer;* @size: size of the heap in bytes if applicable * @align: required alignment in physical memory if applicable * @priv: private info passed from the board file +* @priv2: when creating CMA heap, platform device should better also +* pass the "struct cma *" info, so that the cma buffer request +* know where to go for the buffer * * Provided by the board file. */
@@ -56,6 +59,7 @@ struct ion_platform_heap {size_t size;ion_phys_addr_t align;void *priv; +void *priv2; };/**
drivers/staging/android/ion/ion_cma_heap.c +17 -3
@@ -29,6 +29,7 @@struct ion_cma_heap {struct ion_heap heap;struct device *dev; +struct device default_dma_dev; };#define to_cma_heap (x) container_of(x, struct ion_cma_heap, heap)
@@ -180,9 +181,22 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)return ERR_PTR (-ENOMEM ); cma_heap->heap.ops = &ion_cma_ops; -/* get device from private heaps data, later it will be -* used to make the link with reserved CMA memory */ - cma_heap->dev = data->priv; + +/* +* data->priv for cma heap is currently supposed to point +* to a "struct device *" +*/ +if (data->priv) { + cma_heap->dev = data->priv; + }else { + cma_heap->dev = &cma_heap->default_dma_dev; + cma_heap->dev->coherent_dma_mask =DMA_BIT_MASK (32 ); + cma_heap->dev->dma_mask = &dev->coherent_dma_mask; + } + +/* data->priv2 contains a pointer to struct cma */ +dev_set_cma_area (cma_heap->dev, data->priv2); + cma_heap->heap.type =ION_HEAP_TYPE_DMA ;return &cma_heap->heap; }
Signature · 1 line
1.7.9.5
Quoted 19 lines · Feng Tang
When trying to use several cma heaps on our platforms, we met a memory issue due to that the several
cma_heapsare sharing the same "struct device *".As in current code base, the normal cma heap creating process is, one platform device is created during boot, and it will sequentially create cma heaps (usually passing its own struct device * as a parameter)
For the multiple cma heaps case, there will be one "struct cma" created for each cma heap, and this "struct cma *" is saved in
dev->cma_area. So the single platform device can't meet the requirement here.So this patch add one default device for a cma heap to avoid sharing the same "struct device", thus fix the issue. And it doesn't break existing code by only using that default device when no "struct device *" is passed in.
Quoted 7 lines
Also, since the cma framework has been cleaned up, this patch also add a platform data member to pass the "struct cma*" to
ion_cma_heap_create().Signed-off-by Feng Tang <[email protected]>From CMA’s point of view:
Quoted 20 lines
--- drivers/staging/android/ion/ion.h | 4 ++++ drivers/staging/android/ion/ion_cma_heap.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-)drivers/staging/android/ion/ion.h +3
-0@@ -45,6 +45,9 @@ struct ion_buffer;* @size: size of the heap in bytes if applicable * @align: required alignment in physical memory if applicable * @priv: private info passed from the board file +* @priv2: when creating CMA heap, platform device should better also +* pass the "struct cma *" info, so that the cma buffer request +* know where to go for the buffer * * Provided by the board file. */
drivers/staging/android/ion/ion.h struct ion_platform_heap { · line 62
Quoted 4 lines
drivers/staging/android/ion/ion.h +1
-0@@ -56,6 +59,7 @@ struct ion_platform_heap {size_t size;ion_phys_addr_t align;void *priv; +void *priv2;
Why are those void pointers anyway? Perhaps just make them struct device *dev and struct cma *cma? Especially since priv2 is a bit awkward name.
Quoted 27 lines
drivers/staging/android/ion/ion.h +0
-0};/** drivers/staging/android/ion/ion_cma_heap.c +6
-3@@ -29,6 +29,7 @@struct ion_cma_heap {struct ion_heap heap;struct device *dev; +struct device default_dma_dev; };#define to_cma_heap (x) container_of(x, struct ion_cma_heap, heap)@@ -180,9 +181,22 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)return ERR_PTR (-ENOMEM ); cma_heap->heap.ops = &ion_cma_ops; -/* get device from private heaps data, later it will be -* used to make the link with reserved CMA memory */ - cma_heap->dev = data->priv; + +/* +* data->priv for cma heap is currently supposed to point +* to a "struct device *" +*/
drivers/staging/android/ion/ion_cma_heap.c struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data) · line 198
Quoted 10 lines
drivers/staging/android/ion/ion_cma_heap.c +10
-0+if (data->priv) { + cma_heap->dev = data->priv; + }else { + cma_heap->dev = &cma_heap->default_dma_dev; + cma_heap->dev->coherent_dma_mask =DMA_BIT_MASK (32 ); + cma_heap->dev->dma_mask = &dev->coherent_dma_mask; + } + +/* data->priv2 contains a pointer to struct cma */ +dev_set_cma_area (cma_heap->dev, data->priv2);
Perhaps:
+ if (data->priv2)
+ dev_set_cma_area(cma_heap->dev, data->priv2);
Quoted 7 lines
drivers/staging/android/ion/ion_cma_heap.c +1
-0+ cma_heap->heap.type =ION_HEAP_TYPE_DMA ;return &cma_heap->heap; }Signature · 1 line
1.7.9.5
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<[email protected]>--<xmpp:[email protected]>--ooO--(_)--Ooo--
Hi Michal,
Thanks for the review!
Quoted 49 lines · Michal Nazarewicz
Quoted 19 lines · Feng Tang
When trying to use several cma heaps on our platforms, we met a memory issue due to that the several
cma_heapsare sharing the same "struct device *".As in current code base, the normal cma heap creating process is, one platform device is created during boot, and it will sequentially create cma heaps (usually passing its own struct device * as a parameter)
For the multiple cma heaps case, there will be one "struct cma" created for each cma heap, and this "struct cma *" is saved in
dev->cma_area. So the single platform device can't meet the requirement here.So this patch add one default device for a cma heap to avoid sharing the same "struct device", thus fix the issue. And it doesn't break existing code by only using that default device when no "struct device *" is passed in.
Quoted 7 lines
Also, since the cma framework has been cleaned up, this patch also add a platform data member to pass the "struct cma*" to
ion_cma_heap_create().Signed-off-by Feng Tang <[email protected]>From CMA’s point of view:
Quoted 19 lines
--- drivers/staging/android/ion/ion.h | 4 ++++ drivers/staging/android/ion/ion_cma_heap.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-)drivers/staging/android/ion/ion.h +3
-0@@ -45,6 +45,9 @@ struct ion_buffer;* @size: size of the heap in bytes if applicable * @align: required alignment in physical memory if applicable * @priv: private info passed from the board file +* @priv2: when creating CMA heap, platform device should better also +* pass the "struct cma *" info, so that the cma buffer request +* know where to go for the buffer * * Provided by the board file. */
Quoted 8 lines
drivers/staging/android/ion/ion.h struct ion_platform_heap { · line 62
Quoted 5 lines
drivers/staging/android/ion/ion.h +1
-0@@ -56,6 +59,7 @@ struct ion_platform_heap {size_t size;ion_phys_addr_t align;void *priv; +void *priv2;Why are those void pointers anyway? Perhaps just make them struct device *dev and struct cma *cma? Especially since priv2 is a bit awkward name.
My initial thought is the same, but as there are several other kinds of ion heaps which are also using this structure for their own ion_xxx_heap_create(struct ion_platform_heap *), I gave up using the explicit "struct cma *", in case other kinds of heaps may need to use this additional priv2 in future
Quoted 16 lines
drivers/staging/android/ion/ion.h struct ion_platform_heap {
Quoted 13 lines
drivers/staging/android/ion/ion.h +13
-0+* data->priv for cma heap is currently supposed to point +* to a "struct device *" +*/ +if (data->priv) { + cma_heap->dev = data->priv; + }else { + cma_heap->dev = &cma_heap->default_dma_dev; + cma_heap->dev->coherent_dma_mask =DMA_BIT_MASK (32 ); + cma_heap->dev->dma_mask = &dev->coherent_dma_mask; + } + +/* data->priv2 contains a pointer to struct cma */ +dev_set_cma_area (cma_heap->dev, data->priv2);Perhaps:
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (data->priv2) + dev_set_cma_area(cma_heap->dev, data->priv2);
Yes, this looks more logical, even though the cma_heap structure is kzalloced.
Thanks,
Feng
Greg Kroah-Hartman
maintainerQuoted 63 lines · Feng Tang
Hi Michal,
Thanks for the review!
Quoted 49 lines · Michal Nazarewicz
Quoted 19 lines · Feng Tang
When trying to use several cma heaps on our platforms, we met a memory issue due to that the several
cma_heapsare sharing the same "struct device *".As in current code base, the normal cma heap creating process is, one platform device is created during boot, and it will sequentially create cma heaps (usually passing its own struct device * as a parameter)
For the multiple cma heaps case, there will be one "struct cma" created for each cma heap, and this "struct cma *" is saved in
dev->cma_area. So the single platform device can't meet the requirement here.So this patch add one default device for a cma heap to avoid sharing the same "struct device", thus fix the issue. And it doesn't break existing code by only using that default device when no "struct device *" is passed in.
Quoted 7 lines
Also, since the cma framework has been cleaned up, this patch also add a platform data member to pass the "struct cma*" to
ion_cma_heap_create().Signed-off-by Feng Tang <[email protected]>From CMA’s point of view:
Quoted 19 lines
--- drivers/staging/android/ion/ion.h | 4 ++++ drivers/staging/android/ion/ion_cma_heap.c | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-)drivers/staging/android/ion/ion.h +3
-0@@ -45,6 +45,9 @@ struct ion_buffer;* @size: size of the heap in bytes if applicable * @align: required alignment in physical memory if applicable * @priv: private info passed from the board file +* @priv2: when creating CMA heap, platform device should better also +* pass the "struct cma *" info, so that the cma buffer request +* know where to go for the buffer * * Provided by the board file. */ Quoted 8 lines
drivers/staging/android/ion/ion.h struct ion_platform_heap { · line 62
Quoted 5 lines
drivers/staging/android/ion/ion.h +1
-0@@ -56,6 +59,7 @@ struct ion_platform_heap {size_t size;ion_phys_addr_t align;void *priv; +void *priv2;Why are those void pointers anyway? Perhaps just make them struct device *dev and struct cma *cma? Especially since priv2 is a bit awkward name.
Quoted 5 lines
My initial thought is the same, but as there are several other kinds of ion heaps which are also using this structure for their own
ion_xxx_heap_create(struct ion_platform_heap *), I gave up using the explicit "struct cma *", in case other kinds of heaps may need to use this additional priv2 in future
No, just make it a struct cma *, as that's what it is. Having multiple void * is a sign of a very crazy interface.
thanks,
greg k-h