1d722e3fbSopenharmony_ci/* 2d722e3fbSopenharmony_ci * GLX Hardware Device Driver common code 3d722e3fbSopenharmony_ci * Copyright (C) 1999 Wittawat Yamwong 4d722e3fbSopenharmony_ci * 5d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation 8d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11d722e3fbSopenharmony_ci * 12d722e3fbSopenharmony_ci * The above copyright notice and this permission notice shall be included 13d722e3fbSopenharmony_ci * in all copies or substantial portions of the Software. 14d722e3fbSopenharmony_ci * 15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16d722e3fbSopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18d722e3fbSopenharmony_ci * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 19d722e3fbSopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20d722e3fbSopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 21d722e3fbSopenharmony_ci * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22d722e3fbSopenharmony_ci */ 23d722e3fbSopenharmony_ci 24d722e3fbSopenharmony_ci/** 25d722e3fbSopenharmony_ci * Memory manager code. Primarily used by device drivers to manage texture 26d722e3fbSopenharmony_ci * heaps, etc. 27d722e3fbSopenharmony_ci */ 28d722e3fbSopenharmony_ci 29d722e3fbSopenharmony_ci#ifndef MM_H 30d722e3fbSopenharmony_ci#define MM_H 31d722e3fbSopenharmony_ci 32d722e3fbSopenharmony_ci#include "libdrm_macros.h" 33d722e3fbSopenharmony_ci 34d722e3fbSopenharmony_cistruct mem_block { 35d722e3fbSopenharmony_ci struct mem_block *next, *prev; 36d722e3fbSopenharmony_ci struct mem_block *next_free, *prev_free; 37d722e3fbSopenharmony_ci struct mem_block *heap; 38d722e3fbSopenharmony_ci int ofs, size; 39d722e3fbSopenharmony_ci unsigned int free:1; 40d722e3fbSopenharmony_ci unsigned int reserved:1; 41d722e3fbSopenharmony_ci}; 42d722e3fbSopenharmony_ci 43d722e3fbSopenharmony_ci/** 44d722e3fbSopenharmony_ci * input: total size in bytes 45d722e3fbSopenharmony_ci * return: a heap pointer if OK, NULL if error 46d722e3fbSopenharmony_ci */ 47d722e3fbSopenharmony_cidrm_private extern struct mem_block *mmInit(int ofs, int size); 48d722e3fbSopenharmony_ci 49d722e3fbSopenharmony_ci/** 50d722e3fbSopenharmony_ci * Allocate 'size' bytes with 2^align2 bytes alignment, 51d722e3fbSopenharmony_ci * restrict the search to free memory after 'startSearch' 52d722e3fbSopenharmony_ci * depth and back buffers should be in different 4mb banks 53d722e3fbSopenharmony_ci * to get better page hits if possible 54d722e3fbSopenharmony_ci * input: size = size of block 55d722e3fbSopenharmony_ci * align2 = 2^align2 bytes alignment 56d722e3fbSopenharmony_ci * startSearch = linear offset from start of heap to begin search 57d722e3fbSopenharmony_ci * return: pointer to the allocated block, 0 if error 58d722e3fbSopenharmony_ci */ 59d722e3fbSopenharmony_cidrm_private extern struct mem_block *mmAllocMem(struct mem_block *heap, 60d722e3fbSopenharmony_ci int size, int align2, 61d722e3fbSopenharmony_ci int startSearch); 62d722e3fbSopenharmony_ci 63d722e3fbSopenharmony_ci/** 64d722e3fbSopenharmony_ci * Free block starts at offset 65d722e3fbSopenharmony_ci * input: pointer to a block 66d722e3fbSopenharmony_ci * return: 0 if OK, -1 if error 67d722e3fbSopenharmony_ci */ 68d722e3fbSopenharmony_cidrm_private extern int mmFreeMem(struct mem_block *b); 69d722e3fbSopenharmony_ci 70d722e3fbSopenharmony_ci/** 71d722e3fbSopenharmony_ci * destroy MM 72d722e3fbSopenharmony_ci */ 73d722e3fbSopenharmony_cidrm_private extern void mmDestroy(struct mem_block *mmInit); 74d722e3fbSopenharmony_ci 75d722e3fbSopenharmony_ci/** 76d722e3fbSopenharmony_ci * For debugging purpose. 77d722e3fbSopenharmony_ci */ 78d722e3fbSopenharmony_cidrm_private extern void mmDumpMemInfo(const struct mem_block *mmInit); 79d722e3fbSopenharmony_ci 80d722e3fbSopenharmony_ci#endif 81