| 585 | } |
| 586 | |
| 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) |
| 589 | { |
| 590 | struct rt_dma_pool *pool; |
| 591 | rt_region_t *region = region_list, *region_high = RT_NULL, cma, coherent_pool; |
| 592 | |
| 593 | if (!region_list || !list_len || cma_size < coherent_pool_size) |
| 594 | { |
| 595 | return -RT_EINVAL; |
| 596 | } |
| 597 | |
| 598 | for (rt_size_t i = 0; i < list_len; ++i, ++region) |
| 599 | { |
| 600 | if (!region->name) |
| 601 | { |
| 602 | continue; |
| 603 | } |
| 604 | |
| 605 | /* Always use low address in 4G */ |
| 606 | if (region->end - region->start >= cma_size) |
| 607 | { |
| 608 | if ((rt_ssize_t)((4UL * SIZE_GB) - region->start) < cma_size) |
| 609 | { |
| 610 | region_high = region; |
| 611 | continue; |
| 612 | } |
| 613 | |
| 614 | goto _found; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | if (region_high) |
| 619 | { |
| 620 | region = region_high; |
| 621 | LOG_W("No available DMA zone in 4G"); |
| 622 | |
| 623 | goto _found; |
| 624 | } |
| 625 | |
| 626 | return -RT_EEMPTY; |
| 627 | |
| 628 | _found: |
| 629 | if (region->end - region->start != cma_size) |
| 630 | { |
| 631 | cma.start = region->start; |
| 632 | cma.end = cma.start + cma_size; |
| 633 | |
| 634 | /* Update input region */ |
| 635 | region->start += cma_size; |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | rt_memcpy(&cma, region, sizeof(cma)); |
| 640 | } |
| 641 | |
| 642 | coherent_pool.name = "coherent-pool"; |
| 643 | coherent_pool.start = cma.start; |
| 644 | coherent_pool.end = coherent_pool.start + coherent_pool_size; |
nothing calls this directly
no test coverage detected