Re: [PATCH] mm/cma.c: find a named CMA area by name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14.01.20 17:02, David Hildenbrand<david@xxxxxxxxxx> wrote:
From: david <david@xxxxxxxxxx>

*could help* - if there is no user, why do we need it? Or do you have a
user?


Hi David:
    With the continuous development of video and AI technology, device request
    lots of continuous physical memory. In some cases, in order to ensure device
    obtain continuous physical memory and also aovid debris which create by other 
    device. Based on the above situation, some device need exclusive a special
    named CMA area.

    On CMA, the system support multiple named or anonymous CMA areas, and we can 
    establish CMA area with name on DTS, as follow:

    / {
        reserved-memory {
            #address-cells = <1>;
            #size-cells = <1>;
            ranges;

            linux,cma {
                compatible = "shared-dma-pool";
                reusable;
                size = <0x00800000>; /* 8M */
                alloc-ranges = <0x69000000 0x00800000>;
                linux,cma-default;
            };

            CMA0 { /* Scaler */
                compatible = "shared-dma-pool";
                reusable;
                size = <0x00800000>; /* 8M */
                alloc-ranges = <0x6A000000 0x00800000>;
            };

            CMA1 { /* DECODE */
                compatible = "shared-dma-pool";
                reusable;
                size = <0x00800000>; /* 8M */
                alloc-ranges = <0x6B000000 0x00800000>
            };

            CMA_vpm {
                compatible = "shared-dma-pool";
                reusable;
                size = <0x00800000>; /* 8M */
                alloc-ranges = <0x6C000000 0x00800000>;
            };
        };
    }
    

    As shown above, the system will establish 4 CMA area, and all CMA areas is named 
    CMA area. such as “default"、"CMA0"、"CMA1"、and "CMA_vpm". Some device
    must use or exclusive a special CMA area, so device will process as follow:

    Device A:

    static int XA_probe(struct platform_device *pdev)
    {
        struct cma *cma;

        cma = cma_find_by_name("CMA_vpm");
        if (cma) {
            pdev->dev.cma_area = cma;
        }
        .....
    }
    

    Device B:

    static int XB_probe(struct platform_device *pdev)
    {
        struct cma *cma;

        cma = cma_find_by_name("CMA1");
        if (cma) {
            pdev->dev.cma_area = cma;
        }
        ....
    }


    So, this function could help developer who want to find a special
    named CMA area simply.



The CMA supports multiple named CMA areas, and the device could
use or exclusive a special CAM arae via "cma_area" on "struct
device". When probing, the device can setup special CMA area which
find by "cma_find_by_name()".

If device can't find named CMA area, "cma_find_by_name()" will
return NULL, and device will used default CMA area.

Signed-off-by: BuddyZhang <buddy.zhang@xxxxxxxxxx>
---
mm/cma.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index be55d1988c67..b562557572c4 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -40,6 +40,18 @@ struct cma cma_areas[MAX_CMA_AREAS];
unsigned cma_area_count;
static DEFINE_MUTEX(cma_mutex);

+struct cma *cma_find_by_name(const char *name)
+{
+  int idx;
+
+  for (idx = 0; idx < MAX_CMA_AREAS; idx++) {
+    if (cma_areas[idx].name && !strcmp(name, cma_areas[idx].name))
+      return &cma_areas[idx];
+  }
+  return NULL;
+}
+EXPORT_SYMBOL(cma_find_by_name)
+
phys_addr_t cma_get_base(const struct cma *cma)
{
return PFN_PHYS(cma->base_pfn);



--
Thanks,

David / dhildenb

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux