Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
0003  * All Rights Reserved.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the
0007  * "Software"), to deal in the Software without restriction, including
0008  * without limitation the rights to use, copy, modify, merge, publish,
0009  * distribute, sub license, and/or sell copies of the Software, and to
0010  * permit persons to whom the Software is furnished to do so, subject to
0011  * the following conditions:
0012  *
0013  * The above copyright notice and this permission notice (including the
0014  * next paragraph) shall be included in all copies or substantial portions
0015  * of the Software.
0016  *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0020  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0022  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0023  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0024  */
0025 
0026 /*
0027  * Simple open hash tab implementation.
0028  *
0029  * Authors:
0030  * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
0031  */
0032 
0033 /*
0034  * TODO: Replace this hashtable with Linux' generic implementation
0035  *       from <linux/hashtable.h>.
0036  */
0037 
0038 #ifndef VMWGFX_HASHTAB_H
0039 #define VMWGFX_HASHTAB_H
0040 
0041 #include <linux/list.h>
0042 
0043 #define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
0044 
0045 struct vmwgfx_hash_item {
0046     struct hlist_node head;
0047     unsigned long key;
0048 };
0049 
0050 struct vmwgfx_open_hash {
0051     struct hlist_head *table;
0052     u8 order;
0053 };
0054 
0055 int vmwgfx_ht_create(struct vmwgfx_open_hash *ht, unsigned int order);
0056 int vmwgfx_ht_insert_item(struct vmwgfx_open_hash *ht, struct vmwgfx_hash_item *item);
0057 int vmwgfx_ht_just_insert_please(struct vmwgfx_open_hash *ht, struct vmwgfx_hash_item *item,
0058                  unsigned long seed, int bits, int shift,
0059                  unsigned long add);
0060 int vmwgfx_ht_find_item(struct vmwgfx_open_hash *ht, unsigned long key,
0061             struct vmwgfx_hash_item **item);
0062 
0063 void vmwgfx_ht_verbose_list(struct vmwgfx_open_hash *ht, unsigned long key);
0064 int vmwgfx_ht_remove_key(struct vmwgfx_open_hash *ht, unsigned long key);
0065 int vmwgfx_ht_remove_item(struct vmwgfx_open_hash *ht, struct vmwgfx_hash_item *item);
0066 void vmwgfx_ht_remove(struct vmwgfx_open_hash *ht);
0067 
0068 /*
0069  * RCU-safe interface
0070  *
0071  * The user of this API needs to make sure that two or more instances of the
0072  * hash table manipulation functions are never run simultaneously.
0073  * The lookup function vmwgfx_ht_find_item_rcu may, however, run simultaneously
0074  * with any of the manipulation functions as long as it's called from within
0075  * an RCU read-locked section.
0076  */
0077 #define vmwgfx_ht_insert_item_rcu vmwgfx_ht_insert_item
0078 #define vmwgfx_ht_just_insert_please_rcu vmwgfx_ht_just_insert_please
0079 #define vmwgfx_ht_remove_key_rcu vmwgfx_ht_remove_key
0080 #define vmwgfx_ht_remove_item_rcu vmwgfx_ht_remove_item
0081 #define vmwgfx_ht_find_item_rcu vmwgfx_ht_find_item
0082 
0083 #endif