Release 4.7 drivers/gpu/drm/drm_hashtab.c
  
  
/**************************************************************************
 *
 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *
 **************************************************************************/
/*
 * Simple open hash tab implementation.
 *
 * Authors:
 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
 */
#include <drm/drmP.h>
#include <drm/drm_hashtab.h>
#include <linux/hash.h>
#include <linux/slab.h>
#include <linux/export.h>
int drm_ht_create(struct drm_open_hash *ht, unsigned int order)
{
	unsigned int size = 1 << order;
	ht->order = order;
	ht->table = NULL;
	if (size <= PAGE_SIZE / sizeof(*ht->table))
		ht->table = kcalloc(size, sizeof(*ht->table), GFP_KERNEL);
	else
		ht->table = vzalloc(size*sizeof(*ht->table));
	if (!ht->table) {
		DRM_ERROR("Out of memory for hash table\n");
		return -ENOMEM;
	}
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 61 | 57.55% | 1 | 16.67% | 
| dave airlie | dave airlie | 34 | 32.08% | 3 | 50.00% | 
| chris wilson | chris wilson | 9 | 8.49% | 1 | 16.67% | 
| eric anholt | eric anholt | 2 | 1.89% | 1 | 16.67% | 
 | Total | 106 | 100.00% | 6 | 100.00% | 
EXPORT_SYMBOL(drm_ht_create);
void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	unsigned int hashed_key;
	int count = 0;
	hashed_key = hash_long(key, ht->order);
	DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
	h_list = &ht->table[hashed_key];
	hlist_for_each_entry(entry, h_list, head)
		DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 79 | 95.18% | 3 | 75.00% | 
| dave airlie | dave airlie | 4 | 4.82% | 1 | 25.00% | 
 | Total | 83 | 100.00% | 4 | 100.00% | 
static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
					  unsigned long key)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	unsigned int hashed_key;
	hashed_key = hash_long(key, ht->order);
	h_list = &ht->table[hashed_key];
	hlist_for_each_entry(entry, h_list, head) {
		if (entry->key == key)
			return &entry->head;
		if (entry->key > key)
			break;
	}
	return NULL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 80 | 90.91% | 2 | 50.00% | 
| dave airlie | dave airlie | 4 | 4.55% | 1 | 25.00% | 
| sasha levin | sasha levin | 4 | 4.55% | 1 | 25.00% | 
 | Total | 88 | 100.00% | 4 | 100.00% | 
static struct hlist_node *drm_ht_find_key_rcu(struct drm_open_hash *ht,
					      unsigned long key)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	unsigned int hashed_key;
	hashed_key = hash_long(key, ht->order);
	h_list = &ht->table[hashed_key];
	hlist_for_each_entry_rcu(entry, h_list, head) {
		if (entry->key == key)
			return &entry->head;
		if (entry->key > key)
			break;
	}
	return NULL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 84 | 95.45% | 3 | 75.00% | 
| sasha levin | sasha levin | 4 | 4.55% | 1 | 25.00% | 
 | Total | 88 | 100.00% | 4 | 100.00% | 
int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	struct hlist_node *parent;
	unsigned int hashed_key;
	unsigned long key = item->key;
	hashed_key = hash_long(key, ht->order);
	h_list = &ht->table[hashed_key];
	parent = NULL;
	hlist_for_each_entry(entry, h_list, head) {
		if (entry->key == key)
			return -EINVAL;
		if (entry->key > key)
			break;
		parent = &entry->head;
	}
	if (parent) {
		hlist_add_behind_rcu(&item->head, parent);
	} else {
		hlist_add_head_rcu(&item->head, h_list);
	}
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 124 | 90.51% | 4 | 57.14% | 
| dave airlie | dave airlie | 6 | 4.38% | 1 | 14.29% | 
| sasha levin | sasha levin | 4 | 2.92% | 1 | 14.29% | 
| ken helias | ken helias | 3 | 2.19% | 1 | 14.29% | 
 | Total | 137 | 100.00% | 7 | 100.00% | 
