18c2ecf20Sopenharmony_ci/**************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci **************************************************************************/
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * Simple open hash tab implementation.
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * Authors:
328c2ecf20Sopenharmony_ci * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef DRM_HASHTAB_H
368c2ecf20Sopenharmony_ci#define DRM_HASHTAB_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/list.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct drm_hash_item {
438c2ecf20Sopenharmony_ci	struct hlist_node head;
448c2ecf20Sopenharmony_ci	unsigned long key;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct drm_open_hash {
488c2ecf20Sopenharmony_ci	struct hlist_head *table;
498c2ecf20Sopenharmony_ci	u8 order;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciint drm_ht_create(struct drm_open_hash *ht, unsigned int order);
538c2ecf20Sopenharmony_ciint drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
548c2ecf20Sopenharmony_ciint drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
558c2ecf20Sopenharmony_ci			      unsigned long seed, int bits, int shift,
568c2ecf20Sopenharmony_ci			      unsigned long add);
578c2ecf20Sopenharmony_ciint drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_civoid drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
608c2ecf20Sopenharmony_ciint drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
618c2ecf20Sopenharmony_ciint drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
628c2ecf20Sopenharmony_civoid drm_ht_remove(struct drm_open_hash *ht);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci * RCU-safe interface
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * The user of this API needs to make sure that two or more instances of the
688c2ecf20Sopenharmony_ci * hash table manipulation functions are never run simultaneously.
698c2ecf20Sopenharmony_ci * The lookup function drm_ht_find_item_rcu may, however, run simultaneously
708c2ecf20Sopenharmony_ci * with any of the manipulation functions as long as it's called from within
718c2ecf20Sopenharmony_ci * an RCU read-locked section.
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_ci#define drm_ht_insert_item_rcu drm_ht_insert_item
748c2ecf20Sopenharmony_ci#define drm_ht_just_insert_please_rcu drm_ht_just_insert_please
758c2ecf20Sopenharmony_ci#define drm_ht_remove_key_rcu drm_ht_remove_key
768c2ecf20Sopenharmony_ci#define drm_ht_remove_item_rcu drm_ht_remove_item
778c2ecf20Sopenharmony_ci#define drm_ht_find_item_rcu drm_ht_find_item
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#endif
80