From 7af9d670371de868f0642148fe2d594bc9a7dea3 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 26 Jun 2007 13:05:29 -0700 Subject: Initial XP10 code drop from XGI. See attachment 10246 on https://bugs.freedesktop.org/show_bug.cgi?id=5921 --- linux-core/xgi_fb.c | 528 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 528 insertions(+) create mode 100644 linux-core/xgi_fb.c (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c new file mode 100644 index 00000000..67fdfe17 --- /dev/null +++ b/linux-core/xgi_fb.c @@ -0,0 +1,528 @@ + +/**************************************************************************** + * Copyright (C) 2003-2006 by XGI Technology, Taiwan. + * * + * 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 on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, 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 XGI 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. + ***************************************************************************/ + +#include "xgi_types.h" +#include "xgi_linux.h" +#include "xgi_drv.h" +#include "xgi_fb.h" + +#define XGI_FB_HEAP_START 0x1000000 + +static xgi_mem_heap_t *xgi_fb_heap; +static kmem_cache_t *xgi_fb_cache_block = NULL; +extern struct list_head xgi_mempid_list; + +static xgi_mem_block_t *xgi_mem_new_node(void); +static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t *info, unsigned long size); +static xgi_mem_block_t *xgi_mem_free(xgi_info_t *info, unsigned long offset); + +void xgi_fb_alloc(xgi_info_t *info, + xgi_mem_req_t *req, + xgi_mem_alloc_t *alloc) +{ + xgi_mem_block_t *block; + xgi_mem_pid_t *mempid_block; + + if (req->is_front) + { + alloc->location = LOCAL; + alloc->bus_addr = info->fb.base; + alloc->hw_addr = 0; + XGI_INFO("Video RAM allocation on front buffer successfully! \n"); + } + else + { + xgi_down(info->fb_sem); + block = xgi_mem_alloc(info, req->size); + xgi_up(info->fb_sem); + + if (block == NULL) + { + alloc->location = LOCAL; + alloc->size = 0; + alloc->bus_addr = 0; + alloc->hw_addr = 0; + XGI_ERROR("Video RAM allocation failed\n"); + } + else + { + XGI_INFO("Video RAM allocation succeeded: 0x%p\n", + (char *) block->offset); + alloc->location = LOCAL; + alloc->size = block->size; + alloc->bus_addr = info->fb.base + block->offset; + alloc->hw_addr = block->offset; + + /* manage mempid */ + mempid_block = kmalloc(sizeof(xgi_mem_pid_t), GFP_KERNEL); + mempid_block->location = LOCAL; + mempid_block->bus_addr = alloc->bus_addr; + mempid_block->pid = alloc->pid; + + if (!mempid_block) + XGI_ERROR("mempid_block alloc failed\n"); + + XGI_INFO("Memory ProcessID add one fb block pid:%ld successfully! \n", mempid_block->pid); + list_add(&mempid_block->list, &xgi_mempid_list); + } + } +} + +void xgi_fb_free(xgi_info_t *info, unsigned long bus_addr) +{ + xgi_mem_block_t *block; + unsigned long offset = bus_addr - info->fb.base; + xgi_mem_pid_t *mempid_block; + xgi_mem_pid_t *mempid_freeblock = NULL; + struct list_head *mempid_list; + + if (offset < 0) + { + XGI_INFO("free onscreen frame buffer successfully !\n"); + } + else + { + xgi_down(info->fb_sem); + block = xgi_mem_free(info, offset); + xgi_up(info->fb_sem); + + if (block == NULL) + { + XGI_ERROR("xgi_mem_free() failed at base 0x%lx\n", offset); + } + + /* manage mempid */ + mempid_list = xgi_mempid_list.next; + while (mempid_list != &xgi_mempid_list) + { + mempid_block = list_entry(mempid_list, struct xgi_mem_pid_s, list); + if (mempid_block->location == LOCAL && mempid_block->bus_addr == bus_addr) + { + mempid_freeblock = mempid_block; + break; + } + mempid_list = mempid_list->next; + } + if (mempid_freeblock) + { + list_del(&mempid_freeblock->list); + XGI_INFO("Memory ProcessID delete one fb block pid:%ld successfully! \n", mempid_freeblock->pid); + kfree(mempid_freeblock); + } + } +} + +int xgi_fb_heap_init(xgi_info_t *info) +{ + xgi_mem_block_t *block; + + xgi_fb_heap = kmalloc(sizeof(xgi_mem_heap_t), GFP_KERNEL); + if (!xgi_fb_heap) + { + XGI_ERROR("xgi_fb_heap alloc failed\n"); + return 0; + } + + INIT_LIST_HEAD(&xgi_fb_heap->free_list); + INIT_LIST_HEAD(&xgi_fb_heap->used_list); + INIT_LIST_HEAD(&xgi_fb_heap->sort_list); + + xgi_fb_cache_block = kmem_cache_create("xgi_fb_block", sizeof(xgi_mem_block_t), + 0, SLAB_HWCACHE_ALIGN, NULL, NULL); + + if (NULL == xgi_fb_cache_block) + { + XGI_ERROR("Fail to creat xgi_fb_block\n"); + goto fail1; + } + + block = (xgi_mem_block_t *)kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); + if (!block) + { + XGI_ERROR("kmem_cache_alloc failed\n"); + goto fail2; + } + + block->offset = XGI_FB_HEAP_START; + block->size = info->fb.size - XGI_FB_HEAP_START; + + list_add(&block->list, &xgi_fb_heap->free_list); + + xgi_fb_heap->max_freesize = info->fb.size - XGI_FB_HEAP_START; + + XGI_INFO("fb start offset: 0x%lx, memory size : 0x%lx\n", block->offset, block->size); + XGI_INFO("xgi_fb_heap->max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); + + return 1; + +fail2: + if (xgi_fb_cache_block) + { + kmem_cache_destroy(xgi_fb_cache_block); + xgi_fb_cache_block = NULL; + } +fail1: + if(xgi_fb_heap) + { + kfree(xgi_fb_heap); + xgi_fb_heap = NULL; + } + return 0; +} + +void xgi_fb_heap_cleanup(xgi_info_t *info) +{ + struct list_head *free_list, *temp; + xgi_mem_block_t *block; + int i; + + if (xgi_fb_heap) + { + free_list = &xgi_fb_heap->free_list; + for (i = 0; i < 3; i++, free_list++) + { + temp = free_list->next; + while (temp != free_list) + { + block = list_entry(temp, struct xgi_mem_block_s, list); + temp = temp->next; + + XGI_INFO("No. %d block->offset: 0x%lx block->size: 0x%lx \n", + i, block->offset, block->size); + //XGI_INFO("No. %d free block: 0x%p \n", i, block); + kmem_cache_free(xgi_fb_cache_block, block); + block = NULL; + } + } + XGI_INFO("xgi_fb_heap: 0x%p \n", xgi_fb_heap); + kfree(xgi_fb_heap); + xgi_fb_heap = NULL; + } + + if (xgi_fb_cache_block) + { + kmem_cache_destroy(xgi_fb_cache_block); + xgi_fb_cache_block = NULL; + } +} + +static xgi_mem_block_t * xgi_mem_new_node(void) +{ + xgi_mem_block_t *block; + + block = (xgi_mem_block_t *)kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); + if (!block) + { + XGI_ERROR("kmem_cache_alloc failed\n"); + return NULL; + } + + return block; +} + +#if 0 +static void xgi_mem_insert_node_after(xgi_mem_list_t *list, + xgi_mem_block_t *current, + xgi_mem_block_t *block); +static void xgi_mem_insert_node_before(xgi_mem_list_t *list, + xgi_mem_block_t *current, + xgi_mem_block_t *block); +static void xgi_mem_insert_node_head(xgi_mem_list_t *list, + xgi_mem_block_t *block); +static void xgi_mem_insert_node_tail(xgi_mem_list_t *list, + xgi_mem_block_t *block); +static void xgi_mem_delete_node(xgi_mem_list_t *list, + xgi_mem_block_t *block); +/* + * insert node:block after node:current + */ +static void xgi_mem_insert_node_after(xgi_mem_list_t *list, + xgi_mem_block_t *current, + xgi_mem_block_t *block) +{ + block->prev = current; + block->next = current->next; + current->next = block; + + if (current == list->tail) + { + list->tail = block; + } + else + { + block->next->prev = block; + } +} + +/* + * insert node:block before node:current + */ +static void xgi_mem_insert_node_before(xgi_mem_list_t *list, + xgi_mem_block_t *current, + xgi_mem_block_t *block) +{ + block->prev = current->prev; + block->next = current; + current->prev = block; + if (current == list->head) + { + list->head = block; + } + else + { + block->prev->next = block; + } +} +void xgi_mem_insert_node_head(xgi_mem_list_t *list, + xgi_mem_block_t *block) +{ + block->next = list->head; + block->prev = NULL; + + if (NULL == list->head) + { + list->tail = block; + } + else + { + list->head->prev = block; + } + list->head = block; +} + +static void xgi_mem_insert_node_tail(xgi_mem_list_t *list, + xgi_mem_block_t *block) + +{ + block->next = NULL; + block->prev = list->tail; + if (NULL == list->tail) + { + list->head = block; + } + else + { + list->tail->next = block; + } + list->tail = block; +} + +static void xgi_mem_delete_node(xgi_mem_list_t *list, + xgi_mem_block_t *block) +{ + if (block == list->head) + { + list->head = block->next; + } + if (block == list->tail) + { + list->tail = block->prev; + } + + if (block->prev) + { + block->prev->next = block->next; + } + if (block->next) + { + block->next->prev = block->prev; + } + + block->next = block->prev = NULL; +} +#endif +static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t *info, unsigned long originalSize) +{ + struct list_head *free_list; + xgi_mem_block_t *block, *free_block, *used_block; + + unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; + + XGI_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", originalSize, size); + + if (size == 0) + { + XGI_ERROR("size == 0\n"); + return (NULL); + } + XGI_INFO("max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); + if (size > xgi_fb_heap->max_freesize) + { + XGI_ERROR("size: 0x%lx is bigger than frame buffer total free size: 0x%lx !\n", + size, xgi_fb_heap->max_freesize); + return (NULL); + } + + free_list = xgi_fb_heap->free_list.next; + + while (free_list != &xgi_fb_heap->free_list) + { + XGI_INFO("free_list: 0x%px \n", free_list); + block = list_entry(free_list, struct xgi_mem_block_s, list); + if (size <= block->size) + { + break; + } + free_list = free_list->next; + } + + if (free_list == &xgi_fb_heap->free_list) + { + XGI_ERROR("Can't allocate %ldk size from frame buffer memory !\n", size/1024); + return (NULL); + } + + free_block = block; + XGI_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", + size, free_block->offset, free_block->size); + + if (size == free_block->size) + { + used_block = free_block; + XGI_INFO("size == free_block->size: free_block = 0x%p\n", free_block); + list_del(&free_block->list); + } + else + { + used_block = xgi_mem_new_node(); + + if (used_block == NULL) return (NULL); + + if (used_block == free_block) + { + XGI_ERROR("used_block == free_block = 0x%p\n", used_block); + } + + used_block->offset = free_block->offset; + used_block->size = size; + + free_block->offset += size; + free_block->size -= size; + } + + xgi_fb_heap->max_freesize -= size; + + list_add(&used_block->list, &xgi_fb_heap->used_list); + + return (used_block); +} + +static xgi_mem_block_t *xgi_mem_free(xgi_info_t *info, unsigned long offset) +{ + struct list_head *free_list, *used_list; + xgi_mem_block_t *used_block = NULL, *block = NULL; + xgi_mem_block_t *prev, *next; + + unsigned long upper; + unsigned long lower; + + used_list = xgi_fb_heap->used_list.next; + while (used_list != &xgi_fb_heap->used_list) + { + block = list_entry(used_list, struct xgi_mem_block_s, list); + if (block->offset == offset) + { + break; + } + used_list = used_list->next; + } + + if (used_list == &xgi_fb_heap->used_list) + { + XGI_ERROR("can't find block: 0x%lx to free!\n", offset); + return (NULL); + } + + used_block = block; + XGI_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", + used_block, used_block->offset, used_block->size); + + xgi_fb_heap->max_freesize += used_block->size; + + prev = next = NULL; + upper = used_block->offset + used_block->size; + lower = used_block->offset; + + free_list = xgi_fb_heap->free_list.next; + while (free_list != &xgi_fb_heap->free_list) + { + block = list_entry(free_list, struct xgi_mem_block_s, list); + + if (block->offset == upper) + { + next = block; + } + else if ((block->offset + block->size) == lower) + { + prev = block; + } + free_list = free_list->next; + } + + XGI_INFO("next = 0x%p, prev = 0x%p\n", next, prev); + list_del(&used_block->list); + + if (prev && next) + { + prev->size += (used_block->size + next->size); + list_del(&next->list); + XGI_INFO("free node 0x%p\n", next); + kmem_cache_free(xgi_fb_cache_block, next); + kmem_cache_free(xgi_fb_cache_block, used_block); + + next = NULL; + used_block = NULL; + return (prev); + } + + if (prev) + { + prev->size += used_block->size; + XGI_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_fb_cache_block, used_block); + used_block = NULL; + return (prev); + } + + if (next) + { + next->size += used_block->size; + next->offset = used_block->offset; + XGI_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_fb_cache_block, used_block); + used_block = NULL; + return (next); + } + + list_add(&used_block->list, &xgi_fb_heap->free_list); + XGI_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", + used_block, used_block->offset, used_block->size); + + return (used_block); +} + -- cgit v1.2.3 From 434657a2582362367ba2a94f827511252001368f Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 26 Jun 2007 13:10:30 -0700 Subject: dos2unix and Lindent --- linux-core/xgi_fb.c | 1019 +++++++++++++++++++++++++-------------------------- 1 file changed, 491 insertions(+), 528 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 67fdfe17..fab99ae2 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -1,528 +1,491 @@ - -/**************************************************************************** - * Copyright (C) 2003-2006 by XGI Technology, Taiwan. - * * - * 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 on the rights to use, copy, modify, merge, - * publish, distribute, sublicense, 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 XGI 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. - ***************************************************************************/ - -#include "xgi_types.h" -#include "xgi_linux.h" -#include "xgi_drv.h" -#include "xgi_fb.h" - -#define XGI_FB_HEAP_START 0x1000000 - -static xgi_mem_heap_t *xgi_fb_heap; -static kmem_cache_t *xgi_fb_cache_block = NULL; -extern struct list_head xgi_mempid_list; - -static xgi_mem_block_t *xgi_mem_new_node(void); -static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t *info, unsigned long size); -static xgi_mem_block_t *xgi_mem_free(xgi_info_t *info, unsigned long offset); - -void xgi_fb_alloc(xgi_info_t *info, - xgi_mem_req_t *req, - xgi_mem_alloc_t *alloc) -{ - xgi_mem_block_t *block; - xgi_mem_pid_t *mempid_block; - - if (req->is_front) - { - alloc->location = LOCAL; - alloc->bus_addr = info->fb.base; - alloc->hw_addr = 0; - XGI_INFO("Video RAM allocation on front buffer successfully! \n"); - } - else - { - xgi_down(info->fb_sem); - block = xgi_mem_alloc(info, req->size); - xgi_up(info->fb_sem); - - if (block == NULL) - { - alloc->location = LOCAL; - alloc->size = 0; - alloc->bus_addr = 0; - alloc->hw_addr = 0; - XGI_ERROR("Video RAM allocation failed\n"); - } - else - { - XGI_INFO("Video RAM allocation succeeded: 0x%p\n", - (char *) block->offset); - alloc->location = LOCAL; - alloc->size = block->size; - alloc->bus_addr = info->fb.base + block->offset; - alloc->hw_addr = block->offset; - - /* manage mempid */ - mempid_block = kmalloc(sizeof(xgi_mem_pid_t), GFP_KERNEL); - mempid_block->location = LOCAL; - mempid_block->bus_addr = alloc->bus_addr; - mempid_block->pid = alloc->pid; - - if (!mempid_block) - XGI_ERROR("mempid_block alloc failed\n"); - - XGI_INFO("Memory ProcessID add one fb block pid:%ld successfully! \n", mempid_block->pid); - list_add(&mempid_block->list, &xgi_mempid_list); - } - } -} - -void xgi_fb_free(xgi_info_t *info, unsigned long bus_addr) -{ - xgi_mem_block_t *block; - unsigned long offset = bus_addr - info->fb.base; - xgi_mem_pid_t *mempid_block; - xgi_mem_pid_t *mempid_freeblock = NULL; - struct list_head *mempid_list; - - if (offset < 0) - { - XGI_INFO("free onscreen frame buffer successfully !\n"); - } - else - { - xgi_down(info->fb_sem); - block = xgi_mem_free(info, offset); - xgi_up(info->fb_sem); - - if (block == NULL) - { - XGI_ERROR("xgi_mem_free() failed at base 0x%lx\n", offset); - } - - /* manage mempid */ - mempid_list = xgi_mempid_list.next; - while (mempid_list != &xgi_mempid_list) - { - mempid_block = list_entry(mempid_list, struct xgi_mem_pid_s, list); - if (mempid_block->location == LOCAL && mempid_block->bus_addr == bus_addr) - { - mempid_freeblock = mempid_block; - break; - } - mempid_list = mempid_list->next; - } - if (mempid_freeblock) - { - list_del(&mempid_freeblock->list); - XGI_INFO("Memory ProcessID delete one fb block pid:%ld successfully! \n", mempid_freeblock->pid); - kfree(mempid_freeblock); - } - } -} - -int xgi_fb_heap_init(xgi_info_t *info) -{ - xgi_mem_block_t *block; - - xgi_fb_heap = kmalloc(sizeof(xgi_mem_heap_t), GFP_KERNEL); - if (!xgi_fb_heap) - { - XGI_ERROR("xgi_fb_heap alloc failed\n"); - return 0; - } - - INIT_LIST_HEAD(&xgi_fb_heap->free_list); - INIT_LIST_HEAD(&xgi_fb_heap->used_list); - INIT_LIST_HEAD(&xgi_fb_heap->sort_list); - - xgi_fb_cache_block = kmem_cache_create("xgi_fb_block", sizeof(xgi_mem_block_t), - 0, SLAB_HWCACHE_ALIGN, NULL, NULL); - - if (NULL == xgi_fb_cache_block) - { - XGI_ERROR("Fail to creat xgi_fb_block\n"); - goto fail1; - } - - block = (xgi_mem_block_t *)kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); - if (!block) - { - XGI_ERROR("kmem_cache_alloc failed\n"); - goto fail2; - } - - block->offset = XGI_FB_HEAP_START; - block->size = info->fb.size - XGI_FB_HEAP_START; - - list_add(&block->list, &xgi_fb_heap->free_list); - - xgi_fb_heap->max_freesize = info->fb.size - XGI_FB_HEAP_START; - - XGI_INFO("fb start offset: 0x%lx, memory size : 0x%lx\n", block->offset, block->size); - XGI_INFO("xgi_fb_heap->max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); - - return 1; - -fail2: - if (xgi_fb_cache_block) - { - kmem_cache_destroy(xgi_fb_cache_block); - xgi_fb_cache_block = NULL; - } -fail1: - if(xgi_fb_heap) - { - kfree(xgi_fb_heap); - xgi_fb_heap = NULL; - } - return 0; -} - -void xgi_fb_heap_cleanup(xgi_info_t *info) -{ - struct list_head *free_list, *temp; - xgi_mem_block_t *block; - int i; - - if (xgi_fb_heap) - { - free_list = &xgi_fb_heap->free_list; - for (i = 0; i < 3; i++, free_list++) - { - temp = free_list->next; - while (temp != free_list) - { - block = list_entry(temp, struct xgi_mem_block_s, list); - temp = temp->next; - - XGI_INFO("No. %d block->offset: 0x%lx block->size: 0x%lx \n", - i, block->offset, block->size); - //XGI_INFO("No. %d free block: 0x%p \n", i, block); - kmem_cache_free(xgi_fb_cache_block, block); - block = NULL; - } - } - XGI_INFO("xgi_fb_heap: 0x%p \n", xgi_fb_heap); - kfree(xgi_fb_heap); - xgi_fb_heap = NULL; - } - - if (xgi_fb_cache_block) - { - kmem_cache_destroy(xgi_fb_cache_block); - xgi_fb_cache_block = NULL; - } -} - -static xgi_mem_block_t * xgi_mem_new_node(void) -{ - xgi_mem_block_t *block; - - block = (xgi_mem_block_t *)kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); - if (!block) - { - XGI_ERROR("kmem_cache_alloc failed\n"); - return NULL; - } - - return block; -} - -#if 0 -static void xgi_mem_insert_node_after(xgi_mem_list_t *list, - xgi_mem_block_t *current, - xgi_mem_block_t *block); -static void xgi_mem_insert_node_before(xgi_mem_list_t *list, - xgi_mem_block_t *current, - xgi_mem_block_t *block); -static void xgi_mem_insert_node_head(xgi_mem_list_t *list, - xgi_mem_block_t *block); -static void xgi_mem_insert_node_tail(xgi_mem_list_t *list, - xgi_mem_block_t *block); -static void xgi_mem_delete_node(xgi_mem_list_t *list, - xgi_mem_block_t *block); -/* - * insert node:block after node:current - */ -static void xgi_mem_insert_node_after(xgi_mem_list_t *list, - xgi_mem_block_t *current, - xgi_mem_block_t *block) -{ - block->prev = current; - block->next = current->next; - current->next = block; - - if (current == list->tail) - { - list->tail = block; - } - else - { - block->next->prev = block; - } -} - -/* - * insert node:block before node:current - */ -static void xgi_mem_insert_node_before(xgi_mem_list_t *list, - xgi_mem_block_t *current, - xgi_mem_block_t *block) -{ - block->prev = current->prev; - block->next = current; - current->prev = block; - if (current == list->head) - { - list->head = block; - } - else - { - block->prev->next = block; - } -} -void xgi_mem_insert_node_head(xgi_mem_list_t *list, - xgi_mem_block_t *block) -{ - block->next = list->head; - block->prev = NULL; - - if (NULL == list->head) - { - list->tail = block; - } - else - { - list->head->prev = block; - } - list->head = block; -} - -static void xgi_mem_insert_node_tail(xgi_mem_list_t *list, - xgi_mem_block_t *block) - -{ - block->next = NULL; - block->prev = list->tail; - if (NULL == list->tail) - { - list->head = block; - } - else - { - list->tail->next = block; - } - list->tail = block; -} - -static void xgi_mem_delete_node(xgi_mem_list_t *list, - xgi_mem_block_t *block) -{ - if (block == list->head) - { - list->head = block->next; - } - if (block == list->tail) - { - list->tail = block->prev; - } - - if (block->prev) - { - block->prev->next = block->next; - } - if (block->next) - { - block->next->prev = block->prev; - } - - block->next = block->prev = NULL; -} -#endif -static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t *info, unsigned long originalSize) -{ - struct list_head *free_list; - xgi_mem_block_t *block, *free_block, *used_block; - - unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; - - XGI_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", originalSize, size); - - if (size == 0) - { - XGI_ERROR("size == 0\n"); - return (NULL); - } - XGI_INFO("max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); - if (size > xgi_fb_heap->max_freesize) - { - XGI_ERROR("size: 0x%lx is bigger than frame buffer total free size: 0x%lx !\n", - size, xgi_fb_heap->max_freesize); - return (NULL); - } - - free_list = xgi_fb_heap->free_list.next; - - while (free_list != &xgi_fb_heap->free_list) - { - XGI_INFO("free_list: 0x%px \n", free_list); - block = list_entry(free_list, struct xgi_mem_block_s, list); - if (size <= block->size) - { - break; - } - free_list = free_list->next; - } - - if (free_list == &xgi_fb_heap->free_list) - { - XGI_ERROR("Can't allocate %ldk size from frame buffer memory !\n", size/1024); - return (NULL); - } - - free_block = block; - XGI_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", - size, free_block->offset, free_block->size); - - if (size == free_block->size) - { - used_block = free_block; - XGI_INFO("size == free_block->size: free_block = 0x%p\n", free_block); - list_del(&free_block->list); - } - else - { - used_block = xgi_mem_new_node(); - - if (used_block == NULL) return (NULL); - - if (used_block == free_block) - { - XGI_ERROR("used_block == free_block = 0x%p\n", used_block); - } - - used_block->offset = free_block->offset; - used_block->size = size; - - free_block->offset += size; - free_block->size -= size; - } - - xgi_fb_heap->max_freesize -= size; - - list_add(&used_block->list, &xgi_fb_heap->used_list); - - return (used_block); -} - -static xgi_mem_block_t *xgi_mem_free(xgi_info_t *info, unsigned long offset) -{ - struct list_head *free_list, *used_list; - xgi_mem_block_t *used_block = NULL, *block = NULL; - xgi_mem_block_t *prev, *next; - - unsigned long upper; - unsigned long lower; - - used_list = xgi_fb_heap->used_list.next; - while (used_list != &xgi_fb_heap->used_list) - { - block = list_entry(used_list, struct xgi_mem_block_s, list); - if (block->offset == offset) - { - break; - } - used_list = used_list->next; - } - - if (used_list == &xgi_fb_heap->used_list) - { - XGI_ERROR("can't find block: 0x%lx to free!\n", offset); - return (NULL); - } - - used_block = block; - XGI_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", - used_block, used_block->offset, used_block->size); - - xgi_fb_heap->max_freesize += used_block->size; - - prev = next = NULL; - upper = used_block->offset + used_block->size; - lower = used_block->offset; - - free_list = xgi_fb_heap->free_list.next; - while (free_list != &xgi_fb_heap->free_list) - { - block = list_entry(free_list, struct xgi_mem_block_s, list); - - if (block->offset == upper) - { - next = block; - } - else if ((block->offset + block->size) == lower) - { - prev = block; - } - free_list = free_list->next; - } - - XGI_INFO("next = 0x%p, prev = 0x%p\n", next, prev); - list_del(&used_block->list); - - if (prev && next) - { - prev->size += (used_block->size + next->size); - list_del(&next->list); - XGI_INFO("free node 0x%p\n", next); - kmem_cache_free(xgi_fb_cache_block, next); - kmem_cache_free(xgi_fb_cache_block, used_block); - - next = NULL; - used_block = NULL; - return (prev); - } - - if (prev) - { - prev->size += used_block->size; - XGI_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_fb_cache_block, used_block); - used_block = NULL; - return (prev); - } - - if (next) - { - next->size += used_block->size; - next->offset = used_block->offset; - XGI_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_fb_cache_block, used_block); - used_block = NULL; - return (next); - } - - list_add(&used_block->list, &xgi_fb_heap->free_list); - XGI_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", - used_block, used_block->offset, used_block->size); - - return (used_block); -} - + +/**************************************************************************** + * Copyright (C) 2003-2006 by XGI Technology, Taiwan. + * * + * 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 on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, 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 XGI 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. + ***************************************************************************/ + +#include "xgi_types.h" +#include "xgi_linux.h" +#include "xgi_drv.h" +#include "xgi_fb.h" + +#define XGI_FB_HEAP_START 0x1000000 + +static xgi_mem_heap_t *xgi_fb_heap; +static kmem_cache_t *xgi_fb_cache_block = NULL; +extern struct list_head xgi_mempid_list; + +static xgi_mem_block_t *xgi_mem_new_node(void); +static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, unsigned long size); +static xgi_mem_block_t *xgi_mem_free(xgi_info_t * info, unsigned long offset); + +void xgi_fb_alloc(xgi_info_t * info, + xgi_mem_req_t * req, xgi_mem_alloc_t * alloc) +{ + xgi_mem_block_t *block; + xgi_mem_pid_t *mempid_block; + + if (req->is_front) { + alloc->location = LOCAL; + alloc->bus_addr = info->fb.base; + alloc->hw_addr = 0; + XGI_INFO + ("Video RAM allocation on front buffer successfully! \n"); + } else { + xgi_down(info->fb_sem); + block = xgi_mem_alloc(info, req->size); + xgi_up(info->fb_sem); + + if (block == NULL) { + alloc->location = LOCAL; + alloc->size = 0; + alloc->bus_addr = 0; + alloc->hw_addr = 0; + XGI_ERROR("Video RAM allocation failed\n"); + } else { + XGI_INFO("Video RAM allocation succeeded: 0x%p\n", + (char *)block->offset); + alloc->location = LOCAL; + alloc->size = block->size; + alloc->bus_addr = info->fb.base + block->offset; + alloc->hw_addr = block->offset; + + /* manage mempid */ + mempid_block = + kmalloc(sizeof(xgi_mem_pid_t), GFP_KERNEL); + mempid_block->location = LOCAL; + mempid_block->bus_addr = alloc->bus_addr; + mempid_block->pid = alloc->pid; + + if (!mempid_block) + XGI_ERROR("mempid_block alloc failed\n"); + + XGI_INFO + ("Memory ProcessID add one fb block pid:%ld successfully! \n", + mempid_block->pid); + list_add(&mempid_block->list, &xgi_mempid_list); + } + } +} + +void xgi_fb_free(xgi_info_t * info, unsigned long bus_addr) +{ + xgi_mem_block_t *block; + unsigned long offset = bus_addr - info->fb.base; + xgi_mem_pid_t *mempid_block; + xgi_mem_pid_t *mempid_freeblock = NULL; + struct list_head *mempid_list; + + if (offset < 0) { + XGI_INFO("free onscreen frame buffer successfully !\n"); + } else { + xgi_down(info->fb_sem); + block = xgi_mem_free(info, offset); + xgi_up(info->fb_sem); + + if (block == NULL) { + XGI_ERROR("xgi_mem_free() failed at base 0x%lx\n", + offset); + } + + /* manage mempid */ + mempid_list = xgi_mempid_list.next; + while (mempid_list != &xgi_mempid_list) { + mempid_block = + list_entry(mempid_list, struct xgi_mem_pid_s, list); + if (mempid_block->location == LOCAL + && mempid_block->bus_addr == bus_addr) { + mempid_freeblock = mempid_block; + break; + } + mempid_list = mempid_list->next; + } + if (mempid_freeblock) { + list_del(&mempid_freeblock->list); + XGI_INFO + ("Memory ProcessID delete one fb block pid:%ld successfully! \n", + mempid_freeblock->pid); + kfree(mempid_freeblock); + } + } +} + +int xgi_fb_heap_init(xgi_info_t * info) +{ + xgi_mem_block_t *block; + + xgi_fb_heap = kmalloc(sizeof(xgi_mem_heap_t), GFP_KERNEL); + if (!xgi_fb_heap) { + XGI_ERROR("xgi_fb_heap alloc failed\n"); + return 0; + } + + INIT_LIST_HEAD(&xgi_fb_heap->free_list); + INIT_LIST_HEAD(&xgi_fb_heap->used_list); + INIT_LIST_HEAD(&xgi_fb_heap->sort_list); + + xgi_fb_cache_block = + kmem_cache_create("xgi_fb_block", sizeof(xgi_mem_block_t), 0, + SLAB_HWCACHE_ALIGN, NULL, NULL); + + if (NULL == xgi_fb_cache_block) { + XGI_ERROR("Fail to creat xgi_fb_block\n"); + goto fail1; + } + + block = + (xgi_mem_block_t *) kmem_cache_alloc(xgi_fb_cache_block, + GFP_KERNEL); + if (!block) { + XGI_ERROR("kmem_cache_alloc failed\n"); + goto fail2; + } + + block->offset = XGI_FB_HEAP_START; + block->size = info->fb.size - XGI_FB_HEAP_START; + + list_add(&block->list, &xgi_fb_heap->free_list); + + xgi_fb_heap->max_freesize = info->fb.size - XGI_FB_HEAP_START; + + XGI_INFO("fb start offset: 0x%lx, memory size : 0x%lx\n", block->offset, + block->size); + XGI_INFO("xgi_fb_heap->max_freesize: 0x%lx \n", + xgi_fb_heap->max_freesize); + + return 1; + + fail2: + if (xgi_fb_cache_block) { + kmem_cache_destroy(xgi_fb_cache_block); + xgi_fb_cache_block = NULL; + } + fail1: + if (xgi_fb_heap) { + kfree(xgi_fb_heap); + xgi_fb_heap = NULL; + } + return 0; +} + +void xgi_fb_heap_cleanup(xgi_info_t * info) +{ + struct list_head *free_list, *temp; + xgi_mem_block_t *block; + int i; + + if (xgi_fb_heap) { + free_list = &xgi_fb_heap->free_list; + for (i = 0; i < 3; i++, free_list++) { + temp = free_list->next; + while (temp != free_list) { + block = + list_entry(temp, struct xgi_mem_block_s, + list); + temp = temp->next; + + XGI_INFO + ("No. %d block->offset: 0x%lx block->size: 0x%lx \n", + i, block->offset, block->size); + //XGI_INFO("No. %d free block: 0x%p \n", i, block); + kmem_cache_free(xgi_fb_cache_block, block); + block = NULL; + } + } + XGI_INFO("xgi_fb_heap: 0x%p \n", xgi_fb_heap); + kfree(xgi_fb_heap); + xgi_fb_heap = NULL; + } + + if (xgi_fb_cache_block) { + kmem_cache_destroy(xgi_fb_cache_block); + xgi_fb_cache_block = NULL; + } +} + +static xgi_mem_block_t *xgi_mem_new_node(void) +{ + xgi_mem_block_t *block; + + block = + (xgi_mem_block_t *) kmem_cache_alloc(xgi_fb_cache_block, + GFP_KERNEL); + if (!block) { + XGI_ERROR("kmem_cache_alloc failed\n"); + return NULL; + } + + return block; +} + +#if 0 +static void xgi_mem_insert_node_after(xgi_mem_list_t * list, + xgi_mem_block_t * current, + xgi_mem_block_t * block); +static void xgi_mem_insert_node_before(xgi_mem_list_t * list, + xgi_mem_block_t * current, + xgi_mem_block_t * block); +static void xgi_mem_insert_node_head(xgi_mem_list_t * list, + xgi_mem_block_t * block); +static void xgi_mem_insert_node_tail(xgi_mem_list_t * list, + xgi_mem_block_t * block); +static void xgi_mem_delete_node(xgi_mem_list_t * list, xgi_mem_block_t * block); +/* + * insert node:block after node:current + */ +static void xgi_mem_insert_node_after(xgi_mem_list_t * list, + xgi_mem_block_t * current, + xgi_mem_block_t * block) +{ + block->prev = current; + block->next = current->next; + current->next = block; + + if (current == list->tail) { + list->tail = block; + } else { + block->next->prev = block; + } +} + +/* + * insert node:block before node:current + */ +static void xgi_mem_insert_node_before(xgi_mem_list_t * list, + xgi_mem_block_t * current, + xgi_mem_block_t * block) +{ + block->prev = current->prev; + block->next = current; + current->prev = block; + if (current == list->head) { + list->head = block; + } else { + block->prev->next = block; + } +} +void xgi_mem_insert_node_head(xgi_mem_list_t * list, xgi_mem_block_t * block) +{ + block->next = list->head; + block->prev = NULL; + + if (NULL == list->head) { + list->tail = block; + } else { + list->head->prev = block; + } + list->head = block; +} + +static void xgi_mem_insert_node_tail(xgi_mem_list_t * list, + xgi_mem_block_t * block) +{ + block->next = NULL; + block->prev = list->tail; + if (NULL == list->tail) { + list->head = block; + } else { + list->tail->next = block; + } + list->tail = block; +} + +static void xgi_mem_delete_node(xgi_mem_list_t * list, xgi_mem_block_t * block) +{ + if (block == list->head) { + list->head = block->next; + } + if (block == list->tail) { + list->tail = block->prev; + } + + if (block->prev) { + block->prev->next = block->next; + } + if (block->next) { + block->next->prev = block->prev; + } + + block->next = block->prev = NULL; +} +#endif +static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, + unsigned long originalSize) +{ + struct list_head *free_list; + xgi_mem_block_t *block, *free_block, *used_block; + + unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; + + XGI_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", + originalSize, size); + + if (size == 0) { + XGI_ERROR("size == 0\n"); + return (NULL); + } + XGI_INFO("max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); + if (size > xgi_fb_heap->max_freesize) { + XGI_ERROR + ("size: 0x%lx is bigger than frame buffer total free size: 0x%lx !\n", + size, xgi_fb_heap->max_freesize); + return (NULL); + } + + free_list = xgi_fb_heap->free_list.next; + + while (free_list != &xgi_fb_heap->free_list) { + XGI_INFO("free_list: 0x%px \n", free_list); + block = list_entry(free_list, struct xgi_mem_block_s, list); + if (size <= block->size) { + break; + } + free_list = free_list->next; + } + + if (free_list == &xgi_fb_heap->free_list) { + XGI_ERROR + ("Can't allocate %ldk size from frame buffer memory !\n", + size / 1024); + return (NULL); + } + + free_block = block; + XGI_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", + size, free_block->offset, free_block->size); + + if (size == free_block->size) { + used_block = free_block; + XGI_INFO("size == free_block->size: free_block = 0x%p\n", + free_block); + list_del(&free_block->list); + } else { + used_block = xgi_mem_new_node(); + + if (used_block == NULL) + return (NULL); + + if (used_block == free_block) { + XGI_ERROR("used_block == free_block = 0x%p\n", + used_block); + } + + used_block->offset = free_block->offset; + used_block->size = size; + + free_block->offset += size; + free_block->size -= size; + } + + xgi_fb_heap->max_freesize -= size; + + list_add(&used_block->list, &xgi_fb_heap->used_list); + + return (used_block); +} + +static xgi_mem_block_t *xgi_mem_free(xgi_info_t * info, unsigned long offset) +{ + struct list_head *free_list, *used_list; + xgi_mem_block_t *used_block = NULL, *block = NULL; + xgi_mem_block_t *prev, *next; + + unsigned long upper; + unsigned long lower; + + used_list = xgi_fb_heap->used_list.next; + while (used_list != &xgi_fb_heap->used_list) { + block = list_entry(used_list, struct xgi_mem_block_s, list); + if (block->offset == offset) { + break; + } + used_list = used_list->next; + } + + if (used_list == &xgi_fb_heap->used_list) { + XGI_ERROR("can't find block: 0x%lx to free!\n", offset); + return (NULL); + } + + used_block = block; + XGI_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", + used_block, used_block->offset, used_block->size); + + xgi_fb_heap->max_freesize += used_block->size; + + prev = next = NULL; + upper = used_block->offset + used_block->size; + lower = used_block->offset; + + free_list = xgi_fb_heap->free_list.next; + while (free_list != &xgi_fb_heap->free_list) { + block = list_entry(free_list, struct xgi_mem_block_s, list); + + if (block->offset == upper) { + next = block; + } else if ((block->offset + block->size) == lower) { + prev = block; + } + free_list = free_list->next; + } + + XGI_INFO("next = 0x%p, prev = 0x%p\n", next, prev); + list_del(&used_block->list); + + if (prev && next) { + prev->size += (used_block->size + next->size); + list_del(&next->list); + XGI_INFO("free node 0x%p\n", next); + kmem_cache_free(xgi_fb_cache_block, next); + kmem_cache_free(xgi_fb_cache_block, used_block); + + next = NULL; + used_block = NULL; + return (prev); + } + + if (prev) { + prev->size += used_block->size; + XGI_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_fb_cache_block, used_block); + used_block = NULL; + return (prev); + } + + if (next) { + next->size += used_block->size; + next->offset = used_block->offset; + XGI_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_fb_cache_block, used_block); + used_block = NULL; + return (next); + } + + list_add(&used_block->list, &xgi_fb_heap->free_list); + XGI_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", + used_block, used_block->offset, used_block->size); + + return (used_block); +} -- cgit v1.2.3 From 88328d4ef007c781874aafedfef59aae0d21a37c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 29 Jun 2007 15:27:38 -0700 Subject: Eliminate structure typedefs Documentation/CodingStyle says that 'typedef struct foo foo_t' is evil. I tend to agree. Elminate all uses of such construct. --- linux-core/xgi_fb.c | 110 ++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index fab99ae2..56cc589b 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -33,19 +33,19 @@ #define XGI_FB_HEAP_START 0x1000000 -static xgi_mem_heap_t *xgi_fb_heap; -static kmem_cache_t *xgi_fb_cache_block = NULL; +static struct xgi_mem_heap *xgi_fb_heap; +static struct kmem_cache *xgi_fb_cache_block = NULL; extern struct list_head xgi_mempid_list; -static xgi_mem_block_t *xgi_mem_new_node(void); -static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, unsigned long size); -static xgi_mem_block_t *xgi_mem_free(xgi_info_t * info, unsigned long offset); +static struct xgi_mem_block *xgi_mem_new_node(void); +static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, unsigned long size); +static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset); -void xgi_fb_alloc(xgi_info_t * info, - xgi_mem_req_t * req, xgi_mem_alloc_t * alloc) +void xgi_fb_alloc(struct xgi_info * info, + struct xgi_mem_req * req, struct xgi_mem_alloc * alloc) { - xgi_mem_block_t *block; - xgi_mem_pid_t *mempid_block; + struct xgi_mem_block *block; + struct xgi_mem_pid *mempid_block; if (req->is_front) { alloc->location = LOCAL; @@ -74,7 +74,7 @@ void xgi_fb_alloc(xgi_info_t * info, /* manage mempid */ mempid_block = - kmalloc(sizeof(xgi_mem_pid_t), GFP_KERNEL); + kmalloc(sizeof(struct xgi_mem_pid), GFP_KERNEL); mempid_block->location = LOCAL; mempid_block->bus_addr = alloc->bus_addr; mempid_block->pid = alloc->pid; @@ -90,12 +90,12 @@ void xgi_fb_alloc(xgi_info_t * info, } } -void xgi_fb_free(xgi_info_t * info, unsigned long bus_addr) +void xgi_fb_free(struct xgi_info * info, unsigned long bus_addr) { - xgi_mem_block_t *block; + struct xgi_mem_block *block; unsigned long offset = bus_addr - info->fb.base; - xgi_mem_pid_t *mempid_block; - xgi_mem_pid_t *mempid_freeblock = NULL; + struct xgi_mem_pid *mempid_block; + struct xgi_mem_pid *mempid_freeblock = NULL; struct list_head *mempid_list; if (offset < 0) { @@ -114,7 +114,7 @@ void xgi_fb_free(xgi_info_t * info, unsigned long bus_addr) mempid_list = xgi_mempid_list.next; while (mempid_list != &xgi_mempid_list) { mempid_block = - list_entry(mempid_list, struct xgi_mem_pid_s, list); + list_entry(mempid_list, struct xgi_mem_pid, list); if (mempid_block->location == LOCAL && mempid_block->bus_addr == bus_addr) { mempid_freeblock = mempid_block; @@ -132,11 +132,11 @@ void xgi_fb_free(xgi_info_t * info, unsigned long bus_addr) } } -int xgi_fb_heap_init(xgi_info_t * info) +int xgi_fb_heap_init(struct xgi_info * info) { - xgi_mem_block_t *block; + struct xgi_mem_block *block; - xgi_fb_heap = kmalloc(sizeof(xgi_mem_heap_t), GFP_KERNEL); + xgi_fb_heap = kmalloc(sizeof(struct xgi_mem_heap), GFP_KERNEL); if (!xgi_fb_heap) { XGI_ERROR("xgi_fb_heap alloc failed\n"); return 0; @@ -147,7 +147,7 @@ int xgi_fb_heap_init(xgi_info_t * info) INIT_LIST_HEAD(&xgi_fb_heap->sort_list); xgi_fb_cache_block = - kmem_cache_create("xgi_fb_block", sizeof(xgi_mem_block_t), 0, + kmem_cache_create("xgi_fb_block", sizeof(struct xgi_mem_block), 0, SLAB_HWCACHE_ALIGN, NULL, NULL); if (NULL == xgi_fb_cache_block) { @@ -156,7 +156,7 @@ int xgi_fb_heap_init(xgi_info_t * info) } block = - (xgi_mem_block_t *) kmem_cache_alloc(xgi_fb_cache_block, + (struct xgi_mem_block *) kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); if (!block) { XGI_ERROR("kmem_cache_alloc failed\n"); @@ -190,10 +190,10 @@ int xgi_fb_heap_init(xgi_info_t * info) return 0; } -void xgi_fb_heap_cleanup(xgi_info_t * info) +void xgi_fb_heap_cleanup(struct xgi_info * info) { struct list_head *free_list, *temp; - xgi_mem_block_t *block; + struct xgi_mem_block *block; int i; if (xgi_fb_heap) { @@ -202,7 +202,7 @@ void xgi_fb_heap_cleanup(xgi_info_t * info) temp = free_list->next; while (temp != free_list) { block = - list_entry(temp, struct xgi_mem_block_s, + list_entry(temp, struct xgi_mem_block, list); temp = temp->next; @@ -225,12 +225,12 @@ void xgi_fb_heap_cleanup(xgi_info_t * info) } } -static xgi_mem_block_t *xgi_mem_new_node(void) +static struct xgi_mem_block *xgi_mem_new_node(void) { - xgi_mem_block_t *block; + struct xgi_mem_block *block; block = - (xgi_mem_block_t *) kmem_cache_alloc(xgi_fb_cache_block, + (struct xgi_mem_block *) kmem_cache_alloc(xgi_fb_cache_block, GFP_KERNEL); if (!block) { XGI_ERROR("kmem_cache_alloc failed\n"); @@ -241,23 +241,23 @@ static xgi_mem_block_t *xgi_mem_new_node(void) } #if 0 -static void xgi_mem_insert_node_after(xgi_mem_list_t * list, - xgi_mem_block_t * current, - xgi_mem_block_t * block); -static void xgi_mem_insert_node_before(xgi_mem_list_t * list, - xgi_mem_block_t * current, - xgi_mem_block_t * block); -static void xgi_mem_insert_node_head(xgi_mem_list_t * list, - xgi_mem_block_t * block); -static void xgi_mem_insert_node_tail(xgi_mem_list_t * list, - xgi_mem_block_t * block); -static void xgi_mem_delete_node(xgi_mem_list_t * list, xgi_mem_block_t * block); +static void xgi_mem_insert_node_after(struct xgi_mem_list * list, + struct xgi_mem_block * current, + struct xgi_mem_block * block); +static void xgi_mem_insert_node_before(struct xgi_mem_list * list, + struct xgi_mem_block * current, + struct xgi_mem_block * block); +static void xgi_mem_insert_node_head(struct xgi_mem_list * list, + struct xgi_mem_block * block); +static void xgi_mem_insert_node_tail(struct xgi_mem_list * list, + struct xgi_mem_block * block); +static void xgi_mem_delete_node(struct xgi_mem_list * list, struct xgi_mem_block * block); /* * insert node:block after node:current */ -static void xgi_mem_insert_node_after(xgi_mem_list_t * list, - xgi_mem_block_t * current, - xgi_mem_block_t * block) +static void xgi_mem_insert_node_after(struct xgi_mem_list * list, + struct xgi_mem_block * current, + struct xgi_mem_block * block) { block->prev = current; block->next = current->next; @@ -273,9 +273,9 @@ static void xgi_mem_insert_node_after(xgi_mem_list_t * list, /* * insert node:block before node:current */ -static void xgi_mem_insert_node_before(xgi_mem_list_t * list, - xgi_mem_block_t * current, - xgi_mem_block_t * block) +static void xgi_mem_insert_node_before(struct xgi_mem_list * list, + struct xgi_mem_block * current, + struct xgi_mem_block * block) { block->prev = current->prev; block->next = current; @@ -286,7 +286,7 @@ static void xgi_mem_insert_node_before(xgi_mem_list_t * list, block->prev->next = block; } } -void xgi_mem_insert_node_head(xgi_mem_list_t * list, xgi_mem_block_t * block) +void xgi_mem_insert_node_head(struct xgi_mem_list * list, struct xgi_mem_block * block) { block->next = list->head; block->prev = NULL; @@ -299,8 +299,8 @@ void xgi_mem_insert_node_head(xgi_mem_list_t * list, xgi_mem_block_t * block) list->head = block; } -static void xgi_mem_insert_node_tail(xgi_mem_list_t * list, - xgi_mem_block_t * block) +static void xgi_mem_insert_node_tail(struct xgi_mem_list * list, + struct xgi_mem_block * block) { block->next = NULL; block->prev = list->tail; @@ -312,7 +312,7 @@ static void xgi_mem_insert_node_tail(xgi_mem_list_t * list, list->tail = block; } -static void xgi_mem_delete_node(xgi_mem_list_t * list, xgi_mem_block_t * block) +static void xgi_mem_delete_node(struct xgi_mem_list * list, struct xgi_mem_block * block) { if (block == list->head) { list->head = block->next; @@ -331,11 +331,11 @@ static void xgi_mem_delete_node(xgi_mem_list_t * list, xgi_mem_block_t * block) block->next = block->prev = NULL; } #endif -static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, +static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, unsigned long originalSize) { struct list_head *free_list; - xgi_mem_block_t *block, *free_block, *used_block; + struct xgi_mem_block *block, *free_block, *used_block; unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; @@ -358,7 +358,7 @@ static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, while (free_list != &xgi_fb_heap->free_list) { XGI_INFO("free_list: 0x%px \n", free_list); - block = list_entry(free_list, struct xgi_mem_block_s, list); + block = list_entry(free_list, struct xgi_mem_block, list); if (size <= block->size) { break; } @@ -406,18 +406,18 @@ static xgi_mem_block_t *xgi_mem_alloc(xgi_info_t * info, return (used_block); } -static xgi_mem_block_t *xgi_mem_free(xgi_info_t * info, unsigned long offset) +static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset) { struct list_head *free_list, *used_list; - xgi_mem_block_t *used_block = NULL, *block = NULL; - xgi_mem_block_t *prev, *next; + struct xgi_mem_block *used_block = NULL, *block = NULL; + struct xgi_mem_block *prev, *next; unsigned long upper; unsigned long lower; used_list = xgi_fb_heap->used_list.next; while (used_list != &xgi_fb_heap->used_list) { - block = list_entry(used_list, struct xgi_mem_block_s, list); + block = list_entry(used_list, struct xgi_mem_block, list); if (block->offset == offset) { break; } @@ -441,7 +441,7 @@ static xgi_mem_block_t *xgi_mem_free(xgi_info_t * info, unsigned long offset) free_list = xgi_fb_heap->free_list.next; while (free_list != &xgi_fb_heap->free_list) { - block = list_entry(free_list, struct xgi_mem_block_s, list); + block = list_entry(free_list, struct xgi_mem_block, list); if (block->offset == upper) { next = block; -- cgit v1.2.3 From 32584d94e6ef7c0b463794a40541eb8183c7fb02 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 29 Jun 2007 21:35:27 -0700 Subject: Convert open coded list iterators to either list_for_each_entry or list_for_each_entry_safe --- linux-core/xgi_fb.c | 43 ++++++++++--------------------------------- 1 file changed, 10 insertions(+), 33 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 56cc589b..32fde5ab 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -96,7 +96,6 @@ void xgi_fb_free(struct xgi_info * info, unsigned long bus_addr) unsigned long offset = bus_addr - info->fb.base; struct xgi_mem_pid *mempid_block; struct xgi_mem_pid *mempid_freeblock = NULL; - struct list_head *mempid_list; if (offset < 0) { XGI_INFO("free onscreen frame buffer successfully !\n"); @@ -111,16 +110,12 @@ void xgi_fb_free(struct xgi_info * info, unsigned long bus_addr) } /* manage mempid */ - mempid_list = xgi_mempid_list.next; - while (mempid_list != &xgi_mempid_list) { - mempid_block = - list_entry(mempid_list, struct xgi_mem_pid, list); + list_for_each_entry(mempid_block, &xgi_mempid_list, list) { if (mempid_block->location == LOCAL && mempid_block->bus_addr == bus_addr) { mempid_freeblock = mempid_block; break; } - mempid_list = mempid_list->next; } if (mempid_freeblock) { list_del(&mempid_freeblock->list); @@ -192,20 +187,15 @@ int xgi_fb_heap_init(struct xgi_info * info) void xgi_fb_heap_cleanup(struct xgi_info * info) { - struct list_head *free_list, *temp; + struct list_head *free_list; struct xgi_mem_block *block; + struct xgi_mem_block *next; int i; if (xgi_fb_heap) { free_list = &xgi_fb_heap->free_list; for (i = 0; i < 3; i++, free_list++) { - temp = free_list->next; - while (temp != free_list) { - block = - list_entry(temp, struct xgi_mem_block, - list); - temp = temp->next; - + list_for_each_entry_safe(block, next, free_list, list) { XGI_INFO ("No. %d block->offset: 0x%lx block->size: 0x%lx \n", i, block->offset, block->size); @@ -334,7 +324,6 @@ static void xgi_mem_delete_node(struct xgi_mem_list * list, struct xgi_mem_block static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, unsigned long originalSize) { - struct list_head *free_list; struct xgi_mem_block *block, *free_block, *used_block; unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; @@ -354,18 +343,14 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, return (NULL); } - free_list = xgi_fb_heap->free_list.next; - - while (free_list != &xgi_fb_heap->free_list) { + list_for_each_entry(block, &xgi_fb_heap->free_list, list) { XGI_INFO("free_list: 0x%px \n", free_list); - block = list_entry(free_list, struct xgi_mem_block, list); if (size <= block->size) { break; } - free_list = free_list->next; } - if (free_list == &xgi_fb_heap->free_list) { + if (&block->list == &xgi_fb_heap->free_list) { XGI_ERROR ("Can't allocate %ldk size from frame buffer memory !\n", size / 1024); @@ -408,23 +393,19 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset) { - struct list_head *free_list, *used_list; - struct xgi_mem_block *used_block = NULL, *block = NULL; + struct xgi_mem_block *used_block = NULL, *block; struct xgi_mem_block *prev, *next; unsigned long upper; unsigned long lower; - used_list = xgi_fb_heap->used_list.next; - while (used_list != &xgi_fb_heap->used_list) { - block = list_entry(used_list, struct xgi_mem_block, list); + list_for_each_entry(block, &xgi_fb_heap->used_list, list) { if (block->offset == offset) { break; } - used_list = used_list->next; } - if (used_list == &xgi_fb_heap->used_list) { + if (&block->list == &xgi_fb_heap->used_list) { XGI_ERROR("can't find block: 0x%lx to free!\n", offset); return (NULL); } @@ -439,16 +420,12 @@ static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long upper = used_block->offset + used_block->size; lower = used_block->offset; - free_list = xgi_fb_heap->free_list.next; - while (free_list != &xgi_fb_heap->free_list) { - block = list_entry(free_list, struct xgi_mem_block, list); - + list_for_each_entry(block, &xgi_fb_heap->free_list, list) { if (block->offset == upper) { next = block; } else if ((block->offset + block->size) == lower) { prev = block; } - free_list = free_list->next; } XGI_INFO("next = 0x%p, prev = 0x%p\n", next, prev); -- cgit v1.2.3 From 49ccec1b0845ea14ab2cfd2f53704fe26e38fbef Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 29 Jun 2007 21:38:48 -0700 Subject: Convert xgi_mem_location enum values to less generic names. --- linux-core/xgi_fb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 32fde5ab..d7e9285d 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -48,7 +48,7 @@ void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_pid *mempid_block; if (req->is_front) { - alloc->location = LOCAL; + alloc->location = XGI_MEMLOC_LOCAL; alloc->bus_addr = info->fb.base; alloc->hw_addr = 0; XGI_INFO @@ -59,7 +59,7 @@ void xgi_fb_alloc(struct xgi_info * info, xgi_up(info->fb_sem); if (block == NULL) { - alloc->location = LOCAL; + alloc->location = XGI_MEMLOC_LOCAL; alloc->size = 0; alloc->bus_addr = 0; alloc->hw_addr = 0; @@ -67,7 +67,7 @@ void xgi_fb_alloc(struct xgi_info * info, } else { XGI_INFO("Video RAM allocation succeeded: 0x%p\n", (char *)block->offset); - alloc->location = LOCAL; + alloc->location = XGI_MEMLOC_LOCAL; alloc->size = block->size; alloc->bus_addr = info->fb.base + block->offset; alloc->hw_addr = block->offset; @@ -75,7 +75,7 @@ void xgi_fb_alloc(struct xgi_info * info, /* manage mempid */ mempid_block = kmalloc(sizeof(struct xgi_mem_pid), GFP_KERNEL); - mempid_block->location = LOCAL; + mempid_block->location = XGI_MEMLOC_LOCAL; mempid_block->bus_addr = alloc->bus_addr; mempid_block->pid = alloc->pid; @@ -111,7 +111,7 @@ void xgi_fb_free(struct xgi_info * info, unsigned long bus_addr) /* manage mempid */ list_for_each_entry(mempid_block, &xgi_mempid_list, list) { - if (mempid_block->location == LOCAL + if (mempid_block->location == XGI_MEMLOC_LOCAL && mempid_block->bus_addr == bus_addr) { mempid_freeblock = mempid_block; break; -- cgit v1.2.3 From 2f2d8b9688743ac6367bf13c3c023310a257ceb7 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 9 Jul 2007 15:59:09 -0700 Subject: Merge xgi_mem_req and xgi_mem_alloc into a single type. These two structures were used as the request and reply for certain ioctls. Having a different type for an ioctl's input and output is just wierd. In addition, each structure contained fields (e.g., pid) that had no business being there. This change requires updates to user-space. --- linux-core/xgi_fb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index d7e9285d..ac73b41a 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -41,13 +41,13 @@ static struct xgi_mem_block *xgi_mem_new_node(void); static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, unsigned long size); static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset); -void xgi_fb_alloc(struct xgi_info * info, - struct xgi_mem_req * req, struct xgi_mem_alloc * alloc) +void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, + pid_t pid) { struct xgi_mem_block *block; struct xgi_mem_pid *mempid_block; - if (req->is_front) { + if (alloc->is_front) { alloc->location = XGI_MEMLOC_LOCAL; alloc->bus_addr = info->fb.base; alloc->hw_addr = 0; @@ -55,7 +55,7 @@ void xgi_fb_alloc(struct xgi_info * info, ("Video RAM allocation on front buffer successfully! \n"); } else { xgi_down(info->fb_sem); - block = xgi_mem_alloc(info, req->size); + block = xgi_mem_alloc(info, alloc->size); xgi_up(info->fb_sem); if (block == NULL) { @@ -77,7 +77,7 @@ void xgi_fb_alloc(struct xgi_info * info, kmalloc(sizeof(struct xgi_mem_pid), GFP_KERNEL); mempid_block->location = XGI_MEMLOC_LOCAL; mempid_block->bus_addr = alloc->bus_addr; - mempid_block->pid = alloc->pid; + mempid_block->pid = pid; if (!mempid_block) XGI_ERROR("mempid_block alloc failed\n"); -- cgit v1.2.3 From 76ca1e858fb8e1a65ea49c0c62350d7ca91044a2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 9 Jul 2007 18:54:25 -0700 Subject: Convert occurances of U32 to other types. Most occurances of U32 were converted to u32. These are cases where the data represents something that will be written to the hardware. Other cases were converted to 'unsigned int'. U32 was the last type in xgi_types.h, so that file is removed. --- linux-core/xgi_fb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index ac73b41a..7d390d4b 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -26,7 +26,6 @@ * DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include "xgi_types.h" #include "xgi_linux.h" #include "xgi_drv.h" #include "xgi_fb.h" -- cgit v1.2.3 From 5ba94c2ab8be350fee495e5cfe94afb8f663956a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 19 Jul 2007 10:29:18 -0700 Subject: Initial pass at converting driver to DRM infrastructure. --- linux-core/xgi_fb.c | 511 +++++++++++++++++++++------------------------------- 1 file changed, 208 insertions(+), 303 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 7d390d4b..ce689847 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -26,343 +26,126 @@ * DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include "xgi_linux.h" #include "xgi_drv.h" -#include "xgi_fb.h" #define XGI_FB_HEAP_START 0x1000000 -static struct xgi_mem_heap *xgi_fb_heap; -static struct kmem_cache *xgi_fb_cache_block = NULL; -extern struct list_head xgi_mempid_list; +struct kmem_cache *xgi_mem_block_cache = NULL; static struct xgi_mem_block *xgi_mem_new_node(void); -static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, unsigned long size); -static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset); -void xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, - pid_t pid) -{ - struct xgi_mem_block *block; - struct xgi_mem_pid *mempid_block; - - if (alloc->is_front) { - alloc->location = XGI_MEMLOC_LOCAL; - alloc->bus_addr = info->fb.base; - alloc->hw_addr = 0; - XGI_INFO - ("Video RAM allocation on front buffer successfully! \n"); - } else { - xgi_down(info->fb_sem); - block = xgi_mem_alloc(info, alloc->size); - xgi_up(info->fb_sem); - - if (block == NULL) { - alloc->location = XGI_MEMLOC_LOCAL; - alloc->size = 0; - alloc->bus_addr = 0; - alloc->hw_addr = 0; - XGI_ERROR("Video RAM allocation failed\n"); - } else { - XGI_INFO("Video RAM allocation succeeded: 0x%p\n", - (char *)block->offset); - alloc->location = XGI_MEMLOC_LOCAL; - alloc->size = block->size; - alloc->bus_addr = info->fb.base + block->offset; - alloc->hw_addr = block->offset; - - /* manage mempid */ - mempid_block = - kmalloc(sizeof(struct xgi_mem_pid), GFP_KERNEL); - mempid_block->location = XGI_MEMLOC_LOCAL; - mempid_block->bus_addr = alloc->bus_addr; - mempid_block->pid = pid; - - if (!mempid_block) - XGI_ERROR("mempid_block alloc failed\n"); - - XGI_INFO - ("Memory ProcessID add one fb block pid:%ld successfully! \n", - mempid_block->pid); - list_add(&mempid_block->list, &xgi_mempid_list); - } - } -} -void xgi_fb_free(struct xgi_info * info, unsigned long bus_addr) +int xgi_mem_heap_init(struct xgi_mem_heap *heap, unsigned int start, + unsigned int end) { struct xgi_mem_block *block; - unsigned long offset = bus_addr - info->fb.base; - struct xgi_mem_pid *mempid_block; - struct xgi_mem_pid *mempid_freeblock = NULL; - - if (offset < 0) { - XGI_INFO("free onscreen frame buffer successfully !\n"); - } else { - xgi_down(info->fb_sem); - block = xgi_mem_free(info, offset); - xgi_up(info->fb_sem); - - if (block == NULL) { - XGI_ERROR("xgi_mem_free() failed at base 0x%lx\n", - offset); - } - - /* manage mempid */ - list_for_each_entry(mempid_block, &xgi_mempid_list, list) { - if (mempid_block->location == XGI_MEMLOC_LOCAL - && mempid_block->bus_addr == bus_addr) { - mempid_freeblock = mempid_block; - break; - } - } - if (mempid_freeblock) { - list_del(&mempid_freeblock->list); - XGI_INFO - ("Memory ProcessID delete one fb block pid:%ld successfully! \n", - mempid_freeblock->pid); - kfree(mempid_freeblock); - } - } -} - -int xgi_fb_heap_init(struct xgi_info * info) -{ - struct xgi_mem_block *block; - - xgi_fb_heap = kmalloc(sizeof(struct xgi_mem_heap), GFP_KERNEL); - if (!xgi_fb_heap) { - XGI_ERROR("xgi_fb_heap alloc failed\n"); - return 0; - } - - INIT_LIST_HEAD(&xgi_fb_heap->free_list); - INIT_LIST_HEAD(&xgi_fb_heap->used_list); - INIT_LIST_HEAD(&xgi_fb_heap->sort_list); - xgi_fb_cache_block = - kmem_cache_create("xgi_fb_block", sizeof(struct xgi_mem_block), 0, - SLAB_HWCACHE_ALIGN, NULL, NULL); + INIT_LIST_HEAD(&heap->free_list); + INIT_LIST_HEAD(&heap->used_list); + INIT_LIST_HEAD(&heap->sort_list); + heap->initialized = TRUE; - if (NULL == xgi_fb_cache_block) { - XGI_ERROR("Fail to creat xgi_fb_block\n"); - goto fail1; - } - - block = - (struct xgi_mem_block *) kmem_cache_alloc(xgi_fb_cache_block, - GFP_KERNEL); + block = kmem_cache_alloc(xgi_mem_block_cache, GFP_KERNEL); if (!block) { - XGI_ERROR("kmem_cache_alloc failed\n"); - goto fail2; + return DRM_ERR(ENOMEM); } - block->offset = XGI_FB_HEAP_START; - block->size = info->fb.size - XGI_FB_HEAP_START; - - list_add(&block->list, &xgi_fb_heap->free_list); + block->offset = start; + block->size = end - start; - xgi_fb_heap->max_freesize = info->fb.size - XGI_FB_HEAP_START; + list_add(&block->list, &heap->free_list); - XGI_INFO("fb start offset: 0x%lx, memory size : 0x%lx\n", block->offset, - block->size); - XGI_INFO("xgi_fb_heap->max_freesize: 0x%lx \n", - xgi_fb_heap->max_freesize); + heap->max_freesize = end - start; - return 1; - - fail2: - if (xgi_fb_cache_block) { - kmem_cache_destroy(xgi_fb_cache_block); - xgi_fb_cache_block = NULL; - } - fail1: - if (xgi_fb_heap) { - kfree(xgi_fb_heap); - xgi_fb_heap = NULL; - } return 0; } -void xgi_fb_heap_cleanup(struct xgi_info * info) + +void xgi_mem_heap_cleanup(struct xgi_mem_heap * heap) { struct list_head *free_list; struct xgi_mem_block *block; struct xgi_mem_block *next; int i; - if (xgi_fb_heap) { - free_list = &xgi_fb_heap->free_list; - for (i = 0; i < 3; i++, free_list++) { - list_for_each_entry_safe(block, next, free_list, list) { - XGI_INFO - ("No. %d block->offset: 0x%lx block->size: 0x%lx \n", - i, block->offset, block->size); - //XGI_INFO("No. %d free block: 0x%p \n", i, block); - kmem_cache_free(xgi_fb_cache_block, block); - block = NULL; - } + free_list = &heap->free_list; + for (i = 0; i < 3; i++, free_list++) { + list_for_each_entry_safe(block, next, free_list, list) { + DRM_INFO + ("No. %d block->offset: 0x%lx block->size: 0x%lx \n", + i, block->offset, block->size); + kmem_cache_free(xgi_mem_block_cache, block); + block = NULL; } - XGI_INFO("xgi_fb_heap: 0x%p \n", xgi_fb_heap); - kfree(xgi_fb_heap); - xgi_fb_heap = NULL; - } - - if (xgi_fb_cache_block) { - kmem_cache_destroy(xgi_fb_cache_block); - xgi_fb_cache_block = NULL; } + + heap->initialized = 0; } -static struct xgi_mem_block *xgi_mem_new_node(void) + +struct xgi_mem_block *xgi_mem_new_node(void) { - struct xgi_mem_block *block; + struct xgi_mem_block *block = + kmem_cache_alloc(xgi_mem_block_cache, GFP_KERNEL); - block = - (struct xgi_mem_block *) kmem_cache_alloc(xgi_fb_cache_block, - GFP_KERNEL); if (!block) { - XGI_ERROR("kmem_cache_alloc failed\n"); + DRM_ERROR("kmem_cache_alloc failed\n"); return NULL; } - return block; -} - -#if 0 -static void xgi_mem_insert_node_after(struct xgi_mem_list * list, - struct xgi_mem_block * current, - struct xgi_mem_block * block); -static void xgi_mem_insert_node_before(struct xgi_mem_list * list, - struct xgi_mem_block * current, - struct xgi_mem_block * block); -static void xgi_mem_insert_node_head(struct xgi_mem_list * list, - struct xgi_mem_block * block); -static void xgi_mem_insert_node_tail(struct xgi_mem_list * list, - struct xgi_mem_block * block); -static void xgi_mem_delete_node(struct xgi_mem_list * list, struct xgi_mem_block * block); -/* - * insert node:block after node:current - */ -static void xgi_mem_insert_node_after(struct xgi_mem_list * list, - struct xgi_mem_block * current, - struct xgi_mem_block * block) -{ - block->prev = current; - block->next = current->next; - current->next = block; - - if (current == list->tail) { - list->tail = block; - } else { - block->next->prev = block; - } -} + block->offset = 0; + block->size = 0; + block->owner = PCIE_INVALID; + block->filp = (DRMFILE) -1; -/* - * insert node:block before node:current - */ -static void xgi_mem_insert_node_before(struct xgi_mem_list * list, - struct xgi_mem_block * current, - struct xgi_mem_block * block) -{ - block->prev = current->prev; - block->next = current; - current->prev = block; - if (current == list->head) { - list->head = block; - } else { - block->prev->next = block; - } -} -void xgi_mem_insert_node_head(struct xgi_mem_list * list, struct xgi_mem_block * block) -{ - block->next = list->head; - block->prev = NULL; - - if (NULL == list->head) { - list->tail = block; - } else { - list->head->prev = block; - } - list->head = block; -} - -static void xgi_mem_insert_node_tail(struct xgi_mem_list * list, - struct xgi_mem_block * block) -{ - block->next = NULL; - block->prev = list->tail; - if (NULL == list->tail) { - list->head = block; - } else { - list->tail->next = block; - } - list->tail = block; + return block; } -static void xgi_mem_delete_node(struct xgi_mem_list * list, struct xgi_mem_block * block) -{ - if (block == list->head) { - list->head = block->next; - } - if (block == list->tail) { - list->tail = block->prev; - } - - if (block->prev) { - block->prev->next = block->next; - } - if (block->next) { - block->next->prev = block->prev; - } - block->next = block->prev = NULL; -} -#endif -static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, - unsigned long originalSize) +struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, + unsigned long originalSize, + enum PcieOwner owner) { struct xgi_mem_block *block, *free_block, *used_block; - unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; - XGI_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", + + DRM_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", originalSize, size); if (size == 0) { - XGI_ERROR("size == 0\n"); + DRM_ERROR("size == 0\n"); return (NULL); } - XGI_INFO("max_freesize: 0x%lx \n", xgi_fb_heap->max_freesize); - if (size > xgi_fb_heap->max_freesize) { - XGI_ERROR + DRM_INFO("max_freesize: 0x%lx \n", heap->max_freesize); + if (size > heap->max_freesize) { + DRM_ERROR ("size: 0x%lx is bigger than frame buffer total free size: 0x%lx !\n", - size, xgi_fb_heap->max_freesize); + size, heap->max_freesize); return (NULL); } - list_for_each_entry(block, &xgi_fb_heap->free_list, list) { - XGI_INFO("free_list: 0x%px \n", free_list); + list_for_each_entry(block, &heap->free_list, list) { + DRM_INFO("block: 0x%px \n", block); if (size <= block->size) { break; } } - if (&block->list == &xgi_fb_heap->free_list) { - XGI_ERROR + if (&block->list == &heap->free_list) { + DRM_ERROR ("Can't allocate %ldk size from frame buffer memory !\n", size / 1024); return (NULL); } free_block = block; - XGI_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", + DRM_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", size, free_block->offset, free_block->size); if (size == free_block->size) { used_block = free_block; - XGI_INFO("size == free_block->size: free_block = 0x%p\n", + DRM_INFO("size == free_block->size: free_block = 0x%p\n", free_block); list_del(&free_block->list); } else { @@ -372,7 +155,7 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, return (NULL); if (used_block == free_block) { - XGI_ERROR("used_block == free_block = 0x%p\n", + DRM_ERROR("used_block == free_block = 0x%p\n", used_block); } @@ -383,14 +166,16 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_info * info, free_block->size -= size; } - xgi_fb_heap->max_freesize -= size; + heap->max_freesize -= size; - list_add(&used_block->list, &xgi_fb_heap->used_list); + list_add(&used_block->list, &heap->used_list); + used_block->owner = owner; return (used_block); } -static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long offset) +int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, + DRMFILE filp) { struct xgi_mem_block *used_block = NULL, *block; struct xgi_mem_block *prev, *next; @@ -398,28 +183,32 @@ static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long unsigned long upper; unsigned long lower; - list_for_each_entry(block, &xgi_fb_heap->used_list, list) { + list_for_each_entry(block, &heap->used_list, list) { if (block->offset == offset) { break; } } - if (&block->list == &xgi_fb_heap->used_list) { - XGI_ERROR("can't find block: 0x%lx to free!\n", offset); - return (NULL); + if (&block->list == &heap->used_list) { + DRM_ERROR("can't find block: 0x%lx to free!\n", offset); + return DRM_ERR(ENOENT); + } + + if (block->filp != filp) { + return DRM_ERR(EPERM); } used_block = block; - XGI_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", + DRM_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", used_block, used_block->offset, used_block->size); - xgi_fb_heap->max_freesize += used_block->size; + heap->max_freesize += used_block->size; prev = next = NULL; upper = used_block->offset + used_block->size; lower = used_block->offset; - list_for_each_entry(block, &xgi_fb_heap->free_list, list) { + list_for_each_entry(block, &heap->free_list, list) { if (block->offset == upper) { next = block; } else if ((block->offset + block->size) == lower) { @@ -427,41 +216,157 @@ static struct xgi_mem_block *xgi_mem_free(struct xgi_info * info, unsigned long } } - XGI_INFO("next = 0x%p, prev = 0x%p\n", next, prev); + DRM_INFO("next = 0x%p, prev = 0x%p\n", next, prev); list_del(&used_block->list); if (prev && next) { prev->size += (used_block->size + next->size); list_del(&next->list); - XGI_INFO("free node 0x%p\n", next); - kmem_cache_free(xgi_fb_cache_block, next); - kmem_cache_free(xgi_fb_cache_block, used_block); - - next = NULL; - used_block = NULL; - return (prev); + DRM_INFO("free node 0x%p\n", next); + kmem_cache_free(xgi_mem_block_cache, next); + kmem_cache_free(xgi_mem_block_cache, used_block); } - - if (prev) { + else if (prev) { prev->size += used_block->size; - XGI_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_fb_cache_block, used_block); - used_block = NULL; - return (prev); + DRM_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_mem_block_cache, used_block); } - - if (next) { + else if (next) { next->size += used_block->size; next->offset = used_block->offset; - XGI_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_fb_cache_block, used_block); - used_block = NULL; - return (next); + DRM_INFO("free node 0x%p\n", used_block); + kmem_cache_free(xgi_mem_block_cache, used_block); + } + else { + list_add(&used_block->list, &heap->free_list); + DRM_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", + used_block, used_block->offset, used_block->size); } - list_add(&used_block->list, &xgi_fb_heap->free_list); - XGI_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", - used_block, used_block->offset, used_block->size); + return 0; +} - return (used_block); + +int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, + DRMFILE filp) +{ + struct xgi_mem_block *block; + + if (alloc->is_front) { + alloc->location = XGI_MEMLOC_LOCAL; + alloc->offset = 0; + alloc->hw_addr = 0; + DRM_INFO + ("Video RAM allocation on front buffer successfully! \n"); + } else { + down(&info->fb_sem); + block = xgi_mem_alloc(&info->fb_heap, alloc->size, PCIE_2D); + up(&info->fb_sem); + + if (block == NULL) { + alloc->location = XGI_MEMLOC_LOCAL; + alloc->size = 0; + DRM_ERROR("Video RAM allocation failed\n"); + return DRM_ERR(ENOMEM); + } else { + DRM_INFO("Video RAM allocation succeeded: 0x%p\n", + (char *)block->offset); + alloc->location = XGI_MEMLOC_LOCAL; + alloc->size = block->size; + alloc->offset = block->offset; + alloc->hw_addr = block->offset; + + block->filp = filp; + } + } + + return 0; +} + + +int xgi_fb_alloc_ioctl(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + struct xgi_mem_alloc alloc; + struct xgi_info *info = dev->dev_private; + int err; + + DRM_COPY_FROM_USER_IOCTL(alloc, (struct xgi_mem_alloc __user *) data, + sizeof(alloc)); + + err = xgi_fb_alloc(info, & alloc, filp); + if (err) { + return err; + } + + DRM_COPY_TO_USER_IOCTL((struct xgi_mem_alloc __user *) data, + alloc, sizeof(alloc)); + + return 0; +} + + +int xgi_fb_free(struct xgi_info * info, unsigned long offset, DRMFILE filp) +{ + int err = 0; + + if (offset == 0) { + DRM_INFO("free onscreen frame buffer successfully !\n"); + } else { + down(&info->fb_sem); + err = xgi_mem_free(&info->fb_heap, offset, filp); + up(&info->fb_sem); + } + + return err; +} + + +int xgi_fb_free_ioctl(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + struct xgi_info *info = dev->dev_private; + u32 offset; + + DRM_COPY_FROM_USER_IOCTL(offset, (unsigned long __user *) data, + sizeof(offset)); + + return xgi_fb_free(info, offset, filp); +} + + +int xgi_fb_heap_init(struct xgi_info * info) +{ + return xgi_mem_heap_init(&info->fb_heap, XGI_FB_HEAP_START, + info->fb.size); +} + +/** + * Free all blocks associated with a particular file handle. + */ +void xgi_fb_free_all(struct xgi_info * info, DRMFILE filp) +{ + if (!info->fb_heap.initialized) { + return; + } + + down(&info->fb_sem); + + do { + struct xgi_mem_block *block; + + list_for_each_entry(block, &info->fb_heap.used_list, list) { + if (block->filp == filp) { + break; + } + } + + if (&block->list == &info->fb_heap.used_list) { + break; + } + + (void) xgi_fb_free(info, block->offset, filp); + } while(1); + + up(&info->fb_sem); } -- cgit v1.2.3 From 15245b670e5359a7dbf9151aa9f160e929e0b46b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 19 Jul 2007 11:38:56 -0700 Subject: Rework xgi_(pcie|fb)_free_all to prevent deadlock. --- linux-core/xgi_fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index ce689847..a5885198 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -365,7 +365,7 @@ void xgi_fb_free_all(struct xgi_info * info, DRMFILE filp) break; } - (void) xgi_fb_free(info, block->offset, filp); + (void) xgi_mem_free(&info->fb_heap, block->offset, filp); } while(1); up(&info->fb_sem); -- cgit v1.2.3 From 8e64d2ae862d5fa02e23c68db6b55393e1f86005 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 24 Jul 2007 13:36:02 -0700 Subject: Fix license formatting. --- linux-core/xgi_fb.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index a5885198..3d3b2ae0 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -1,29 +1,27 @@ - /**************************************************************************** - * Copyright (C) 2003-2006 by XGI Technology, Taiwan. - * * - * All Rights Reserved. * - * * + * Copyright (C) 2003-2006 by XGI Technology, Taiwan. + * + * 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 on the rights to use, copy, modify, merge, - * publish, distribute, sublicense, 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 XGI 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. + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, 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 + * XGI 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. ***************************************************************************/ #include "xgi_drv.h" -- cgit v1.2.3 From c37ed9eca57a42b98cc67ca98dbf5135f5ab7aba Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 26 Jul 2007 17:01:16 -0700 Subject: Eliminate use of DRM_ERR. --- linux-core/xgi_fb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 3d3b2ae0..10343c13 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -45,7 +45,7 @@ int xgi_mem_heap_init(struct xgi_mem_heap *heap, unsigned int start, block = kmem_cache_alloc(xgi_mem_block_cache, GFP_KERNEL); if (!block) { - return DRM_ERR(ENOMEM); + return -ENOMEM; } block->offset = start; @@ -189,11 +189,11 @@ int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, if (&block->list == &heap->used_list) { DRM_ERROR("can't find block: 0x%lx to free!\n", offset); - return DRM_ERR(ENOENT); + return -ENOENT; } if (block->filp != filp) { - return DRM_ERR(EPERM); + return -EPERM; } used_block = block; @@ -265,7 +265,7 @@ int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, alloc->location = XGI_MEMLOC_LOCAL; alloc->size = 0; DRM_ERROR("Video RAM allocation failed\n"); - return DRM_ERR(ENOMEM); + return -ENOMEM; } else { DRM_INFO("Video RAM allocation succeeded: 0x%p\n", (char *)block->offset); -- cgit v1.2.3 From cd51f131389297f923798daef6c734ba93f4422b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 27 Jul 2007 15:45:59 -0700 Subject: Convert to new ioctl interface between core DRM and device-specific module. --- linux-core/xgi_fb.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 10343c13..9c60a874 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -94,7 +94,7 @@ struct xgi_mem_block *xgi_mem_new_node(void) block->offset = 0; block->size = 0; block->owner = PCIE_INVALID; - block->filp = (DRMFILE) -1; + block->filp = (struct drm_file *) -1; return block; } @@ -173,7 +173,7 @@ struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, } int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, - DRMFILE filp) + struct drm_file * filp) { struct xgi_mem_block *used_block = NULL, *block; struct xgi_mem_block *prev, *next; @@ -246,7 +246,7 @@ int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, - DRMFILE filp) + struct drm_file * filp) { struct xgi_mem_block *block; @@ -282,29 +282,19 @@ int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, } -int xgi_fb_alloc_ioctl(DRM_IOCTL_ARGS) +int xgi_fb_alloc_ioctl(struct drm_device * dev, void * data, + struct drm_file * filp) { - DRM_DEVICE; - struct xgi_mem_alloc alloc; + struct xgi_mem_alloc *alloc = + (struct xgi_mem_alloc *) data; struct xgi_info *info = dev->dev_private; - int err; - DRM_COPY_FROM_USER_IOCTL(alloc, (struct xgi_mem_alloc __user *) data, - sizeof(alloc)); - - err = xgi_fb_alloc(info, & alloc, filp); - if (err) { - return err; - } - - DRM_COPY_TO_USER_IOCTL((struct xgi_mem_alloc __user *) data, - alloc, sizeof(alloc)); - - return 0; + return xgi_fb_alloc(info, alloc, filp); } -int xgi_fb_free(struct xgi_info * info, unsigned long offset, DRMFILE filp) +int xgi_fb_free(struct xgi_info * info, unsigned long offset, + struct drm_file * filp) { int err = 0; @@ -320,16 +310,12 @@ int xgi_fb_free(struct xgi_info * info, unsigned long offset, DRMFILE filp) } -int xgi_fb_free_ioctl(DRM_IOCTL_ARGS) +int xgi_fb_free_ioctl(struct drm_device * dev, void * data, + struct drm_file * filp) { - DRM_DEVICE; struct xgi_info *info = dev->dev_private; - u32 offset; - - DRM_COPY_FROM_USER_IOCTL(offset, (unsigned long __user *) data, - sizeof(offset)); - return xgi_fb_free(info, offset, filp); + return xgi_fb_free(info, *(u32 *) data, filp); } @@ -342,7 +328,7 @@ int xgi_fb_heap_init(struct xgi_info * info) /** * Free all blocks associated with a particular file handle. */ -void xgi_fb_free_all(struct xgi_info * info, DRMFILE filp) +void xgi_fb_free_all(struct xgi_info * info, struct drm_file * filp) { if (!info->fb_heap.initialized) { return; -- cgit v1.2.3 From 997a9a738ec26cf0ef2c7dee5e30bb53bd11bf6c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 15:31:34 -0700 Subject: Eliminate allocation "owner" usage. --- linux-core/xgi_fb.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 9c60a874..bbdebb57 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -93,7 +93,6 @@ struct xgi_mem_block *xgi_mem_new_node(void) block->offset = 0; block->size = 0; - block->owner = PCIE_INVALID; block->filp = (struct drm_file *) -1; return block; @@ -101,8 +100,7 @@ struct xgi_mem_block *xgi_mem_new_node(void) struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, - unsigned long originalSize, - enum PcieOwner owner) + unsigned long originalSize) { struct xgi_mem_block *block, *free_block, *used_block; unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; @@ -167,7 +165,6 @@ struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, heap->max_freesize -= size; list_add(&used_block->list, &heap->used_list); - used_block->owner = owner; return (used_block); } @@ -258,7 +255,7 @@ int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, ("Video RAM allocation on front buffer successfully! \n"); } else { down(&info->fb_sem); - block = xgi_mem_alloc(&info->fb_heap, alloc->size, PCIE_2D); + block = xgi_mem_alloc(&info->fb_heap, alloc->size); up(&info->fb_sem); if (block == NULL) { -- cgit v1.2.3 From 78e9c1a93d00097895bc77d9ac90da1945021804 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 15:37:56 -0700 Subject: Eliminate special-case handling of framebuffer (fake) allocation. --- linux-core/xgi_fb.c | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index bbdebb57..b27b6b20 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -247,32 +247,23 @@ int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, { struct xgi_mem_block *block; - if (alloc->is_front) { - alloc->location = XGI_MEMLOC_LOCAL; - alloc->offset = 0; - alloc->hw_addr = 0; - DRM_INFO - ("Video RAM allocation on front buffer successfully! \n"); + down(&info->fb_sem); + block = xgi_mem_alloc(&info->fb_heap, alloc->size); + up(&info->fb_sem); + + if (block == NULL) { + alloc->size = 0; + DRM_ERROR("Video RAM allocation failed\n"); + return -ENOMEM; } else { - down(&info->fb_sem); - block = xgi_mem_alloc(&info->fb_heap, alloc->size); - up(&info->fb_sem); - - if (block == NULL) { - alloc->location = XGI_MEMLOC_LOCAL; - alloc->size = 0; - DRM_ERROR("Video RAM allocation failed\n"); - return -ENOMEM; - } else { - DRM_INFO("Video RAM allocation succeeded: 0x%p\n", - (char *)block->offset); - alloc->location = XGI_MEMLOC_LOCAL; - alloc->size = block->size; - alloc->offset = block->offset; - alloc->hw_addr = block->offset; - - block->filp = filp; - } + DRM_INFO("Video RAM allocation succeeded: 0x%p\n", + (char *)block->offset); + alloc->location = XGI_MEMLOC_LOCAL; + alloc->size = block->size; + alloc->offset = block->offset; + alloc->hw_addr = block->offset; + + block->filp = filp; } return 0; @@ -295,13 +286,9 @@ int xgi_fb_free(struct xgi_info * info, unsigned long offset, { int err = 0; - if (offset == 0) { - DRM_INFO("free onscreen frame buffer successfully !\n"); - } else { - down(&info->fb_sem); - err = xgi_mem_free(&info->fb_heap, offset, filp); - up(&info->fb_sem); - } + down(&info->fb_sem); + err = xgi_mem_free(&info->fb_heap, offset, filp); + up(&info->fb_sem); return err; } -- cgit v1.2.3 From f96bff9e213a950ab910832908d30e732435e628 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 16:09:05 -0700 Subject: Unify infrastructure for allocating (not yet freeing) on-card / GART memory. --- linux-core/xgi_fb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index b27b6b20..1d5dc22b 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -99,8 +99,8 @@ struct xgi_mem_block *xgi_mem_new_node(void) } -struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, - unsigned long originalSize) +static struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, + unsigned long originalSize) { struct xgi_mem_block *block, *free_block, *used_block; unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; @@ -242,13 +242,15 @@ int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, } -int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, +int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, struct drm_file * filp) { struct xgi_mem_block *block; down(&info->fb_sem); - block = xgi_mem_alloc(&info->fb_heap, alloc->size); + block = xgi_mem_alloc((alloc->location == XGI_MEMLOC_LOCAL) + ? &info->fb_heap : &info->pcie_heap, + alloc->size); up(&info->fb_sem); if (block == NULL) { @@ -258,11 +260,14 @@ int xgi_fb_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, } else { DRM_INFO("Video RAM allocation succeeded: 0x%p\n", (char *)block->offset); - alloc->location = XGI_MEMLOC_LOCAL; alloc->size = block->size; alloc->offset = block->offset; alloc->hw_addr = block->offset; + if (alloc->location == XGI_MEMLOC_NON_LOCAL) { + alloc->hw_addr += info->pcie.base; + } + block->filp = filp; } @@ -277,7 +282,8 @@ int xgi_fb_alloc_ioctl(struct drm_device * dev, void * data, (struct xgi_mem_alloc *) data; struct xgi_info *info = dev->dev_private; - return xgi_fb_alloc(info, alloc, filp); + alloc->location = XGI_MEMLOC_LOCAL; + return xgi_alloc(info, alloc, filp); } -- cgit v1.2.3 From 90907c59152f628d6f0efea4927a06e547f4a3c7 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 16:17:23 -0700 Subject: Replace per-heap semaphores with drm_device::struct_mutex. --- linux-core/xgi_fb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 1d5dc22b..373c45dd 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -247,11 +247,11 @@ int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, { struct xgi_mem_block *block; - down(&info->fb_sem); + mutex_lock(&info->dev->struct_mutex); block = xgi_mem_alloc((alloc->location == XGI_MEMLOC_LOCAL) ? &info->fb_heap : &info->pcie_heap, alloc->size); - up(&info->fb_sem); + mutex_unlock(&info->dev->struct_mutex); if (block == NULL) { alloc->size = 0; @@ -292,9 +292,9 @@ int xgi_fb_free(struct xgi_info * info, unsigned long offset, { int err = 0; - down(&info->fb_sem); + mutex_lock(&info->dev->struct_mutex); err = xgi_mem_free(&info->fb_heap, offset, filp); - up(&info->fb_sem); + mutex_unlock(&info->dev->struct_mutex); return err; } @@ -324,7 +324,7 @@ void xgi_fb_free_all(struct xgi_info * info, struct drm_file * filp) return; } - down(&info->fb_sem); + mutex_lock(&info->dev->struct_mutex); do { struct xgi_mem_block *block; @@ -342,5 +342,5 @@ void xgi_fb_free_all(struct xgi_info * info, struct drm_file * filp) (void) xgi_mem_free(&info->fb_heap, block->offset, filp); } while(1); - up(&info->fb_sem); + mutex_unlock(&info->dev->struct_mutex); } -- cgit v1.2.3 From f3072becda3a2d5fe587f20e155d4d4f9ace60a2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 16:35:07 -0700 Subject: Refactor xgi_(fb|pcie)_free_all into xgi_free_all. --- linux-core/xgi_fb.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 373c45dd..f8341a67 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -318,29 +318,27 @@ int xgi_fb_heap_init(struct xgi_info * info) /** * Free all blocks associated with a particular file handle. */ -void xgi_fb_free_all(struct xgi_info * info, struct drm_file * filp) +void xgi_free_all(struct xgi_info * info, struct xgi_mem_heap * heap, + struct drm_file * filp) { - if (!info->fb_heap.initialized) { + if (!heap->initialized) { return; } - mutex_lock(&info->dev->struct_mutex); do { struct xgi_mem_block *block; - list_for_each_entry(block, &info->fb_heap.used_list, list) { + list_for_each_entry(block, &heap->used_list, list) { if (block->filp == filp) { break; } } - if (&block->list == &info->fb_heap.used_list) { + if (&block->list == &heap->used_list) { break; } - (void) xgi_mem_free(&info->fb_heap, block->offset, filp); + (void) xgi_mem_free(heap, block->offset, filp); } while(1); - - mutex_unlock(&info->dev->struct_mutex); } -- cgit v1.2.3 From f7ba02b7458823627097a2320bf9befa84fc9c76 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 6 Aug 2007 17:27:15 -0700 Subject: Unify infrastructure for freeing on-card / GART memory. --- linux-core/xgi_fb.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index f8341a67..26e6fc4e 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -169,8 +169,8 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, return (used_block); } -int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, - struct drm_file * filp) +static int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, + struct drm_file * filp) { struct xgi_mem_block *used_block = NULL, *block; struct xgi_mem_block *prev, *next; @@ -287,13 +287,16 @@ int xgi_fb_alloc_ioctl(struct drm_device * dev, void * data, } -int xgi_fb_free(struct xgi_info * info, unsigned long offset, - struct drm_file * filp) +int xgi_free(struct xgi_info * info, unsigned long index, + struct drm_file * filp) { int err = 0; + const unsigned heap = index & 0x03; mutex_lock(&info->dev->struct_mutex); - err = xgi_mem_free(&info->fb_heap, offset, filp); + err = xgi_mem_free((heap == XGI_MEMLOC_NON_LOCAL) + ? &info->pcie_heap : &info->fb_heap, + (index & ~0x03), filp); mutex_unlock(&info->dev->struct_mutex); return err; @@ -305,7 +308,7 @@ int xgi_fb_free_ioctl(struct drm_device * dev, void * data, { struct xgi_info *info = dev->dev_private; - return xgi_fb_free(info, *(u32 *) data, filp); + return xgi_free(info, XGI_MEMLOC_LOCAL | *(u32 *) data, filp); } -- cgit v1.2.3 From aea6b4dea9708f66f5fc2068fe84407682570aca Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 9 Aug 2007 15:30:36 -0700 Subject: Unify alloc and free ioctls. The DRM_XGI_PCIE_ALLOC and DRM_XGI_FB_ALLOC ioctls (and the matching free ioctls) are unified to DRM_XGI_ALLOC. The desired memory region is selected by xgi_mem_alloc::location. The region is magically encoded in xgi_mem_alloc::index, which is used to release the memory. Bump to version 0.11.0. This update requires a new DDX. --- linux-core/xgi_fb.c | 65 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 26e6fc4e..d0182831 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -169,8 +169,8 @@ static struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, return (used_block); } -static int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, - struct drm_file * filp) +int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, + struct drm_file * filp) { struct xgi_mem_block *used_block = NULL, *block; struct xgi_mem_block *prev, *next; @@ -243,26 +243,45 @@ static int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, - struct drm_file * filp) + struct drm_file * filp) { struct xgi_mem_block *block; + struct xgi_mem_heap *heap; + const char *const mem_name = (alloc->location == XGI_MEMLOC_LOCAL) + ? "on-card" : "GART"; + + + if ((alloc->location != XGI_MEMLOC_LOCAL) + && (alloc->location != XGI_MEMLOC_NON_LOCAL)) { + DRM_ERROR("Invalid memory pool (0x%08x) specified.\n", + alloc->location); + return -EINVAL; + } + + heap = (alloc->location == XGI_MEMLOC_LOCAL) + ? &info->fb_heap : &info->pcie_heap; + + if (!heap->initialized) { + DRM_ERROR("Attempt to allocate from uninitialized memory " + "pool (0x%08x).\n", alloc->location); + return -EINVAL; + } mutex_lock(&info->dev->struct_mutex); - block = xgi_mem_alloc((alloc->location == XGI_MEMLOC_LOCAL) - ? &info->fb_heap : &info->pcie_heap, - alloc->size); + block = xgi_mem_alloc(heap, alloc->size); mutex_unlock(&info->dev->struct_mutex); if (block == NULL) { alloc->size = 0; - DRM_ERROR("Video RAM allocation failed\n"); + DRM_ERROR("%s memory allocation failed\n", mem_name); return -ENOMEM; } else { - DRM_INFO("Video RAM allocation succeeded: 0x%p\n", - (char *)block->offset); + DRM_DEBUG("%s memory allocation succeeded: 0x%p\n", + mem_name, (char *)block->offset); alloc->size = block->size; alloc->offset = block->offset; alloc->hw_addr = block->offset; + alloc->index = alloc->offset | alloc->location; if (alloc->location == XGI_MEMLOC_NON_LOCAL) { alloc->hw_addr += info->pcie.base; @@ -275,47 +294,45 @@ int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, } -int xgi_fb_alloc_ioctl(struct drm_device * dev, void * data, - struct drm_file * filp) +int xgi_alloc_ioctl(struct drm_device * dev, void * data, + struct drm_file * filp) { - struct xgi_mem_alloc *alloc = - (struct xgi_mem_alloc *) data; struct xgi_info *info = dev->dev_private; - alloc->location = XGI_MEMLOC_LOCAL; - return xgi_alloc(info, alloc, filp); + return xgi_alloc(info, (struct xgi_mem_alloc *) data, filp); } int xgi_free(struct xgi_info * info, unsigned long index, struct drm_file * filp) { - int err = 0; - const unsigned heap = index & 0x03; + int err; + struct xgi_mem_heap *const heap = + ((index & 0x03) == XGI_MEMLOC_NON_LOCAL) + ? &info->pcie_heap : &info->fb_heap; + const u32 offset = (index & ~0x03); mutex_lock(&info->dev->struct_mutex); - err = xgi_mem_free((heap == XGI_MEMLOC_NON_LOCAL) - ? &info->pcie_heap : &info->fb_heap, - (index & ~0x03), filp); + err = xgi_mem_free(heap, offset, filp); mutex_unlock(&info->dev->struct_mutex); return err; } -int xgi_fb_free_ioctl(struct drm_device * dev, void * data, - struct drm_file * filp) +int xgi_free_ioctl(struct drm_device * dev, void * data, + struct drm_file * filp) { struct xgi_info *info = dev->dev_private; - return xgi_free(info, XGI_MEMLOC_LOCAL | *(u32 *) data, filp); + return xgi_free(info, *(unsigned long *) data, filp); } int xgi_fb_heap_init(struct xgi_info * info) { return xgi_mem_heap_init(&info->fb_heap, XGI_FB_HEAP_START, - info->fb.size); + info->fb.size - XGI_FB_HEAP_START); } /** -- cgit v1.2.3 From dbd4d0597ff32458bbe4347bdea0e4b9e55a14da Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 9 Aug 2007 16:01:14 -0700 Subject: Use sman memory manager instead of internal version. --- linux-core/xgi_fb.c | 281 ++++------------------------------------------------ 1 file changed, 20 insertions(+), 261 deletions(-) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index d0182831..40f39fbc 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -28,225 +28,10 @@ #define XGI_FB_HEAP_START 0x1000000 -struct kmem_cache *xgi_mem_block_cache = NULL; - -static struct xgi_mem_block *xgi_mem_new_node(void); - - -int xgi_mem_heap_init(struct xgi_mem_heap *heap, unsigned int start, - unsigned int end) -{ - struct xgi_mem_block *block; - - INIT_LIST_HEAD(&heap->free_list); - INIT_LIST_HEAD(&heap->used_list); - INIT_LIST_HEAD(&heap->sort_list); - heap->initialized = TRUE; - - block = kmem_cache_alloc(xgi_mem_block_cache, GFP_KERNEL); - if (!block) { - return -ENOMEM; - } - - block->offset = start; - block->size = end - start; - - list_add(&block->list, &heap->free_list); - - heap->max_freesize = end - start; - - return 0; -} - - -void xgi_mem_heap_cleanup(struct xgi_mem_heap * heap) -{ - struct list_head *free_list; - struct xgi_mem_block *block; - struct xgi_mem_block *next; - int i; - - free_list = &heap->free_list; - for (i = 0; i < 3; i++, free_list++) { - list_for_each_entry_safe(block, next, free_list, list) { - DRM_INFO - ("No. %d block->offset: 0x%lx block->size: 0x%lx \n", - i, block->offset, block->size); - kmem_cache_free(xgi_mem_block_cache, block); - block = NULL; - } - } - - heap->initialized = 0; -} - - -struct xgi_mem_block *xgi_mem_new_node(void) -{ - struct xgi_mem_block *block = - kmem_cache_alloc(xgi_mem_block_cache, GFP_KERNEL); - - if (!block) { - DRM_ERROR("kmem_cache_alloc failed\n"); - return NULL; - } - - block->offset = 0; - block->size = 0; - block->filp = (struct drm_file *) -1; - - return block; -} - - -static struct xgi_mem_block *xgi_mem_alloc(struct xgi_mem_heap * heap, - unsigned long originalSize) -{ - struct xgi_mem_block *block, *free_block, *used_block; - unsigned long size = (originalSize + PAGE_SIZE - 1) & PAGE_MASK; - - - DRM_INFO("Original 0x%lx bytes requested, really 0x%lx allocated\n", - originalSize, size); - - if (size == 0) { - DRM_ERROR("size == 0\n"); - return (NULL); - } - DRM_INFO("max_freesize: 0x%lx \n", heap->max_freesize); - if (size > heap->max_freesize) { - DRM_ERROR - ("size: 0x%lx is bigger than frame buffer total free size: 0x%lx !\n", - size, heap->max_freesize); - return (NULL); - } - - list_for_each_entry(block, &heap->free_list, list) { - DRM_INFO("block: 0x%px \n", block); - if (size <= block->size) { - break; - } - } - - if (&block->list == &heap->free_list) { - DRM_ERROR - ("Can't allocate %ldk size from frame buffer memory !\n", - size / 1024); - return (NULL); - } - - free_block = block; - DRM_INFO("alloc size: 0x%lx from offset: 0x%lx size: 0x%lx \n", - size, free_block->offset, free_block->size); - - if (size == free_block->size) { - used_block = free_block; - DRM_INFO("size == free_block->size: free_block = 0x%p\n", - free_block); - list_del(&free_block->list); - } else { - used_block = xgi_mem_new_node(); - - if (used_block == NULL) - return (NULL); - - if (used_block == free_block) { - DRM_ERROR("used_block == free_block = 0x%p\n", - used_block); - } - - used_block->offset = free_block->offset; - used_block->size = size; - - free_block->offset += size; - free_block->size -= size; - } - - heap->max_freesize -= size; - - list_add(&used_block->list, &heap->used_list); - - return (used_block); -} - -int xgi_mem_free(struct xgi_mem_heap * heap, unsigned long offset, - struct drm_file * filp) -{ - struct xgi_mem_block *used_block = NULL, *block; - struct xgi_mem_block *prev, *next; - - unsigned long upper; - unsigned long lower; - - list_for_each_entry(block, &heap->used_list, list) { - if (block->offset == offset) { - break; - } - } - - if (&block->list == &heap->used_list) { - DRM_ERROR("can't find block: 0x%lx to free!\n", offset); - return -ENOENT; - } - - if (block->filp != filp) { - return -EPERM; - } - - used_block = block; - DRM_INFO("used_block: 0x%p, offset = 0x%lx, size = 0x%lx\n", - used_block, used_block->offset, used_block->size); - - heap->max_freesize += used_block->size; - - prev = next = NULL; - upper = used_block->offset + used_block->size; - lower = used_block->offset; - - list_for_each_entry(block, &heap->free_list, list) { - if (block->offset == upper) { - next = block; - } else if ((block->offset + block->size) == lower) { - prev = block; - } - } - - DRM_INFO("next = 0x%p, prev = 0x%p\n", next, prev); - list_del(&used_block->list); - - if (prev && next) { - prev->size += (used_block->size + next->size); - list_del(&next->list); - DRM_INFO("free node 0x%p\n", next); - kmem_cache_free(xgi_mem_block_cache, next); - kmem_cache_free(xgi_mem_block_cache, used_block); - } - else if (prev) { - prev->size += used_block->size; - DRM_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_mem_block_cache, used_block); - } - else if (next) { - next->size += used_block->size; - next->offset = used_block->offset; - DRM_INFO("free node 0x%p\n", used_block); - kmem_cache_free(xgi_mem_block_cache, used_block); - } - else { - list_add(&used_block->list, &heap->free_list); - DRM_INFO("Recycled free node %p, offset = 0x%lx, size = 0x%lx\n", - used_block, used_block->offset, used_block->size); - } - - return 0; -} - - int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, struct drm_file * filp) { - struct xgi_mem_block *block; - struct xgi_mem_heap *heap; + struct drm_memblock_item *block; const char *const mem_name = (alloc->location == XGI_MEMLOC_LOCAL) ? "on-card" : "GART"; @@ -258,17 +43,16 @@ int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, return -EINVAL; } - heap = (alloc->location == XGI_MEMLOC_LOCAL) - ? &info->fb_heap : &info->pcie_heap; - - if (!heap->initialized) { + if ((alloc->location == XGI_MEMLOC_LOCAL) + ? !info->fb_heap_initialized : !info->pcie_heap_initialized) { DRM_ERROR("Attempt to allocate from uninitialized memory " "pool (0x%08x).\n", alloc->location); return -EINVAL; } mutex_lock(&info->dev->struct_mutex); - block = xgi_mem_alloc(heap, alloc->size); + block = drm_sman_alloc(&info->sman, alloc->location, alloc->size, + 0, (unsigned long) filp); mutex_unlock(&info->dev->struct_mutex); if (block == NULL) { @@ -276,18 +60,17 @@ int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, DRM_ERROR("%s memory allocation failed\n", mem_name); return -ENOMEM; } else { - DRM_DEBUG("%s memory allocation succeeded: 0x%p\n", - mem_name, (char *)block->offset); - alloc->size = block->size; - alloc->offset = block->offset; - alloc->hw_addr = block->offset; - alloc->index = alloc->offset | alloc->location; + alloc->offset = (*block->mm->offset)(block->mm, + block->mm_info); + alloc->hw_addr = alloc->offset; + alloc->index = block->user_hash.key; if (alloc->location == XGI_MEMLOC_NON_LOCAL) { alloc->hw_addr += info->pcie.base; } - block->filp = filp; + DRM_DEBUG("%s memory allocation succeeded: 0x%x\n", + mem_name, alloc->offset); } return 0; @@ -307,13 +90,9 @@ int xgi_free(struct xgi_info * info, unsigned long index, struct drm_file * filp) { int err; - struct xgi_mem_heap *const heap = - ((index & 0x03) == XGI_MEMLOC_NON_LOCAL) - ? &info->pcie_heap : &info->fb_heap; - const u32 offset = (index & ~0x03); mutex_lock(&info->dev->struct_mutex); - err = xgi_mem_free(heap, offset, filp); + err = drm_sman_free_key(&info->sman, index); mutex_unlock(&info->dev->struct_mutex); return err; @@ -331,34 +110,14 @@ int xgi_free_ioctl(struct drm_device * dev, void * data, int xgi_fb_heap_init(struct xgi_info * info) { - return xgi_mem_heap_init(&info->fb_heap, XGI_FB_HEAP_START, + int err; + + mutex_lock(&info->dev->struct_mutex); + err = drm_sman_set_range(&info->sman, XGI_MEMLOC_LOCAL, + XGI_FB_HEAP_START, info->fb.size - XGI_FB_HEAP_START); -} - -/** - * Free all blocks associated with a particular file handle. - */ -void xgi_free_all(struct xgi_info * info, struct xgi_mem_heap * heap, - struct drm_file * filp) -{ - if (!heap->initialized) { - return; - } - - - do { - struct xgi_mem_block *block; - - list_for_each_entry(block, &heap->used_list, list) { - if (block->filp == filp) { - break; - } - } - - if (&block->list == &heap->used_list) { - break; - } + mutex_unlock(&info->dev->struct_mutex); - (void) xgi_mem_free(heap, block->offset, filp); - } while(1); + info->fb_heap_initialized = (err == 0); + return err; } -- cgit v1.2.3 From a3881ad2fef99aaf0a863609a847020ea822798c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 18 Sep 2007 11:03:49 -0700 Subject: Add ioc32 compat layer for XGI DRM. --- linux-core/xgi_fb.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'linux-core/xgi_fb.c') diff --git a/linux-core/xgi_fb.c b/linux-core/xgi_fb.c index 40f39fbc..2e2d0094 100644 --- a/linux-core/xgi_fb.c +++ b/linux-core/xgi_fb.c @@ -65,6 +65,13 @@ int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc, alloc->hw_addr = alloc->offset; alloc->index = block->user_hash.key; + if (block->user_hash.key != (unsigned long) alloc->index) { + DRM_ERROR("%s truncated handle %lx for pool %d " + "offset %x\n", + __func__, block->user_hash.key, + alloc->location, alloc->offset); + } + if (alloc->location == XGI_MEMLOC_NON_LOCAL) { alloc->hw_addr += info->pcie.base; } -- cgit v1.2.3