guo ecf2d82159
sync branch rt-smart. (#6641)
* Synchronize the code of the rt mart branch to the master branch.
  * TTY device
  * Add lwP code from rt-smart
  * Add vnode in DFS, but DFS will be re-write for rt-smart
  * There are three libcpu for rt-smart:
    * arm/cortex-a, arm/aarch64
    * riscv64

Co-authored-by: Rbb666 <zhangbingru@rt-thread.com>
Co-authored-by: zhkag <zhkag@foxmail.com>
2022-12-03 12:07:44 +08:00

39 lines
829 B
C

#include <stdio.h>
#include <hal_mem.h>
#include "sunxi_hal_common.h"
void dma_free_coherent(void *addr)
{
void *malloc_ptr = NULL;
if (!addr)
{
return;
}
malloc_ptr = (void *)*(unsigned long *)((unsigned long *)addr - 1);
hal_free(malloc_ptr);
}
void *dma_alloc_coherent(size_t size)
{
void *fake_ptr = NULL;
void *malloc_ptr = NULL;
malloc_ptr = hal_malloc(size + 2 * CACHELINE_LEN);
if ((unsigned long)malloc_ptr & (sizeof(long) - 1))
{
printf("error: mm_alloc not align. \r\n");
return NULL;
}
if (!malloc_ptr) {
return NULL;
}
fake_ptr = (void *)((unsigned long)(malloc_ptr + CACHELINE_LEN) & (~(CACHELINE_LEN - 1)));
*(unsigned long *)((unsigned long *)fake_ptr - 1) = (unsigned long)malloc_ptr;
return fake_ptr;
}