Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 203 lines (182 sloc) 5.199 kb
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 PathScale Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include "drm.h"
28 #include "nouveau_drv.h"
29 #include "pscnv_mem.h"
ecf63a4 @koriakin Nuke two includes from nouveau_drv.h
koriakin authored
30 #include "pscnv_vm.h"
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
31 #ifdef __linux__
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
32 #include <linux/list.h>
33 #include <linux/kernel.h>
34 #include <linux/mutex.h>
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
35 #endif
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
36
37 int
38 pscnv_mem_init(struct drm_device *dev)
39 {
40 struct drm_nouveau_private *dev_priv = dev->dev_private;
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
41 int ret;
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
42
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
43 int dma_bits = 32;
b14c58e @mlankhorst more port
mlankhorst authored
44 #ifdef __linux__
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
45 if (dev_priv->card_type >= NV_50 &&
46 pci_dma_supported(dev->pdev, DMA_BIT_MASK(40)))
47 dma_bits = 40;
48
49 ret = pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(dma_bits));
50 if (ret) {
51 NV_ERROR(dev, "Error setting DMA mask: %d\n", ret);
52 return ret;
53 }
b14c58e @mlankhorst more port
mlankhorst authored
54 #else
55 if (dev_priv->card_type >= NV_50)
56 dma_bits = 40;
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
57 #endif
b14c58e @mlankhorst more port
mlankhorst authored
58 dev_priv->dma_mask = DMA_BIT_MASK(dma_bits);
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
59
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
60 spin_lock_init(&dev_priv->pramin_lock);
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
61 mutex_init(&dev_priv->vram_mutex);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
62
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
63 switch (dev_priv->card_type) {
64 case NV_50:
65 ret = nv50_vram_init(dev);
66 break;
270c119 @mlankhorst fix d9 support and corruption
mlankhorst authored
67 case NV_D0:
baf85a1 @koriakin vram: Add NVC0 support.
koriakin authored
68 case NV_C0:
69 ret = nvc0_vram_init(dev);
70 break;
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
71 default:
72 NV_ERROR(dev, "No VRAM allocator for NV%02x!\n", dev_priv->chipset);
73 ret = -ENOSYS;
74 }
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
75 if (ret)
76 return ret;
77
5cda219 @mlankhorst minor steps to getting running on bsd
mlankhorst authored
78 dev_priv->fb_mtrr = drm_mtrr_add(drm_get_resource_start(dev, 1),
79 drm_get_resource_len(dev, 1),
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
80 DRM_MTRR_WC);
81
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
82 return 0;
83 }
84
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
85 void
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
86 pscnv_mem_takedown(struct drm_device *dev)
87 {
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
88 struct drm_nouveau_private *dev_priv = dev->dev_private;
89 dev_priv->vram->takedown(dev);
90
91 if (dev_priv->fb_mtrr >= 0) {
5cda219 @mlankhorst minor steps to getting running on bsd
mlankhorst authored
92 drm_mtrr_del(dev_priv->fb_mtrr, drm_get_resource_start(dev, 1),
93 drm_get_resource_len(dev, 1), DRM_MTRR_WC);
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
94 dev_priv->fb_mtrr = 0;
95 }
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
96 }
97
98 struct pscnv_bo *
99 pscnv_mem_alloc(struct drm_device *dev,
100 uint64_t size, int flags, int tile_flags, uint32_t cookie)
101 {
102 static int serial = 0;
103 struct drm_nouveau_private *dev_priv = dev->dev_private;
104 struct pscnv_bo *res;
105 int ret;
106 /* avoid all sorts of integer overflows possible otherwise. */
107 if (size >= (1ULL << 40))
108 return 0;
109 if (!size)
110 return 0;
111
112 res = kzalloc (sizeof *res, GFP_KERNEL);
113 if (!res)
114 return 0;
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
115 size = (size + PSCNV_MEM_PAGE_SIZE - 1) & ~(PSCNV_MEM_PAGE_SIZE - 1);
116 size = PAGE_ALIGN(size);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
117 res->dev = dev;
118 res->size = size;
119 res->flags = flags;
120 res->tile_flags = tile_flags;
121 res->cookie = cookie;
122 res->gem = 0;
123
124 /* XXX: another mutex? */
125 mutex_lock(&dev_priv->vram_mutex);
126 res->serial = serial++;
127 mutex_unlock(&dev_priv->vram_mutex);
128
129 if (pscnv_mem_debug >= 1)
130 NV_INFO(dev, "Allocating %d, %#llx-byte %sBO of type %08x, tile_flags %x\n", res->serial, size,
131 (flags & PSCNV_GEM_CONTIG ? "contig " : ""), cookie, tile_flags);
132 switch (res->flags & PSCNV_GEM_MEMTYPE_MASK) {
133 case PSCNV_GEM_VRAM_SMALL:
134 case PSCNV_GEM_VRAM_LARGE:
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
135 ret = dev_priv->vram->alloc(res);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
136 break;
137 case PSCNV_GEM_SYSRAM_SNOOP:
138 case PSCNV_GEM_SYSRAM_NOSNOOP:
9a44ae4 @koriakin Add tiled sysram support.
koriakin authored
139 if (dev_priv->vram->sysram_tiling_ok(res))
140 ret = pscnv_sysram_alloc(res);
141 else
142 ret = -EINVAL;
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
143 break;
144 default:
145 ret = -ENOSYS;
146 }
147 if (ret) {
148 kfree(res);
149 return 0;
150 }
151 return res;
152 }
153
154 int
155 pscnv_mem_free(struct pscnv_bo *bo)
156 {
157 struct drm_nouveau_private *dev_priv = bo->dev->dev_private;
158 if (pscnv_mem_debug >= 1)
8a59ccb print more debug info
Alexander Polakov authored
159 NV_INFO(bo->dev, "Freeing %d, %#llx-byte %sBO(%p) of type %08x, tile_flags %x\n", bo->serial, bo->size,
160 (bo->flags & PSCNV_GEM_CONTIG ? "contig " : ""), bo, bo->cookie, bo->tile_flags);
329bdb5 @mlankhorst and finish up on freebsd support, for now
mlankhorst authored
161
8246241 @koriakin vm: Switch to new memory manager.
koriakin authored
162 if (dev_priv->vm_ok && bo->map1)
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
163 pscnv_vspace_unmap_node(bo->map1);
8246241 @koriakin vm: Switch to new memory manager.
koriakin authored
164 if (dev_priv->vm_ok && bo->map3)
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
165 pscnv_vspace_unmap_node(bo->map3);
166 switch (bo->flags & PSCNV_GEM_MEMTYPE_MASK) {
167 case PSCNV_GEM_VRAM_SMALL:
168 case PSCNV_GEM_VRAM_LARGE:
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
169 dev_priv->vram->free(bo);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
170 break;
171 case PSCNV_GEM_SYSRAM_SNOOP:
172 case PSCNV_GEM_SYSRAM_NOSNOOP:
173 pscnv_sysram_free(bo);
174 break;
175 }
176 kfree (bo);
177 return 0;
178 }
f5121a8 @koriakin Add vram abstraction, pscnv_vram.c -> nv50_vram.c
koriakin authored
179
180 int
181 pscnv_vram_free(struct pscnv_bo *bo)
182 {
183 struct drm_nouveau_private *dev_priv = bo->dev->dev_private;
184 mutex_lock(&dev_priv->vram_mutex);
185 pscnv_mm_free(bo->mmnode);
186 mutex_unlock(&dev_priv->vram_mutex);
187 return 0;
188 }
189
190 static void pscnv_vram_takedown_free(struct pscnv_mm_node *node) {
191 struct pscnv_bo *bo = node->tag;
192 NV_ERROR(bo->dev, "BO %d of type %08x still exists at takedown!\n",
193 bo->serial, bo->cookie);
194 pscnv_mem_free(bo);
195 }
196
197 void
198 pscnv_vram_takedown(struct drm_device *dev)
199 {
200 struct drm_nouveau_private *dev_priv = dev->dev_private;
201 pscnv_mm_takedown(dev_priv->vram_mm, pscnv_vram_takedown_free);
202 }
Something went wrong with that request. Please try again.