drm: fixup whitespace and style for Linux kernel import
parent
35066b51ef
commit
248d1a32a2
|
@ -36,161 +36,155 @@
|
|||
#include "drm_hashtab.h"
|
||||
#include <linux/hash.h>
|
||||
|
||||
int
|
||||
drm_ht_create(drm_open_hash_t *ht, unsigned int order)
|
||||
int drm_ht_create(drm_open_hash_t *ht, unsigned int order)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i;
|
||||
|
||||
ht->size = 1 << order;
|
||||
ht->order = order;
|
||||
ht->fill = 0;
|
||||
ht->table = vmalloc(ht->size*sizeof(*ht->table));
|
||||
if (!ht->table) {
|
||||
DRM_ERROR("Out of memory for hash table\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
for (i=0; i< ht->size; ++i) {
|
||||
INIT_HLIST_HEAD(&ht->table[i]);
|
||||
}
|
||||
return 0;
|
||||
ht->size = 1 << order;
|
||||
ht->order = order;
|
||||
ht->fill = 0;
|
||||
ht->table = vmalloc(ht->size*sizeof(*ht->table));
|
||||
if (!ht->table) {
|
||||
DRM_ERROR("Out of memory for hash table\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
for (i=0; i< ht->size; ++i) {
|
||||
INIT_HLIST_HEAD(&ht->table[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
|
||||
void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
|
||||
{
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *list;
|
||||
unsigned int hashed_key;
|
||||
int count = 0;
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *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(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
|
||||
}
|
||||
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(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
|
||||
}
|
||||
}
|
||||
|
||||
static struct hlist_node
|
||||
*drm_ht_find_key(drm_open_hash_t *ht, unsigned long key)
|
||||
static struct hlist_node *drm_ht_find_key(drm_open_hash_t *ht,
|
||||
unsigned long key)
|
||||
{
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *list;
|
||||
unsigned int hashed_key;
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *list;
|
||||
unsigned int hashed_key;
|
||||
|
||||
hashed_key = hash_long(key, ht->order);
|
||||
h_list = &ht->table[hashed_key];
|
||||
hlist_for_each(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
if (entry->key == key)
|
||||
return list;
|
||||
if (entry->key > key)
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
hashed_key = hash_long(key, ht->order);
|
||||
h_list = &ht->table[hashed_key];
|
||||
hlist_for_each(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
if (entry->key == key)
|
||||
return list;
|
||||
if (entry->key > key)
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
|
||||
int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
|
||||
{
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *list, *parent;
|
||||
unsigned int hashed_key;
|
||||
unsigned long key = item->key;
|
||||
drm_hash_item_t *entry;
|
||||
struct hlist_head *h_list;
|
||||
struct hlist_node *list, *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(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
if (entry->key == key)
|
||||
return -1;
|
||||
if (entry->key > key)
|
||||
break;
|
||||
parent = list;
|
||||
}
|
||||
if (parent) {
|
||||
hlist_add_after(parent, &item->head);
|
||||
} else {
|
||||
hlist_add_head(&item->head, h_list);
|
||||
}
|
||||
return 0;
|
||||
hashed_key = hash_long(key, ht->order);
|
||||
h_list = &ht->table[hashed_key];
|
||||
parent = NULL;
|
||||
hlist_for_each(list, h_list) {
|
||||
entry = hlist_entry(list, drm_hash_item_t, head);
|
||||
if (entry->key == key)
|
||||
return -1;
|
||||
if (entry->key > key)
|
||||
break;
|
||||
parent = list;
|
||||
}
|
||||
if (parent) {
|
||||
hlist_add_after(parent, &item->head);
|
||||
} else {
|
||||
hlist_add_head(&item->head, h_list);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Just insert an item and return any "bits" bit key that hasn't been used before.
|
||||
* Just insert an item and return any "bits" bit key that hasn't been
|
||||
* used before.
|
||||
*/
|
||||
|
||||
int
|
||||
drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
|
||||
unsigned long seed, int bits, int shift,
|
||||
unsigned long add)
|
||||
int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
|
||||
unsigned long seed, int bits, int shift,
|
||||
unsigned long add)
|
||||
{
|
||||
int ret;
|
||||
unsigned long mask = (1 << bits) - 1;
|
||||
unsigned long first, unshifted_key;
|
||||
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));
|
||||
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;
|
||||
if (ret) {
|
||||
DRM_ERROR("Available key bit space exhausted\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, drm_hash_item_t **item)
|
||||
int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key,
|
||||
drm_hash_item_t **item)
|
||||
{
|
||||
struct hlist_node *list;
|
||||
struct hlist_node *list;
|
||||
|
||||
list = drm_ht_find_key(ht, key);
|
||||
if (!list)
|
||||
return -1;
|
||||
list = drm_ht_find_key(ht, key);
|
||||
if (!list)
|
||||
return -1;
|
||||
|
||||
*item = hlist_entry(list, drm_hash_item_t, head);
|
||||
return 0;
|
||||
*item = hlist_entry(list, drm_hash_item_t, head);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key)
|
||||
int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key)
|
||||
{
|
||||
struct hlist_node *list;
|
||||
struct hlist_node *list;
|
||||
|
||||
list = drm_ht_find_key(ht, key);
|
||||
if (list) {
|
||||
hlist_del_init(list);
|
||||
ht->fill--;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
list = drm_ht_find_key(ht, key);
|
||||
if (list) {
|
||||
hlist_del_init(list);
|
||||
ht->fill--;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
|
||||
int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
|
||||
{
|
||||
hlist_del_init(&item->head);
|
||||
ht->fill--;
|
||||
return 0;
|
||||
hlist_del_init(&item->head);
|
||||
ht->fill--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void drm_ht_remove(drm_open_hash_t *ht)
|
||||
{
|
||||
if (ht->table) {
|
||||
vfree(ht->table);
|
||||
ht->table = NULL;
|
||||
}
|
||||
if (ht->table) {
|
||||
vfree(ht->table);
|
||||
ht->table = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,15 +38,15 @@
|
|||
#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
|
||||
|
||||
typedef struct drm_hash_item{
|
||||
struct hlist_node head;
|
||||
unsigned long key;
|
||||
struct hlist_node head;
|
||||
unsigned long key;
|
||||
} drm_hash_item_t;
|
||||
|
||||
typedef struct drm_open_hash{
|
||||
unsigned int size;
|
||||
unsigned int order;
|
||||
unsigned int fill;
|
||||
struct hlist_head *table;
|
||||
unsigned int size;
|
||||
unsigned int order;
|
||||
unsigned int fill;
|
||||
struct hlist_head *table;
|
||||
} drm_open_hash_t;
|
||||
|
||||
|
||||
|
|
|
@ -77,9 +77,9 @@ drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
|
|||
goto out;
|
||||
|
||||
drm_ht_remove(&sman->owner_hash_tab);
|
||||
out1:
|
||||
out1:
|
||||
drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -163,8 +163,8 @@ drm_sman_set_manager(drm_sman_t * sman, unsigned int manager,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static drm_owner_item_t
|
||||
* drm_sman_get_owner_item(drm_sman_t * sman, unsigned long owner)
|
||||
static drm_owner_item_t *drm_sman_get_owner_item(drm_sman_t * sman,
|
||||
unsigned long owner)
|
||||
{
|
||||
int ret;
|
||||
drm_hash_item_t *owner_hash_item;
|
||||
|
@ -173,7 +173,7 @@ static drm_owner_item_t
|
|||
ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
|
||||
if (!ret) {
|
||||
return drm_hash_entry(owner_hash_item, drm_owner_item_t,
|
||||
owner_hash);
|
||||
owner_hash);
|
||||
}
|
||||
|
||||
owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM);
|
||||
|
@ -188,13 +188,13 @@ static drm_owner_item_t
|
|||
list_add_tail(&owner_item->sman_list, &sman->owner_items);
|
||||
return owner_item;
|
||||
|
||||
out1:
|
||||
out1:
|
||||
drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
|
||||
out:
|
||||
out:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, unsigned int manager,
|
||||
drm_memblock_item_t *drm_sman_alloc(drm_sman_t *sman, unsigned int manager,
|
||||
unsigned long size, unsigned alignment,
|
||||
unsigned long owner)
|
||||
{
|
||||
|
@ -234,11 +234,11 @@ drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, unsigned int manager,
|
|||
|
||||
return memblock;
|
||||
|
||||
out2:
|
||||
out2:
|
||||
drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
|
||||
out1:
|
||||
out1:
|
||||
drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
|
||||
out:
|
||||
out:
|
||||
sman_mm->free(sman_mm->private, tmp);
|
||||
|
||||
return NULL;
|
||||
|
@ -246,7 +246,7 @@ drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, unsigned int manager,
|
|||
|
||||
EXPORT_SYMBOL(drm_sman_alloc);
|
||||
|
||||
static void drm_sman_free(drm_memblock_item_t * item)
|
||||
static void drm_sman_free(drm_memblock_item_t *item)
|
||||
{
|
||||
drm_sman_t *sman = item->sman;
|
||||
|
||||
|
@ -256,7 +256,7 @@ static void drm_sman_free(drm_memblock_item_t * item)
|
|||
drm_free(item, sizeof(*item), DRM_MEM_MM);
|
||||
}
|
||||
|
||||
int drm_sman_free_key(drm_sman_t * sman, unsigned int key)
|
||||
int drm_sman_free_key(drm_sman_t *sman, unsigned int key)
|
||||
{
|
||||
drm_hash_item_t *hash_item;
|
||||
drm_memblock_item_t *memblock_item;
|
||||
|
@ -271,15 +271,15 @@ int drm_sman_free_key(drm_sman_t * sman, unsigned int key)
|
|||
|
||||
EXPORT_SYMBOL(drm_sman_free_key);
|
||||
|
||||
static void
|
||||
drm_sman_remove_owner(drm_sman_t * sman, drm_owner_item_t * owner_item)
|
||||
static void drm_sman_remove_owner(drm_sman_t *sman,
|
||||
drm_owner_item_t *owner_item)
|
||||
{
|
||||
list_del(&owner_item->sman_list);
|
||||
drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
|
||||
drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
|
||||
}
|
||||
|
||||
int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner)
|
||||
int drm_sman_owner_clean(drm_sman_t *sman, unsigned long owner)
|
||||
{
|
||||
|
||||
drm_hash_item_t *hash_item;
|
||||
|
@ -300,8 +300,8 @@ int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner)
|
|||
|
||||
EXPORT_SYMBOL(drm_sman_owner_clean);
|
||||
|
||||
static void
|
||||
drm_sman_do_owner_cleanup(drm_sman_t * sman, drm_owner_item_t * owner_item)
|
||||
static void drm_sman_do_owner_cleanup(drm_sman_t *sman,
|
||||
drm_owner_item_t *owner_item)
|
||||
{
|
||||
drm_memblock_item_t *entry, *next;
|
||||
|
||||
|
@ -312,7 +312,7 @@ drm_sman_do_owner_cleanup(drm_sman_t * sman, drm_owner_item_t * owner_item)
|
|||
drm_sman_remove_owner(sman, owner_item);
|
||||
}
|
||||
|
||||
void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner)
|
||||
void drm_sman_owner_cleanup(drm_sman_t *sman, unsigned long owner)
|
||||
{
|
||||
|
||||
drm_hash_item_t *hash_item;
|
||||
|
@ -329,7 +329,7 @@ void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner)
|
|||
|
||||
EXPORT_SYMBOL(drm_sman_owner_cleanup);
|
||||
|
||||
void drm_sman_cleanup(drm_sman_t * sman)
|
||||
void drm_sman_cleanup(drm_sman_t *sman)
|
||||
{
|
||||
drm_owner_item_t *entry, *next;
|
||||
unsigned int i;
|
||||
|
|
|
@ -103,12 +103,12 @@ extern void drm_sman_takedown(drm_sman_t * sman);
|
|||
* Allocate structures for a manager.
|
||||
* num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
|
||||
* user_order is the log2 of the number of buckets in the user hash table.
|
||||
* set this to approximately log2 of the max number of memory regions
|
||||
* that will be allocated for _all_ pools together.
|
||||
* set this to approximately log2 of the max number of memory regions
|
||||
* that will be allocated for _all_ pools together.
|
||||
* owner_order is the log2 of the number of buckets in the owner hash table.
|
||||
* set this to approximately log2 of
|
||||
* the number of client file connections that will
|
||||
* be using the manager.
|
||||
* set this to approximately log2 of
|
||||
* the number of client file connections that will
|
||||
* be using the manager.
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue