memory.c 671 B

12345678910111213141516171819202122232425262728293031323334
  1. /* CBMA -- Cafe's Bad Memory Allocator */
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <pandriver.h>
  5. #define CBMA_PAGES 1024
  6. uint32_t cbma_bottom;
  7. uint32_t cbma_top;
  8. void init_cbma(int fd)
  9. {
  10. cbma_bottom = alloc_gpu_pages(
  11. fd, CBMA_PAGES,
  12. MALI_MEM_PROT_CPU_RD | MALI_MEM_PROT_CPU_WR | MALI_MEM_PROT_GPU_RD |
  13. MALI_MEM_PROT_GPU_WR | MALI_MEM_SAME_VA);
  14. cbma_top = cbma_bottom;
  15. memset((void*) cbma_bottom, 0, CBMA_PAGES << PAGE_SHIFT);
  16. }
  17. void* galloc(size_t sz)
  18. {
  19. cbma_bottom &= 0xFFFFFC00;
  20. cbma_bottom += 0x400;
  21. cbma_bottom += sz;
  22. return (void*) (uint32_t) (cbma_bottom - sz);
  23. }
  24. void gfree(void* ptr)
  25. {
  26. printf("gfree %p\n", ptr);
  27. /* TODO */
  28. }