1 /* 2 * simple_idr.h 3 * 4 * Copyright (c) 2007-2019 Allwinnertech Co., Ltd. 5 * 6 * 7 * This software is licensed under the terms of the GNU General Public 8 * License version 2, as published by the Free Software Foundation, and 9 * may be copied, distributed, and modified under those terms. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 */ 17 18 #include <hal_sem.h> 19 20 #ifndef _MALI_IDR_H 21 #define _MALI_IDR_H 22 #define IDR_BIT 8 23 #define IDR_SIZE (1<<8) 24 #define IDR32_MASK 0xffffffff 25 #define NO_ID 0 26 27 struct id_layer { 28 int num_layer; 29 struct id_layer *layer[IDR_SIZE]; 30 int bitmap[IDR_SIZE/32];//full will set 31 struct id_layer *pre; 32 struct id_layer *next; 33 }; 34 35 struct id_dir { 36 hal_sem_t lock; 37 struct id_layer *top; 38 struct id_layer *lu_cache[4]; 39 int lu_id; 40 int cur_max_level; 41 int status;// -1 is destroyed, 0 is normal no visitting, 1 is now visitting... 42 struct id_layer *head; 43 }; 44 45 int id_alloc(struct id_dir *dir, void *value); 46 47 48 void id_free(struct id_dir *dir, int id); 49 50 void* id_get(struct id_dir *dir, int id); 51 52 struct id_dir* id_creat(void); 53 54 void id_destroyed(struct id_dir *dir); 55 56 #endif 57