1 1.3 riastrad /* $NetBSD: drm_hashtab.h,v 1.4 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.3 riastrad 3 1.1 riastrad /************************************************************************** 4 1.1 riastrad * 5 1.1 riastrad * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA. 6 1.1 riastrad * All Rights Reserved. 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the 10 1.1 riastrad * "Software"), to deal in the Software without restriction, including 11 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 12 1.1 riastrad * distribute, sub license, and/or sell copies of the Software, and to 13 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 14 1.1 riastrad * the following conditions: 15 1.1 riastrad * 16 1.1 riastrad * The above copyright notice and this permission notice (including the 17 1.1 riastrad * next paragraph) shall be included in all copies or substantial portions 18 1.1 riastrad * of the Software. 19 1.1 riastrad * 20 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 1.1 riastrad * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 24 1.1 riastrad * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 1.1 riastrad * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 26 1.1 riastrad * USE OR OTHER DEALINGS IN THE SOFTWARE. 27 1.1 riastrad * 28 1.1 riastrad * 29 1.1 riastrad **************************************************************************/ 30 1.1 riastrad /* 31 1.1 riastrad * Simple open hash tab implementation. 32 1.1 riastrad * 33 1.1 riastrad * Authors: 34 1.1 riastrad * Thomas Hellstrm <thomas-at-tungstengraphics-dot-com> 35 1.1 riastrad */ 36 1.1 riastrad 37 1.1 riastrad #ifndef DRM_HASHTAB_H 38 1.1 riastrad #define DRM_HASHTAB_H 39 1.1 riastrad 40 1.2 riastrad #include <linux/kernel.h> 41 1.1 riastrad #include <linux/list.h> 42 1.2 riastrad #include <linux/types.h> 43 1.1 riastrad 44 1.1 riastrad #define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member) 45 1.1 riastrad 46 1.1 riastrad struct drm_hash_item { 47 1.1 riastrad struct hlist_node head; 48 1.1 riastrad unsigned long key; 49 1.1 riastrad }; 50 1.1 riastrad 51 1.1 riastrad struct drm_open_hash { 52 1.1 riastrad struct hlist_head *table; 53 1.1 riastrad u8 order; 54 1.1 riastrad }; 55 1.1 riastrad 56 1.4 riastrad int drm_ht_create(struct drm_open_hash *ht, unsigned int order); 57 1.4 riastrad int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item); 58 1.4 riastrad int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item, 59 1.4 riastrad unsigned long seed, int bits, int shift, 60 1.4 riastrad unsigned long add); 61 1.4 riastrad int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item); 62 1.1 riastrad 63 1.4 riastrad void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key); 64 1.4 riastrad int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key); 65 1.4 riastrad int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item); 66 1.4 riastrad void drm_ht_remove(struct drm_open_hash *ht); 67 1.1 riastrad 68 1.1 riastrad /* 69 1.1 riastrad * RCU-safe interface 70 1.1 riastrad * 71 1.1 riastrad * The user of this API needs to make sure that two or more instances of the 72 1.1 riastrad * hash table manipulation functions are never run simultaneously. 73 1.1 riastrad * The lookup function drm_ht_find_item_rcu may, however, run simultaneously 74 1.1 riastrad * with any of the manipulation functions as long as it's called from within 75 1.1 riastrad * an RCU read-locked section. 76 1.1 riastrad */ 77 1.1 riastrad #define drm_ht_insert_item_rcu drm_ht_insert_item 78 1.1 riastrad #define drm_ht_just_insert_please_rcu drm_ht_just_insert_please 79 1.1 riastrad #define drm_ht_remove_key_rcu drm_ht_remove_key 80 1.1 riastrad #define drm_ht_remove_item_rcu drm_ht_remove_item 81 1.1 riastrad #define drm_ht_find_item_rcu drm_ht_find_item 82 1.1 riastrad 83 1.1 riastrad #endif 84