Skip to content

Commit 6ea8e75

Browse files
committed
[DM/DMA] Update DMA Pool
1. Append WT attribute. 2. Change the API with pool size only. Signed-off-by: GuEe-GUI <[email protected]>
1 parent 2fb53c8 commit 6ea8e75

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

components/drivers/dma/dma_pool.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <rtdbg.h>
1818

1919
#include <mm_aspace.h>
20+
#include <mm_memblock.h>
2021
#include <dt-bindings/size.h>
2122

2223
static RT_DEFINE_SPINLOCK(dma_pools_lock);
@@ -291,9 +292,13 @@ static rt_ubase_t dma_pool_alloc(struct rt_dma_pool *pool, rt_size_t size)
291292
rt_bitmap_set_bit(pool->map, next_bit);
292293
}
293294

295+
LOG_D("%s offset = %p, pages = %d", "Alloc",
296+
pool->start + bit * ARCH_PAGE_SIZE, size);
297+
294298
return pool->start + bit * ARCH_PAGE_SIZE;
295299
}
296300
_next:
301+
;
297302
}
298303

299304
return RT_NULL;
@@ -310,6 +315,8 @@ static void dma_pool_free(struct rt_dma_pool *pool, rt_ubase_t offset, rt_size_t
310315
{
311316
rt_bitmap_clear_bit(pool->map, bit);
312317
}
318+
319+
LOG_D("%s offset = %p, pages = %d", "Free", offset, size);
313320
}
314321

315322
static void *dma_alloc(struct rt_device *dev, rt_size_t size,
@@ -344,11 +351,6 @@ static void *dma_alloc(struct rt_device *dev, rt_size_t size,
344351
continue;
345352
}
346353

347-
if ((flags & RT_DMA_F_LINEAR) && !((pool->flags & RT_DMA_F_LINEAR)))
348-
{
349-
continue;
350-
}
351-
352354
*dma_handle = dma_pool_alloc(pool, size);
353355

354356
if (*dma_handle && !(flags & RT_DMA_F_NOMAP))
@@ -357,6 +359,10 @@ static void *dma_alloc(struct rt_device *dev, rt_size_t size,
357359
{
358360
dma_buffer = rt_ioremap_nocache((void *)*dma_handle, size);
359361
}
362+
else if (flags & RT_DMA_F_WT)
363+
{
364+
dma_buffer = rt_ioremap_wt((void *)*dma_handle, size);
365+
}
360366
else
361367
{
362368
dma_buffer = rt_ioremap_cached((void *)*dma_handle, size);
@@ -584,20 +590,33 @@ struct rt_dma_pool *rt_dma_pool_install(rt_region_t *region)
584590
return pool;
585591
}
586592

587-
rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
588-
rt_size_t cma_size, rt_size_t coherent_pool_size)
593+
rt_err_t rt_dma_pool_extract(rt_size_t cma_size, rt_size_t coherent_pool_size)
589594
{
590595
struct rt_dma_pool *pool;
591-
rt_region_t *region = region_list, *region_high = RT_NULL, cma, coherent_pool;
596+
struct rt_mmblk_reg *reg, *reg_high;
597+
struct rt_memblock *memblock = rt_memblock_get_reserved();
598+
rt_region_t *region, *region_high = RT_NULL, cma, coherent_pool;
592599

593-
if (!region_list || !list_len || cma_size < coherent_pool_size)
600+
if (!memblock)
601+
{
602+
return -RT_ENOSYS;
603+
}
604+
605+
/* Coherent pool is included in CMA */
606+
if (cma_size < coherent_pool_size)
594607
{
595608
return -RT_EINVAL;
596609
}
597610

598-
for (rt_size_t i = 0; i < list_len; ++i, ++region)
611+
rt_slist_for_each_entry(reg, &memblock->reg_list, node)
599612
{
600-
if (!region->name)
613+
if (!reg->alloc || (reg->flags & MEMBLOCK_HOTPLUG))
614+
{
615+
continue;
616+
}
617+
618+
region = &reg->memreg;
619+
if (rt_strcmp(region->name, "dma-pool") || !reg->memreg.name)
601620
{
602621
continue;
603622
}
@@ -608,6 +627,7 @@ rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
608627
if ((rt_ssize_t)((4UL * SIZE_GB) - region->start) < cma_size)
609628
{
610629
region_high = region;
630+
reg_high = reg;
611631
continue;
612632
}
613633

@@ -618,6 +638,7 @@ rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
618638
if (region_high)
619639
{
620640
region = region_high;
641+
reg = reg_high;
621642
LOG_W("No available DMA zone in 4G");
622643

623644
goto _found;
@@ -630,9 +651,6 @@ rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
630651
{
631652
cma.start = region->start;
632653
cma.end = cma.start + cma_size;
633-
634-
/* Update input region */
635-
region->start += cma_size;
636654
}
637655
else
638656
{
@@ -657,6 +675,8 @@ rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
657675
return -RT_ENOMEM;
658676
}
659677

678+
reg->alloc = RT_FALSE;
679+
660680
return RT_EOK;
661681
}
662682

components/drivers/include/drivers/dma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ rt_err_t rt_dma_chan_release(struct rt_dma_chan *chan);
188188
#define RT_DMA_F_NOCACHE RT_BIT(2)
189189
#define RT_DMA_F_DEVICE RT_BIT(3)
190190
#define RT_DMA_F_NOMAP RT_BIT(4)
191+
#define RT_DMA_F_WT RT_BIT(5)
191192

192193
#define RT_DMA_PAGE_SIZE ARCH_PAGE_SIZE
193194

@@ -228,7 +229,6 @@ rt_inline void rt_dma_device_set_ops(struct rt_device *dev,
228229
}
229230

230231
struct rt_dma_pool *rt_dma_pool_install(rt_region_t *region);
231-
rt_err_t rt_dma_pool_extract(rt_region_t *region_list, rt_size_t list_len,
232-
rt_size_t cma_size, rt_size_t coherent_pool_size);
232+
rt_err_t rt_dma_pool_extract(rt_size_t cma_size, rt_size_t coherent_pool_size);
233233

234234
#endif /* __DMA_H__ */

0 commit comments

Comments
 (0)