]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/blob - linux-core/xgi_fb.c
libdrm_radeon: add radeon_bo_is_referenced_by_cs function
[glsdk/libdrm.git] / linux-core / xgi_fb.c
1 /****************************************************************************
2  * Copyright (C) 2003-2006 by XGI Technology, Taiwan.
3  *
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation on the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial
16  * portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
21  * XGI AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  ***************************************************************************/
27 #include "xgi_drv.h"
29 #define XGI_FB_HEAP_START 0x1000000
31 int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc,
32               struct drm_file * filp)
33 {
34         struct drm_memblock_item *block;
35         const char *const mem_name = (alloc->location == XGI_MEMLOC_LOCAL)
36                 ? "on-card" : "GART";
39         if ((alloc->location != XGI_MEMLOC_LOCAL)
40             && (alloc->location != XGI_MEMLOC_NON_LOCAL)) {
41                 DRM_ERROR("Invalid memory pool (0x%08x) specified.\n",
42                           alloc->location);
43                 return -EINVAL;
44         }
46         if ((alloc->location == XGI_MEMLOC_LOCAL)
47             ? !info->fb_heap_initialized : !info->pcie_heap_initialized) {
48                 DRM_ERROR("Attempt to allocate from uninitialized memory "
49                           "pool (0x%08x).\n", alloc->location);
50                 return -EINVAL;
51         }
53         mutex_lock(&info->dev->struct_mutex);
54         block = drm_sman_alloc(&info->sman, alloc->location, alloc->size,
55                                0, (unsigned long) filp);
56         mutex_unlock(&info->dev->struct_mutex);
58         if (block == NULL) {
59                 alloc->size = 0;
60                 DRM_ERROR("%s memory allocation failed\n", mem_name);
61                 return -ENOMEM;
62         } else {
63                 alloc->offset = (*block->mm->offset)(block->mm,
64                                                      block->mm_info);
65                 alloc->hw_addr = alloc->offset;
66                 alloc->index = block->user_hash.key;
68                 if (block->user_hash.key != (unsigned long) alloc->index) {
69                         DRM_ERROR("%s truncated handle %lx for pool %d "
70                                   "offset %x\n",
71                                   __func__, block->user_hash.key,
72                                   alloc->location, alloc->offset);
73                 }
75                 if (alloc->location == XGI_MEMLOC_NON_LOCAL) {
76                         alloc->hw_addr += info->pcie.base;
77                 }
79                 DRM_DEBUG("%s memory allocation succeeded: 0x%x\n",
80                           mem_name, alloc->offset);
81         }
83         return 0;
84 }
87 int xgi_alloc_ioctl(struct drm_device * dev, void * data,
88                     struct drm_file * filp)
89 {
90         struct xgi_info *info = dev->dev_private;
92         return xgi_alloc(info, (struct xgi_mem_alloc *) data, filp);
93 }
96 int xgi_free(struct xgi_info * info, unsigned int index,
97              struct drm_file * filp)
98 {
99         int err;
101         mutex_lock(&info->dev->struct_mutex);
102         err = drm_sman_free_key(&info->sman, index);
103         mutex_unlock(&info->dev->struct_mutex);
105         return err;
109 int xgi_free_ioctl(struct drm_device * dev, void * data,
110                    struct drm_file * filp)
112         struct xgi_info *info = dev->dev_private;
114         return xgi_free(info, *(unsigned int *) data, filp);
118 int xgi_fb_heap_init(struct xgi_info * info)
120         int err;
122         mutex_lock(&info->dev->struct_mutex);
123         err = drm_sman_set_range(&info->sman, XGI_MEMLOC_LOCAL,
124                                  XGI_FB_HEAP_START,
125                                  info->fb.size - XGI_FB_HEAP_START);
126         mutex_unlock(&info->dev->struct_mutex);
128         info->fb_heap_initialized = (err == 0);
129         return err;