From fdc0b8a63c1124bb025a2846d41531a123845740 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 25 Oct 2011 16:32:34 +0200 Subject: drm/sis: track obj->drm_fd relations in the driver By attach a driver private struct to each open drm fd. Because we steal the owner_list from drm_sman until things settle, use list_move instead of list_add. This requires to export a drm_sman function temporarily before drm_sman will die for real completely. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_sman.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/drm/drm_sman.c') diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c index cebce45f4429..462cdc87cdb8 100644 --- a/drivers/gpu/drm/drm_sman.c +++ b/drivers/gpu/drm/drm_sman.c @@ -244,7 +244,7 @@ out: EXPORT_SYMBOL(drm_sman_alloc); -static void drm_sman_free(struct drm_memblock_item *item) +void drm_sman_free(struct drm_memblock_item *item) { struct drm_sman *sman = item->sman; @@ -253,6 +253,7 @@ static void drm_sman_free(struct drm_memblock_item *item) item->mm->free(item->mm->private, item->mm_info); kfree(item); } +EXPORT_SYMBOL(drm_sman_free); int drm_sman_free_key(struct drm_sman *sman, unsigned int key) { -- cgit v1.2.3 From aa38e2e01521f88e9b0230c0236d2bd89d0af0ed Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 25 Oct 2011 16:39:59 +0200 Subject: drm/sman: kill owner tracking interface functions These are now unused. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_sman.c | 38 -------------------------------------- include/drm/drm_sman.h | 19 ------------------- 2 files changed, 57 deletions(-) (limited to 'drivers/gpu/drm/drm_sman.c') diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c index 462cdc87cdb8..9d03cdc1a914 100644 --- a/drivers/gpu/drm/drm_sman.c +++ b/drivers/gpu/drm/drm_sman.c @@ -279,27 +279,6 @@ static void drm_sman_remove_owner(struct drm_sman *sman, kfree(owner_item); } -int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner) -{ - - struct drm_hash_item *hash_item; - struct drm_owner_item *owner_item; - - if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { - return -1; - } - - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash); - if (owner_item->mem_blocks.next == &owner_item->mem_blocks) { - drm_sman_remove_owner(sman, owner_item); - return -1; - } - - return 0; -} - -EXPORT_SYMBOL(drm_sman_owner_clean); - static void drm_sman_do_owner_cleanup(struct drm_sman *sman, struct drm_owner_item *owner_item) { @@ -312,23 +291,6 @@ static void drm_sman_do_owner_cleanup(struct drm_sman *sman, drm_sman_remove_owner(sman, owner_item); } -void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner) -{ - - struct drm_hash_item *hash_item; - struct drm_owner_item *owner_item; - - if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { - - return; - } - - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash); - drm_sman_do_owner_cleanup(sman, owner_item); -} - -EXPORT_SYMBOL(drm_sman_owner_cleanup); - void drm_sman_cleanup(struct drm_sman *sman) { struct drm_owner_item *entry, *next; diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h index 3b65ccfd1400..d5ed903867e3 100644 --- a/include/drm/drm_sman.h +++ b/include/drm/drm_sman.h @@ -148,25 +148,6 @@ extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman, extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key); extern void drm_sman_free(struct drm_memblock_item *item); -/* - * returns 1 iff there are no stale memory blocks associated with this owner. - * Typically called to determine if we need to idle the hardware and call - * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all - * resources associated with owner. - */ - -extern int drm_sman_owner_clean(struct drm_sman * sman, unsigned long owner); - -/* - * Frees all stale memory blocks associated with this owner. Note that this - * requires that the hardware is finished with all blocks, so the graphics engine - * should be idled before this call is made. This function also frees - * any resources associated with "owner" and should be called when owner - * is not going to be referenced anymore. - */ - -extern void drm_sman_owner_cleanup(struct drm_sman * sman, unsigned long owner); - /* * Frees all stale memory blocks associated with the memory manager. * See idling above. -- cgit v1.2.3 From 763240deb423c477b4d46c23e0b582099d4b8753 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Wed, 26 Oct 2011 22:28:07 +0200 Subject: drm/sman: rip out owner tracking In contrast to kms drivers, sis/via _always_ associated a buffer with a drm fd. So by the time we reach lastclose, all open drm fds are gone and with them their associated objects. So when sis/via call drm_sman_cleanup in their lastclose funcs, that will free 0 objects. The owner tracking now serves no purpose at all, hence rip it ou. We can't kill the corresponding fields in struct drm_memblock_item yet because we hijack these in the new driver private owner tracking. But now that drm_sman.c doesn't touch ->owner_list anymore, we need to kill the list_move hack and properly add the item to the file_priv list. Also leave the list_del(&obj->owner_list) in drm_sman_free for the moment, it will move to the drivers when sman disappears completely. v2: Remove the redundant INIT_LIST_HEAD as noted by Chris Wilson Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_sman.c | 71 -------------------------------------------- drivers/gpu/drm/sis/sis_mm.c | 2 +- drivers/gpu/drm/via/via_mm.c | 2 +- include/drm/drm_sman.h | 2 -- 4 files changed, 2 insertions(+), 75 deletions(-) (limited to 'drivers/gpu/drm/drm_sman.c') diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c index 9d03cdc1a914..af4728477a90 100644 --- a/drivers/gpu/drm/drm_sman.c +++ b/drivers/gpu/drm/drm_sman.c @@ -48,7 +48,6 @@ struct drm_owner_item { void drm_sman_takedown(struct drm_sman * sman) { drm_ht_remove(&sman->user_hash_tab); - drm_ht_remove(&sman->owner_hash_tab); kfree(sman->mm); } @@ -66,16 +65,10 @@ drm_sman_init(struct drm_sman * sman, unsigned int num_managers, goto out; } sman->num_managers = num_managers; - INIT_LIST_HEAD(&sman->owner_items); - ret = drm_ht_create(&sman->owner_hash_tab, owner_order); - if (ret) - goto out1; ret = drm_ht_create(&sman->user_hash_tab, user_order); if (!ret) goto out; - drm_ht_remove(&sman->owner_hash_tab); -out1: kfree(sman->mm); out: return ret; @@ -161,44 +154,12 @@ drm_sman_set_manager(struct drm_sman * sman, unsigned int manager, } EXPORT_SYMBOL(drm_sman_set_manager); -static struct drm_owner_item *drm_sman_get_owner_item(struct drm_sman * sman, - unsigned long owner) -{ - int ret; - struct drm_hash_item *owner_hash_item; - struct drm_owner_item *owner_item; - - ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item); - if (!ret) { - return drm_hash_entry(owner_hash_item, struct drm_owner_item, - owner_hash); - } - - owner_item = kzalloc(sizeof(*owner_item), GFP_KERNEL); - if (!owner_item) - goto out; - - INIT_LIST_HEAD(&owner_item->mem_blocks); - owner_item->owner_hash.key = owner; - if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash)) - goto out1; - - list_add_tail(&owner_item->sman_list, &sman->owner_items); - return owner_item; - -out1: - kfree(owner_item); -out: - return NULL; -} - struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int manager, unsigned long size, unsigned alignment, unsigned long owner) { void *tmp; struct drm_sman_mm *sman_mm; - struct drm_owner_item *owner_item; struct drm_memblock_item *memblock; BUG_ON(manager >= sman->num_managers); @@ -224,16 +185,8 @@ struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int man (unsigned long)memblock, 32, 0, 0)) goto out1; - owner_item = drm_sman_get_owner_item(sman, owner); - if (!owner_item) - goto out2; - - list_add_tail(&memblock->owner_list, &owner_item->mem_blocks); - return memblock; -out2: - drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash); out1: kfree(memblock); out: @@ -271,35 +224,11 @@ int drm_sman_free_key(struct drm_sman *sman, unsigned int key) EXPORT_SYMBOL(drm_sman_free_key); -static void drm_sman_remove_owner(struct drm_sman *sman, - struct drm_owner_item *owner_item) -{ - list_del(&owner_item->sman_list); - drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash); - kfree(owner_item); -} - -static void drm_sman_do_owner_cleanup(struct drm_sman *sman, - struct drm_owner_item *owner_item) -{ - struct drm_memblock_item *entry, *next; - - list_for_each_entry_safe(entry, next, &owner_item->mem_blocks, - owner_list) { - drm_sman_free(entry); - } - drm_sman_remove_owner(sman, owner_item); -} - void drm_sman_cleanup(struct drm_sman *sman) { - struct drm_owner_item *entry, *next; unsigned int i; struct drm_sman_mm *sman_mm; - list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) { - drm_sman_do_owner_cleanup(sman, entry); - } if (sman->mm) { for (i = 0; i < sman->num_managers; ++i) { sman_mm = &sman->mm[i]; diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c index a70b1bbff2e6..c76a118812a9 100644 --- a/drivers/gpu/drm/sis/sis_mm.c +++ b/drivers/gpu/drm/sis/sis_mm.c @@ -143,7 +143,7 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file, item = drm_sman_alloc(&dev_priv->sman, pool, mem->size, 0, 0); if (item) { - list_move(&item->owner_list, &file_priv->obj_list); + list_add(&item->owner_list, &file_priv->obj_list); mem->offset = ((pool == 0) ? dev_priv->vram_offset : dev_priv->agp_offset) + (item->mm-> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c index 19bb77cdeb46..e0110bc27606 100644 --- a/drivers/gpu/drm/via/via_mm.c +++ b/drivers/gpu/drm/via/via_mm.c @@ -141,7 +141,7 @@ int via_mem_alloc(struct drm_device *dev, void *data, item = drm_sman_alloc(&dev_priv->sman, mem->type, tmpSize, 0, 0); if (item) { - list_move(&item->owner_list, &file_priv->obj_list); + list_add(&item->owner_list, &file_priv->obj_list); mem->offset = ((mem->type == VIA_MEM_VIDEO) ? dev_priv->vram_offset : dev_priv->agp_offset) + (item->mm-> diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h index d5ed903867e3..34ae5ca05a40 100644 --- a/include/drm/drm_sman.h +++ b/include/drm/drm_sman.h @@ -87,9 +87,7 @@ struct drm_memblock_item { struct drm_sman { struct drm_sman_mm *mm; int num_managers; - struct drm_open_hash owner_hash_tab; struct drm_open_hash user_hash_tab; - struct list_head owner_items; }; /* -- cgit v1.2.3 From 94e895321bade1bafbcb2af1ef1e79b01e018012 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 25 Oct 2011 22:33:37 +0200 Subject: drm/sman: kill user_hash_tab No longer used. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_sman.c | 36 ++---------------------------------- include/drm/drm_sman.h | 5 ----- 2 files changed, 2 insertions(+), 39 deletions(-) (limited to 'drivers/gpu/drm/drm_sman.c') diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c index af4728477a90..a8ff350e50b8 100644 --- a/drivers/gpu/drm/drm_sman.c +++ b/drivers/gpu/drm/drm_sman.c @@ -47,7 +47,6 @@ struct drm_owner_item { void drm_sman_takedown(struct drm_sman * sman) { - drm_ht_remove(&sman->user_hash_tab); kfree(sman->mm); } @@ -62,16 +61,11 @@ drm_sman_init(struct drm_sman * sman, unsigned int num_managers, sman->mm = kcalloc(num_managers, sizeof(*sman->mm), GFP_KERNEL); if (!sman->mm) { ret = -ENOMEM; - goto out; + return ret; } sman->num_managers = num_managers; - ret = drm_ht_create(&sman->user_hash_tab, user_order); - if (!ret) - goto out; - kfree(sman->mm); -out: - return ret; + return 0; } EXPORT_SYMBOL(drm_sman_init); @@ -180,15 +174,8 @@ struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int man memblock->mm = sman_mm; memblock->sman = sman; - if (drm_ht_just_insert_please - (&sman->user_hash_tab, &memblock->user_hash, - (unsigned long)memblock, 32, 0, 0)) - goto out1; - return memblock; -out1: - kfree(memblock); out: sman_mm->free(sman_mm->private, tmp); @@ -199,31 +186,12 @@ EXPORT_SYMBOL(drm_sman_alloc); void drm_sman_free(struct drm_memblock_item *item) { - struct drm_sman *sman = item->sman; - list_del(&item->owner_list); - drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash); item->mm->free(item->mm->private, item->mm_info); kfree(item); } EXPORT_SYMBOL(drm_sman_free); -int drm_sman_free_key(struct drm_sman *sman, unsigned int key) -{ - struct drm_hash_item *hash_item; - struct drm_memblock_item *memblock_item; - - if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item)) - return -EINVAL; - - memblock_item = drm_hash_entry(hash_item, struct drm_memblock_item, - user_hash); - drm_sman_free(memblock_item); - return 0; -} - -EXPORT_SYMBOL(drm_sman_free_key); - void drm_sman_cleanup(struct drm_sman *sman) { unsigned int i; diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h index 34ae5ca05a40..031e52189295 100644 --- a/include/drm/drm_sman.h +++ b/include/drm/drm_sman.h @@ -87,7 +87,6 @@ struct drm_memblock_item { struct drm_sman { struct drm_sman_mm *mm; int num_managers; - struct drm_open_hash user_hash_tab; }; /* @@ -139,11 +138,7 @@ extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman, unsigned long size, unsigned alignment, unsigned long owner); -/* - * Free a memory block identified by its user hash key. - */ -extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key); extern void drm_sman_free(struct drm_memblock_item *item); /* -- cgit v1.2.3 From 7a6e0daaf4058d1b7dd515bc470ec904454a798c Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 25 Oct 2011 23:19:27 +0200 Subject: drm: kill drm_sman No longer used. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_sman.c | 211 --------------------------------------------- include/drm/drm_sman.h | 151 -------------------------------- 3 files changed, 1 insertion(+), 363 deletions(-) delete mode 100644 drivers/gpu/drm/drm_sman.c delete mode 100644 include/drm/drm_sman.h (limited to 'drivers/gpu/drm/drm_sman.c') diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 6307486b1637..0cde1b80fdb1 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -9,7 +9,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \ drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \ drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \ drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ - drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \ + drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ drm_crtc.o drm_modes.o drm_edid.o \ drm_info.o drm_debugfs.o drm_encoder_slave.o \ drm_trace_points.o drm_global.o drm_usb.o diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c deleted file mode 100644 index a8ff350e50b8..000000000000 --- a/drivers/gpu/drm/drm_sman.c +++ /dev/null @@ -1,211 +0,0 @@ -/************************************************************************** - * - * 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 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ -/* - * Simple memory manager interface that keeps track on allocate regions on a - * per "owner" basis. All regions associated with an "owner" can be released - * with a simple call. Typically if the "owner" exists. The owner is any - * "unsigned long" identifier. Can typically be a pointer to a file private - * struct or a context identifier. - * - * Authors: - * Thomas Hellström - */ - -#include -#include "drm_sman.h" - -struct drm_owner_item { - struct drm_hash_item owner_hash; - struct list_head sman_list; - struct list_head mem_blocks; -}; - -void drm_sman_takedown(struct drm_sman * sman) -{ - kfree(sman->mm); -} - -EXPORT_SYMBOL(drm_sman_takedown); - -int -drm_sman_init(struct drm_sman * sman, unsigned int num_managers, - unsigned int user_order, unsigned int owner_order) -{ - int ret = 0; - - sman->mm = kcalloc(num_managers, sizeof(*sman->mm), GFP_KERNEL); - if (!sman->mm) { - ret = -ENOMEM; - return ret; - } - sman->num_managers = num_managers; - - return 0; -} - -EXPORT_SYMBOL(drm_sman_init); - -static void *drm_sman_mm_allocate(void *private, unsigned long size, - unsigned alignment) -{ - struct drm_mm *mm = (struct drm_mm *) private; - struct drm_mm_node *tmp; - - tmp = drm_mm_search_free(mm, size, alignment, 1); - if (!tmp) { - return NULL; - } - tmp = drm_mm_get_block(tmp, size, alignment); - return tmp; -} - -static void drm_sman_mm_free(void *private, void *ref) -{ - struct drm_mm_node *node = (struct drm_mm_node *) ref; - - drm_mm_put_block(node); -} - -static void drm_sman_mm_destroy(void *private) -{ - struct drm_mm *mm = (struct drm_mm *) private; - drm_mm_takedown(mm); - kfree(mm); -} - -static unsigned long drm_sman_mm_offset(void *private, void *ref) -{ - struct drm_mm_node *node = (struct drm_mm_node *) ref; - return node->start; -} - -int -drm_sman_set_range(struct drm_sman * sman, unsigned int manager, - unsigned long start, unsigned long size) -{ - struct drm_sman_mm *sman_mm; - struct drm_mm *mm; - int ret; - - BUG_ON(manager >= sman->num_managers); - - sman_mm = &sman->mm[manager]; - mm = kzalloc(sizeof(*mm), GFP_KERNEL); - if (!mm) { - return -ENOMEM; - } - sman_mm->private = mm; - ret = drm_mm_init(mm, start, size); - - if (ret) { - kfree(mm); - return ret; - } - - sman_mm->allocate = drm_sman_mm_allocate; - sman_mm->free = drm_sman_mm_free; - sman_mm->destroy = drm_sman_mm_destroy; - sman_mm->offset = drm_sman_mm_offset; - - return 0; -} - -EXPORT_SYMBOL(drm_sman_set_range); - -int -drm_sman_set_manager(struct drm_sman * sman, unsigned int manager, - struct drm_sman_mm * allocator) -{ - BUG_ON(manager >= sman->num_managers); - sman->mm[manager] = *allocator; - - return 0; -} -EXPORT_SYMBOL(drm_sman_set_manager); - -struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int manager, - unsigned long size, unsigned alignment, - unsigned long owner) -{ - void *tmp; - struct drm_sman_mm *sman_mm; - struct drm_memblock_item *memblock; - - BUG_ON(manager >= sman->num_managers); - - sman_mm = &sman->mm[manager]; - tmp = sman_mm->allocate(sman_mm->private, size, alignment); - - if (!tmp) { - return NULL; - } - - memblock = kzalloc(sizeof(*memblock), GFP_KERNEL); - - if (!memblock) - goto out; - - memblock->mm_info = tmp; - memblock->mm = sman_mm; - memblock->sman = sman; - - return memblock; - -out: - sman_mm->free(sman_mm->private, tmp); - - return NULL; -} - -EXPORT_SYMBOL(drm_sman_alloc); - -void drm_sman_free(struct drm_memblock_item *item) -{ - list_del(&item->owner_list); - item->mm->free(item->mm->private, item->mm_info); - kfree(item); -} -EXPORT_SYMBOL(drm_sman_free); - -void drm_sman_cleanup(struct drm_sman *sman) -{ - unsigned int i; - struct drm_sman_mm *sman_mm; - - if (sman->mm) { - for (i = 0; i < sman->num_managers; ++i) { - sman_mm = &sman->mm[i]; - if (sman_mm->private) { - sman_mm->destroy(sman_mm->private); - sman_mm->private = NULL; - } - } - } -} - -EXPORT_SYMBOL(drm_sman_cleanup); diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h deleted file mode 100644 index 031e52189295..000000000000 --- a/include/drm/drm_sman.h +++ /dev/null @@ -1,151 +0,0 @@ -/************************************************************************** - * - * 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 memory MANager interface that keeps track on allocate regions on a - * per "owner" basis. All regions associated with an "owner" can be released - * with a simple call. Typically if the "owner" exists. The owner is any - * "unsigned long" identifier. Can typically be a pointer to a file private - * struct or a context identifier. - * - * Authors: - * Thomas Hellström - */ - -#ifndef DRM_SMAN_H -#define DRM_SMAN_H - -#include "drmP.h" -#include "drm_hashtab.h" - -/* - * A class that is an abstration of a simple memory allocator. - * The sman implementation provides a default such allocator - * using the drm_mm.c implementation. But the user can replace it. - * See the SiS implementation, which may use the SiS FB kernel module - * for memory management. - */ - -struct drm_sman_mm { - /* private info. If allocated, needs to be destroyed by the destroy - function */ - void *private; - - /* Allocate a memory block with given size and alignment. - Return an opaque reference to the memory block */ - - void *(*allocate) (void *private, unsigned long size, - unsigned alignment); - - /* Free a memory block. "ref" is the opaque reference that we got from - the "alloc" function */ - - void (*free) (void *private, void *ref); - - /* Free all resources associated with this allocator */ - - void (*destroy) (void *private); - - /* Return a memory offset from the opaque reference returned from the - "alloc" function */ - - unsigned long (*offset) (void *private, void *ref); -}; - -struct drm_memblock_item { - struct list_head owner_list; - struct drm_hash_item user_hash; - void *mm_info; - struct drm_sman_mm *mm; - struct drm_sman *sman; -}; - -struct drm_sman { - struct drm_sman_mm *mm; - int num_managers; -}; - -/* - * Take down a memory manager. This function should only be called after a - * successful init and after a call to drm_sman_cleanup. - */ - -extern void drm_sman_takedown(struct drm_sman * 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. - * 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. - * - */ - -extern int drm_sman_init(struct drm_sman * sman, unsigned int num_managers, - unsigned int user_order, unsigned int owner_order); - -/* - * Initialize a drm_mm.c allocator. Should be called only once for each - * manager unless a customized allogator is used. - */ - -extern int drm_sman_set_range(struct drm_sman * sman, unsigned int manager, - unsigned long start, unsigned long size); - -/* - * Initialize a customized allocator for one of the managers. - * (See the SiS module). The object pointed to by "allocator" is copied, - * so it can be destroyed after this call. - */ - -extern int drm_sman_set_manager(struct drm_sman * sman, unsigned int mananger, - struct drm_sman_mm * allocator); - -/* - * Allocate a memory block. Aligment is not implemented yet. - */ - -extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman, - unsigned int manager, - unsigned long size, - unsigned alignment, - unsigned long owner); - -extern void drm_sman_free(struct drm_memblock_item *item); - -/* - * Frees all stale memory blocks associated with the memory manager. - * See idling above. - */ - -extern void drm_sman_cleanup(struct drm_sman * sman); - -#endif -- cgit v1.2.3