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.
25 #include <core/gpuobj.h>
27 #include <subdev/timer.h>
28 #include <subdev/fb.h>
29 #include <subdev/vm.h>
33 struct nvc0_bar_priv {
34 struct nouveau_bar base;
37 struct nouveau_gpuobj *mem;
38 struct nouveau_gpuobj *pgd;
39 struct nouveau_vm *vm;
44 nvc0_bar_kmap(struct nouveau_bar *bar, struct nouveau_mem *mem,
45 u32 flags, struct nouveau_vma *vma)
47 struct nvc0_bar_priv *priv = (void *)bar;
50 ret = nouveau_vm_get(priv->bar[0].vm, mem->size << 12, 12, flags, vma);
54 nouveau_vm_map(vma, mem);
59 nvc0_bar_umap(struct nouveau_bar *bar, struct nouveau_mem *mem,
60 u32 flags, struct nouveau_vma *vma)
62 struct nvc0_bar_priv *priv = (void *)bar;
65 ret = nouveau_vm_get(priv->bar[1].vm, mem->size << 12,
66 mem->page_shift, flags, vma);
70 nouveau_vm_map(vma, mem);
75 nvc0_bar_unmap(struct nouveau_bar *bar, struct nouveau_vma *vma)
77 nouveau_vm_unmap(vma);
82 nvc0_bar_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
83 struct nouveau_oclass *oclass, void *data, u32 size,
84 struct nouveau_object **pobject)
86 struct nouveau_device *device = nv_device(parent);
87 struct pci_dev *pdev = device->pdev;
88 struct nvc0_bar_priv *priv;
89 struct nouveau_gpuobj *mem;
90 struct nouveau_vm *vm;
93 ret = nouveau_bar_create(parent, engine, oclass, &priv);
94 *pobject = nv_object(priv);
99 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0, 0,
101 mem = priv->bar[0].mem;
105 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x8000, 0, 0,
110 ret = nouveau_vm_new(device, 0, pci_resource_len(pdev, 3), 0, &vm);
114 atomic_inc(&vm->engref[NVDEV_SUBDEV_BAR]);
116 ret = nouveau_gpuobj_new(nv_object(priv), NULL,
117 (pci_resource_len(pdev, 3) >> 12) * 8,
118 0x1000, NVOBJ_FLAG_ZERO_ALLOC,
120 vm->pgt[0].refcount[0] = 1;
124 ret = nouveau_vm_ref(vm, &priv->bar[0].vm, priv->bar[0].pgd);
125 nouveau_vm_ref(NULL, &vm, NULL);
129 nv_wo32(mem, 0x0200, lower_32_bits(priv->bar[0].pgd->addr));
130 nv_wo32(mem, 0x0204, upper_32_bits(priv->bar[0].pgd->addr));
131 nv_wo32(mem, 0x0208, lower_32_bits(pci_resource_len(pdev, 3) - 1));
132 nv_wo32(mem, 0x020c, upper_32_bits(pci_resource_len(pdev, 3) - 1));
135 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0, 0,
137 mem = priv->bar[1].mem;
141 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x8000, 0, 0,
146 ret = nouveau_vm_new(device, 0, pci_resource_len(pdev, 1), 0, &vm);
150 atomic_inc(&vm->engref[NVDEV_SUBDEV_BAR]);
152 ret = nouveau_vm_ref(vm, &priv->bar[1].vm, priv->bar[1].pgd);
153 nouveau_vm_ref(NULL, &vm, NULL);
157 nv_wo32(mem, 0x0200, lower_32_bits(priv->bar[1].pgd->addr));
158 nv_wo32(mem, 0x0204, upper_32_bits(priv->bar[1].pgd->addr));
159 nv_wo32(mem, 0x0208, lower_32_bits(pci_resource_len(pdev, 1) - 1));
160 nv_wo32(mem, 0x020c, upper_32_bits(pci_resource_len(pdev, 1) - 1));
162 priv->base.alloc = nouveau_bar_alloc;
163 priv->base.kmap = nvc0_bar_kmap;
164 priv->base.umap = nvc0_bar_umap;
165 priv->base.unmap = nvc0_bar_unmap;
166 priv->base.flush = nv84_bar_flush;
167 spin_lock_init(&priv->lock);
172 nvc0_bar_dtor(struct nouveau_object *object)
174 struct nvc0_bar_priv *priv = (void *)object;
176 nouveau_vm_ref(NULL, &priv->bar[1].vm, priv->bar[1].pgd);
177 nouveau_gpuobj_ref(NULL, &priv->bar[1].pgd);
178 nouveau_gpuobj_ref(NULL, &priv->bar[1].mem);
180 if (priv->bar[0].vm) {
181 nouveau_gpuobj_ref(NULL, &priv->bar[0].vm->pgt[0].obj[0]);
182 nouveau_vm_ref(NULL, &priv->bar[0].vm, priv->bar[0].pgd);
184 nouveau_gpuobj_ref(NULL, &priv->bar[0].pgd);
185 nouveau_gpuobj_ref(NULL, &priv->bar[0].mem);
187 nouveau_bar_destroy(&priv->base);
191 nvc0_bar_init(struct nouveau_object *object)
193 struct nvc0_bar_priv *priv = (void *)object;
196 ret = nouveau_bar_init(&priv->base);
200 nv_mask(priv, 0x000200, 0x00000100, 0x00000000);
201 nv_mask(priv, 0x000200, 0x00000100, 0x00000100);
202 nv_mask(priv, 0x100c80, 0x00000001, 0x00000000);
204 nv_wr32(priv, 0x001704, 0x80000000 | priv->bar[1].mem->addr >> 12);
205 nv_wr32(priv, 0x001714, 0xc0000000 | priv->bar[0].mem->addr >> 12);
209 struct nouveau_oclass
211 .handle = NV_SUBDEV(BAR, 0xc0),
212 .ofuncs = &(struct nouveau_ofuncs) {
213 .ctor = nvc0_bar_ctor,
214 .dtor = nvc0_bar_dtor,
215 .init = nvc0_bar_init,
216 .fini = _nouveau_bar_fini,