2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <core/device.h>
27 #include <core/gpuobj.h>
28 #include <subdev/fb.h>
29 #include <subdev/mmu.h>
30 #include <subdev/timer.h>
32 struct nv50_bar_priv {
35 struct nvkm_gpuobj *mem;
36 struct nvkm_gpuobj *pad;
37 struct nvkm_gpuobj *pgd;
38 struct nvkm_vm *bar1_vm;
39 struct nvkm_gpuobj *bar1;
40 struct nvkm_vm *bar3_vm;
41 struct nvkm_gpuobj *bar3;
45 nv50_bar_kmap(struct nvkm_bar *bar, struct nvkm_mem *mem, u32 flags,
48 struct nv50_bar_priv *priv = (void *)bar;
51 ret = nvkm_vm_get(priv->bar3_vm, mem->size << 12, 12, flags, vma);
55 nvkm_vm_map(vma, mem);
60 nv50_bar_umap(struct nvkm_bar *bar, struct nvkm_mem *mem, u32 flags,
63 struct nv50_bar_priv *priv = (void *)bar;
66 ret = nvkm_vm_get(priv->bar1_vm, mem->size << 12, 12, flags, vma);
70 nvkm_vm_map(vma, mem);
75 nv50_bar_unmap(struct nvkm_bar *bar, struct nvkm_vma *vma)
82 nv50_bar_flush(struct nvkm_bar *bar)
84 struct nv50_bar_priv *priv = (void *)bar;
86 spin_lock_irqsave(&priv->lock, flags);
87 nv_wr32(priv, 0x00330c, 0x00000001);
88 if (!nv_wait(priv, 0x00330c, 0x00000002, 0x00000000))
89 nv_warn(priv, "flush timeout\n");
90 spin_unlock_irqrestore(&priv->lock, flags);
94 g84_bar_flush(struct nvkm_bar *bar)
96 struct nv50_bar_priv *priv = (void *)bar;
98 spin_lock_irqsave(&priv->lock, flags);
99 nv_wr32(bar, 0x070000, 0x00000001);
100 if (!nv_wait(priv, 0x070000, 0x00000002, 0x00000000))
101 nv_warn(priv, "flush timeout\n");
102 spin_unlock_irqrestore(&priv->lock, flags);
106 nv50_bar_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
107 struct nvkm_oclass *oclass, void *data, u32 size,
108 struct nvkm_object **pobject)
110 struct nvkm_device *device = nv_device(parent);
111 struct nvkm_object *heap;
113 struct nv50_bar_priv *priv;
117 ret = nvkm_bar_create(parent, engine, oclass, &priv);
118 *pobject = nv_object(priv);
122 ret = nvkm_gpuobj_new(nv_object(priv), NULL, 0x20000, 0,
123 NVOBJ_FLAG_HEAP, &priv->mem);
124 heap = nv_object(priv->mem);
128 ret = nvkm_gpuobj_new(nv_object(priv), heap,
129 (device->chipset == 0x50) ? 0x1400 : 0x0200,
134 ret = nvkm_gpuobj_new(nv_object(priv), heap, 0x4000, 0, 0, &priv->pgd);
139 start = 0x0100000000ULL;
140 limit = start + nv_device_resource_len(device, 3);
142 ret = nvkm_vm_new(device, start, limit, start, &vm);
146 atomic_inc(&vm->engref[NVDEV_SUBDEV_BAR]);
148 ret = nvkm_gpuobj_new(nv_object(priv), heap,
149 ((limit-- - start) >> 12) * 8, 0x1000,
150 NVOBJ_FLAG_ZERO_ALLOC, &vm->pgt[0].obj[0]);
151 vm->pgt[0].refcount[0] = 1;
155 ret = nvkm_vm_ref(vm, &priv->bar3_vm, priv->pgd);
156 nvkm_vm_ref(NULL, &vm, NULL);
160 ret = nvkm_gpuobj_new(nv_object(priv), heap, 24, 16, 0, &priv->bar3);
164 nv_wo32(priv->bar3, 0x00, 0x7fc00000);
165 nv_wo32(priv->bar3, 0x04, lower_32_bits(limit));
166 nv_wo32(priv->bar3, 0x08, lower_32_bits(start));
167 nv_wo32(priv->bar3, 0x0c, upper_32_bits(limit) << 24 |
168 upper_32_bits(start));
169 nv_wo32(priv->bar3, 0x10, 0x00000000);
170 nv_wo32(priv->bar3, 0x14, 0x00000000);
173 start = 0x0000000000ULL;
174 limit = start + nv_device_resource_len(device, 1);
176 ret = nvkm_vm_new(device, start, limit--, start, &vm);
180 atomic_inc(&vm->engref[NVDEV_SUBDEV_BAR]);
182 ret = nvkm_vm_ref(vm, &priv->bar1_vm, priv->pgd);
183 nvkm_vm_ref(NULL, &vm, NULL);
187 ret = nvkm_gpuobj_new(nv_object(priv), heap, 24, 16, 0, &priv->bar1);
191 nv_wo32(priv->bar1, 0x00, 0x7fc00000);
192 nv_wo32(priv->bar1, 0x04, lower_32_bits(limit));
193 nv_wo32(priv->bar1, 0x08, lower_32_bits(start));
194 nv_wo32(priv->bar1, 0x0c, upper_32_bits(limit) << 24 |
195 upper_32_bits(start));
196 nv_wo32(priv->bar1, 0x10, 0x00000000);
197 nv_wo32(priv->bar1, 0x14, 0x00000000);
199 priv->base.alloc = nvkm_bar_alloc;
200 priv->base.kmap = nv50_bar_kmap;
201 priv->base.umap = nv50_bar_umap;
202 priv->base.unmap = nv50_bar_unmap;
203 if (device->chipset == 0x50)
204 priv->base.flush = nv50_bar_flush;
206 priv->base.flush = g84_bar_flush;
207 spin_lock_init(&priv->lock);
212 nv50_bar_dtor(struct nvkm_object *object)
214 struct nv50_bar_priv *priv = (void *)object;
215 nvkm_gpuobj_ref(NULL, &priv->bar1);
216 nvkm_vm_ref(NULL, &priv->bar1_vm, priv->pgd);
217 nvkm_gpuobj_ref(NULL, &priv->bar3);
219 nvkm_gpuobj_ref(NULL, &priv->bar3_vm->pgt[0].obj[0]);
220 nvkm_vm_ref(NULL, &priv->bar3_vm, priv->pgd);
222 nvkm_gpuobj_ref(NULL, &priv->pgd);
223 nvkm_gpuobj_ref(NULL, &priv->pad);
224 nvkm_gpuobj_ref(NULL, &priv->mem);
225 nvkm_bar_destroy(&priv->base);
229 nv50_bar_init(struct nvkm_object *object)
231 struct nv50_bar_priv *priv = (void *)object;
234 ret = nvkm_bar_init(&priv->base);
238 nv_mask(priv, 0x000200, 0x00000100, 0x00000000);
239 nv_mask(priv, 0x000200, 0x00000100, 0x00000100);
240 nv_wr32(priv, 0x100c80, 0x00060001);
241 if (!nv_wait(priv, 0x100c80, 0x00000001, 0x00000000)) {
242 nv_error(priv, "vm flush timeout\n");
246 nv_wr32(priv, 0x001704, 0x00000000 | priv->mem->addr >> 12);
247 nv_wr32(priv, 0x001704, 0x40000000 | priv->mem->addr >> 12);
248 nv_wr32(priv, 0x001708, 0x80000000 | priv->bar1->node->offset >> 4);
249 nv_wr32(priv, 0x00170c, 0x80000000 | priv->bar3->node->offset >> 4);
250 for (i = 0; i < 8; i++)
251 nv_wr32(priv, 0x001900 + (i * 4), 0x00000000);
256 nv50_bar_fini(struct nvkm_object *object, bool suspend)
258 struct nv50_bar_priv *priv = (void *)object;
259 return nvkm_bar_fini(&priv->base, suspend);
264 .handle = NV_SUBDEV(BAR, 0x50),
265 .ofuncs = &(struct nvkm_ofuncs) {
266 .ctor = nv50_bar_ctor,
267 .dtor = nv50_bar_dtor,
268 .init = nv50_bar_init,
269 .fini = nv50_bar_fini,