drm: fixup whitespace and style for Linux kernel import

main
Dave Airlie 2006-08-07 20:56:38 +10:00
parent 35066b51ef
commit 248d1a32a2
4 changed files with 197 additions and 203 deletions

View File

@ -36,161 +36,155 @@
#include "drm_hashtab.h" #include "drm_hashtab.h"
#include <linux/hash.h> #include <linux/hash.h>
int int drm_ht_create(drm_open_hash_t *ht, unsigned int order)
drm_ht_create(drm_open_hash_t *ht, unsigned int order)
{ {
unsigned int i; unsigned int i;
ht->size = 1 << order; ht->size = 1 << order;
ht->order = order; ht->order = order;
ht->fill = 0; ht->fill = 0;
ht->table = vmalloc(ht->size*sizeof(*ht->table)); ht->table = vmalloc(ht->size*sizeof(*ht->table));
if (!ht->table) { if (!ht->table) {
DRM_ERROR("Out of memory for hash table\n"); DRM_ERROR("Out of memory for hash table\n");
return -ENOMEM; return -ENOMEM;
} }
for (i=0; i< ht->size; ++i) { for (i=0; i< ht->size; ++i) {
INIT_HLIST_HEAD(&ht->table[i]); INIT_HLIST_HEAD(&ht->table[i]);
} }
return 0; return 0;
} }
void void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
{ {
drm_hash_item_t *entry; drm_hash_item_t *entry;
struct hlist_head *h_list; struct hlist_head *h_list;
struct hlist_node *list; struct hlist_node *list;
unsigned int hashed_key; unsigned int hashed_key;
int count = 0; int count = 0;
hashed_key = hash_long(key, ht->order); hashed_key = hash_long(key, ht->order);
DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key); DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
h_list = &ht->table[hashed_key]; h_list = &ht->table[hashed_key];
hlist_for_each(list, h_list) { hlist_for_each(list, h_list) {
entry = hlist_entry(list, drm_hash_item_t, head); entry = hlist_entry(list, drm_hash_item_t, head);
DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key); DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
} }
} }
static struct hlist_node static struct hlist_node *drm_ht_find_key(drm_open_hash_t *ht,
*drm_ht_find_key(drm_open_hash_t *ht, unsigned long key) unsigned long key)
{ {
drm_hash_item_t *entry; drm_hash_item_t *entry;
struct hlist_head *h_list; struct hlist_head *h_list;
struct hlist_node *list; struct hlist_node *list;
unsigned int hashed_key; unsigned int hashed_key;
hashed_key = hash_long(key, ht->order); hashed_key = hash_long(key, ht->order);
h_list = &ht->table[hashed_key]; h_list = &ht->table[hashed_key];
hlist_for_each(list, h_list) { hlist_for_each(list, h_list) {
entry = hlist_entry(list, drm_hash_item_t, head); entry = hlist_entry(list, drm_hash_item_t, head);
if (entry->key == key) if (entry->key == key)
return list; return list;
if (entry->key > key) if (entry->key > key)
break; break;
} }
return NULL; return NULL;
} }
int int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
{ {
drm_hash_item_t *entry; drm_hash_item_t *entry;
struct hlist_head *h_list; struct hlist_head *h_list;
struct hlist_node *list, *parent; struct hlist_node *list, *parent;
unsigned int hashed_key; unsigned int hashed_key;
unsigned long key = item->key; unsigned long key = item->key;
hashed_key = hash_long(key, ht->order); hashed_key = hash_long(key, ht->order);
h_list = &ht->table[hashed_key]; h_list = &ht->table[hashed_key];
parent = NULL; parent = NULL;
hlist_for_each(list, h_list) { hlist_for_each(list, h_list) {
entry = hlist_entry(list, drm_hash_item_t, head); entry = hlist_entry(list, drm_hash_item_t, head);
if (entry->key == key) if (entry->key == key)
return -1; return -1;
if (entry->key > key) if (entry->key > key)
break; break;
parent = list; parent = list;
} }
if (parent) { if (parent) {
hlist_add_after(parent, &item->head); hlist_add_after(parent, &item->head);
} else { } else {
hlist_add_head(&item->head, h_list); hlist_add_head(&item->head, h_list);
} }
return 0; 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,
int unsigned long seed, int bits, int shift,
drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item, unsigned long add)
unsigned long seed, int bits, int shift,
unsigned long add)
{ {
int ret; int ret;
unsigned long mask = (1 << bits) - 1; unsigned long mask = (1 << bits) - 1;
unsigned long first, unshifted_key; unsigned long first, unshifted_key;
unshifted_key = hash_long(seed, bits); unshifted_key = hash_long(seed, bits);
first = unshifted_key; first = unshifted_key;
do{ do {
item->key = (unshifted_key << shift) + add; item->key = (unshifted_key << shift) + add;
ret = drm_ht_insert_item(ht, item); ret = drm_ht_insert_item(ht, item);
if (ret) if (ret)
unshifted_key = (unshifted_key + 1) & mask; unshifted_key = (unshifted_key + 1) & mask;
} while(ret && (unshifted_key != first)); } while(ret && (unshifted_key != first));
if (ret) { if (ret) {
DRM_ERROR("Available key bit space exhausted\n"); DRM_ERROR("Available key bit space exhausted\n");
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
int int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key,
drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, drm_hash_item_t **item) drm_hash_item_t **item)
{ {
struct hlist_node *list; struct hlist_node *list;
list = drm_ht_find_key(ht, key); list = drm_ht_find_key(ht, key);
if (!list) if (!list)
return -1; return -1;
*item = hlist_entry(list, drm_hash_item_t, head); *item = hlist_entry(list, drm_hash_item_t, head);
return 0; return 0;
} }
int int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key)
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); list = drm_ht_find_key(ht, key);
if (list) { if (list) {
hlist_del_init(list); hlist_del_init(list);
ht->fill--; ht->fill--;
return 0; return 0;
} }
return -1; return -1;
} }
int int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
{ {
hlist_del_init(&item->head); hlist_del_init(&item->head);
ht->fill--; ht->fill--;
return 0; return 0;
} }
void drm_ht_remove(drm_open_hash_t *ht) void drm_ht_remove(drm_open_hash_t *ht)
{ {
if (ht->table) { if (ht->table) {
vfree(ht->table); vfree(ht->table);
ht->table = NULL; ht->table = NULL;
} }
} }

