void *g2d_malloc(__u32 bytes_num, __u32 *phy_addr) { #ifdef __FPGA_DEBUG_G2D__ __u32 actual_bytes; struct g2d_alloc_struct *ptr, *newptr; if(!bytes_num)return 0; actual_bytes = G2D_BYTE_ALIGN(bytes_num); ptr = &boot_heap_head; while(ptr && ptr->next) { if(ptr->next->address >= (ptr->address + ptr->size +(8*1024)+ actual_bytes)) { break; } ptr = ptr->next; } if (!ptr->next) { ERR(" it has reached the boot_heap_tail of the heap now\n"); return 0; /* it has reached the boot_heap_tail of the heap now */ } newptr = (struct g2d_alloc_struct *)(ptr->address + ptr->size); /* create a new node for the memory block */ if (!newptr) { ERR(" create the node failed, can't manage the block\n"); return 0; /* create the node failed, can't manage the block */ } /* set the memory block chain, insert the node to the chain */ newptr->address = ptr->address + ptr->size + 4*1024; newptr->size = actual_bytes; newptr->u_size = bytes_num; newptr->next = ptr->next; ptr->next = newptr; return (void *)newptr->address; #else __u32 actual_bytes; __u32 address; if(0!= bytes_num) { actual_bytes = G2D_BYTE_ALIGN(bytes_num); address = sunxi_mem_alloc(actual_bytes); if(address) { *phy_addr = address; return (void *)ioremap((unsigned int)address,actual_bytes); } INFO("sunxi_mem_alloc fail,size=0x%x\n",bytes_num); } return 0; #endif }
void g2d_free(void *virt_addr, void *phy_addr, unsigned int size) { #ifdef __FPGA_DEBUG_G2D__ struct g2d_alloc_struct *ptr, *prev; if( virt_addr == NULL ) return; ptr = &boot_heap_head; /* look for the node which po__s32 this memory block */ while (ptr && ptr->next) { if (ptr->next->address == (__u32)virt_addr) break; /* find the node which need to be release */ ptr = ptr->next; } prev = ptr; ptr = ptr->next; if (!ptr) return; /* the node is heap boot_heap_tail */ prev->next = ptr->next; /* delete the node which need be released from the memory block chain */ return; #else __u32 actual_bytes = G2D_BYTE_ALIGN(size); if(virt_addr) sunxi_buf_free(virt_addr, (unsigned int)phy_addr, actual_bytes); return; #endif }
void *g2d_malloc(__u32 bytes_num) { __u32 actual_bytes; struct g2d_alloc_struct *ptr, *newptr; if(!bytes_num)return 0; actual_bytes = G2D_BYTE_ALIGN(bytes_num); ptr = &boot_heap_head; while(ptr && ptr->next) { if(ptr->next->address >= (ptr->address + ptr->size +(8*1024)+ actual_bytes)) { break; } ptr = ptr->next; } if (!ptr->next) { ERR(" it has reached the boot_heap_tail of the heap now\n"); return 0; /* it has reached the boot_heap_tail of the heap now */ } newptr = (struct g2d_alloc_struct *)(ptr->address + ptr->size); /* create a new node for the memory block */ if (!newptr) { ERR(" create the node failed, can't manage the block\n"); return 0; /* create the node failed, can't manage the block */ } /* set the memory block chain, insert the node to the chain */ newptr->address = ptr->address + ptr->size + 4*1024; newptr->size = actual_bytes; newptr->u_size = bytes_num; newptr->next = ptr->next; ptr->next = newptr; return (void *)newptr->address; }