EXPORT_SYMBOL(drm_ht_insert_item);
/*
 * Just insert an item and return any "bits" bit key that hasn't been
 * used before.
 */
int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
			      unsigned long seed, int bits, int shift,
			      unsigned long add)
{
	int ret;
	unsigned long mask = (1 << bits) - 1;
	unsigned long first, unshifted_key;
	unshifted_key = hash_long(seed, bits);
	first = unshifted_key;
	do {
		item->key = (unshifted_key << shift) + add;
		ret = drm_ht_insert_item(ht, item);
		if (ret)
			unshifted_key = (unshifted_key + 1) & mask;
	} while(ret && (unshifted_key != first));
	if (ret) {
		DRM_ERROR("Available key bit space exhausted\n");
		return -EINVAL;
	}
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 126 | 96.92% | 1 | 50.00% | 
| dave airlie | dave airlie | 4 | 3.08% | 1 | 50.00% | 
 | Total | 130 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL(drm_ht_just_insert_please);
int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key,
		     struct drm_hash_item **item)
{
	struct hlist_node *list;
	list = drm_ht_find_key_rcu(ht, key);
	if (!list)
		return -EINVAL;
	*item = hlist_entry(list, struct drm_hash_item, head);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 53 | 89.83% | 3 | 75.00% | 
| dave airlie | dave airlie | 6 | 10.17% | 1 | 25.00% | 
 | Total | 59 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL(drm_ht_find_item);
int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key)
{
	struct hlist_node *list;
	list = drm_ht_find_key(ht, key);
	if (list) {
		hlist_del_init_rcu(list);
		return 0;
	}
	return -EINVAL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 44 | 95.65% | 3 | 75.00% | 
| dave airlie | dave airlie | 2 | 4.35% | 1 | 25.00% | 
 | Total | 46 | 100.00% | 4 | 100.00% | 
int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item)
{
	hlist_del_init_rcu(&item->head);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 22 | 84.62% | 2 | 66.67% | 
| dave airlie | dave airlie | 4 | 15.38% | 1 | 33.33% | 
 | Total | 26 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL(drm_ht_remove_item);
void drm_ht_remove(struct drm_open_hash *ht)
{
	if (ht->table) {
		kvfree(ht->table);
		ht->table = NULL;
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 22 | 70.97% | 1 | 25.00% | 
| dave airlie | dave airlie | 8 | 25.81% | 2 | 50.00% | 
| tetsuo handa | tetsuo handa | 1 | 3.23% | 1 | 25.00% | 
 | Total | 31 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL(drm_ht_remove);
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| thomas hellstrom | thomas hellstrom | 703 | 83.49% | 4 | 21.05% | 
| dave airlie | dave airlie | 73 | 8.67% | 4 | 21.05% | 
| jerome glisse | jerome glisse | 20 | 2.38% | 1 | 5.26% | 
| sasha levin | sasha levin | 12 | 1.43% | 1 | 5.26% | 
| jesse barnes | jesse barnes | 10 | 1.19% | 1 | 5.26% | 
| chris wilson | chris wilson | 9 | 1.07% | 1 | 5.26% | 
| paul gortmaker | paul gortmaker | 3 | 0.36% | 1 | 5.26% | 
| tejun heo | tejun heo | 3 | 0.36% | 1 | 5.26% | 
| ken helias | ken helias | 3 | 0.36% | 1 | 5.26% | 
| david howells | david howells | 2 | 0.24% | 1 | 5.26% | 
| eric anholt | eric anholt | 2 | 0.24% | 1 | 5.26% | 
| jan engelhardt | jan engelhardt | 1 | 0.12% | 1 | 5.26% | 
| tetsuo handa | tetsuo handa | 1 | 0.12% | 1 | 5.26% | 
 | Total | 842 | 100.00% | 19 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.