View File

@ -38,15 +38,15 @@
#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member) #define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
typedef struct drm_hash_item{ typedef struct drm_hash_item{
struct hlist_node head; struct hlist_node head;
unsigned long key; unsigned long key;
} drm_hash_item_t; } drm_hash_item_t;
typedef struct drm_open_hash{ typedef struct drm_open_hash{
unsigned int size; unsigned int size;
unsigned int order; unsigned int order;
unsigned int fill; unsigned int fill;
struct hlist_head *table; struct hlist_head *table;
} drm_open_hash_t; } drm_open_hash_t;

View File

@ -77,9 +77,9 @@ drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
goto out; goto out;
drm_ht_remove(&sman->owner_hash_tab); drm_ht_remove(&sman->owner_hash_tab);
out1: out1:
drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM); drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
out: out:
return ret; return ret;
} }
@ -163,8 +163,8 @@ drm_sman_set_manager(drm_sman_t * sman, unsigned int manager,
return 0; return 0;
} }
static drm_owner_item_t static drm_owner_item_t *drm_sman_get_owner_item(drm_sman_t * sman,
* drm_sman_get_owner_item(drm_sman_t * sman, unsigned long owner) unsigned long owner)
{ {
int ret; int ret;
drm_hash_item_t *owner_hash_item; 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); ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
if (!ret) { if (!ret) {
return drm_hash_entry(owner_hash_item, drm_owner_item_t, 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); 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); list_add_tail(&owner_item->sman_list, &sman->owner_items);
return owner_item; return owner_item;
out1: out1:
drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM); drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
out: out:
return NULL; 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 size, unsigned alignment,
unsigned long owner) unsigned long owner)
{ {
@ -234,11 +234,11 @@ drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, unsigned int manager,
return memblock; return memblock;
out2: out2:
drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash); drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
out1: out1:
drm_free(memblock, sizeof(*memblock), DRM_MEM_MM); drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
out: out:
sman_mm->free(sman_mm->private, tmp); sman_mm->free(sman_mm->private, tmp);
return NULL; 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); 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; 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); 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_hash_item_t *hash_item;
drm_memblock_item_t *memblock_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); EXPORT_SYMBOL(drm_sman_free_key);
static void static void drm_sman_remove_owner(drm_sman_t *sman,
drm_sman_remove_owner(drm_sman_t * sman, drm_owner_item_t * owner_item) drm_owner_item_t *owner_item)
{ {
list_del(&owner_item->sman_list); list_del(&owner_item->sman_list);
drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash); drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM); 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; 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); EXPORT_SYMBOL(drm_sman_owner_clean);
static void static void drm_sman_do_owner_cleanup(drm_sman_t *sman,
drm_sman_do_owner_cleanup(drm_sman_t * sman, drm_owner_item_t * owner_item) drm_owner_item_t *owner_item)
{ {
drm_memblock_item_t *entry, *next; 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); 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; 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); 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; drm_owner_item_t *entry, *next;
unsigned int i; unsigned int i;

View File

@ -103,12 +103,12 @@ extern void drm_sman_takedown(drm_sman_t * sman);
* Allocate structures for a manager. * Allocate structures for a manager.
* num_managers are the number of memory pools to manage. (VRAM, AGP, ....) * 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. * 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 * set this to approximately log2 of the max number of memory regions
* that will be allocated for _all_ pools together. * that will be allocated for _all_ pools together.
* owner_order is the log2 of the number of buckets in the owner hash table. * owner_order is the log2 of the number of buckets in the owner hash table.
* set this to approximately log2 of * set this to approximately log2 of
* the number of client file connections that will * the number of client file connections that will
* be using the manager. * be using the manager.
* *
*/ */