1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 8 * See "LICENSE_GPLv2.txt" for details. 9 * 10 * @TAG(DATA61_GPL) 11 */ 12 13#include <ethdrivers/helpers.h> 14 15dma_addr_t 16dma_alloc_pin(ps_dma_man_t *dma_man, size_t size, int cached, int alignment) 17{ 18 void *virt = ps_dma_alloc(dma_man, size, alignment, cached, PS_MEM_NORMAL); 19 if (!virt) { 20 return (dma_addr_t) {0, 0}; 21 } 22 uintptr_t phys = ps_dma_pin(dma_man, virt, size); 23 if (!phys) { 24 /* hmm this shouldn't really happen */ 25 ps_dma_free(dma_man, virt, size); 26 return (dma_addr_t) {0, 0}; 27 } 28 if (!cached) { 29 /* Prevent any cache bombs */ 30 ps_dma_cache_clean_invalidate(dma_man, virt, size); 31 } 32 return (dma_addr_t) {.virt = virt, .phys = phys}; 33} 34 35void 36dma_unpin_free(ps_dma_man_t *dma_man, void *virt, size_t size) 37{ 38 ps_dma_unpin(dma_man, virt, size); 39 ps_dma_free(dma_man, virt, size); 40} 41