Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nouveau_heap.h
4570 views
/*1* Copyright 2007 Nouveau Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#ifndef __NOUVEAU_HEAP_H__23#define __NOUVEAU_HEAP_H__2425/* This datastructure represents a memory allocation heap. Fundamentally, this26* is a doubly-linked list with a few properties, and a usage convention.27*28* On initial allocation, there is a single node with the full size that's29* marked as not in-use. As allocations are made, blocks are taken off the end30* of that first node, and inserted right after it. If the first node doesn't31* have enough free space, we look for free space down in the rest of the32* list. This can happen if an allocation is made and then freed.33*34* The first node will remain with in_use == 0 even if the whole heap is35* exhausted. Another invariant is that there will never be two sequential36* in_use == 0 nodes. If a node is freed and it has one (or both) adjacent37* free nodes, they are merged into one, and the relevant heap entries are38* freed.39*40* The pattern to free the whole heap is to start with the first node and then41* just free the "next" node, until there is no next node. This should assure42* that at the end the first (and only) node is not in use and contains the43* full size of the heap.44*/45struct nouveau_heap {46struct nouveau_heap *prev;47struct nouveau_heap *next;4849void *priv;5051unsigned start;52unsigned size;5354int in_use;55};5657int58nouveau_heap_init(struct nouveau_heap **heap, unsigned start,59unsigned size);6061void62nouveau_heap_destroy(struct nouveau_heap **heap);6364int65nouveau_heap_alloc(struct nouveau_heap *heap, unsigned size, void *priv,66struct nouveau_heap **);6768void69nouveau_heap_free(struct nouveau_heap **);7071#endif727374