]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/nouveau/nvkm/subdev/mmu/nv44.c
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/option.h>
27 #include <subdev/timer.h>
29 #include <nvif/class.h>
31 #define NV44_GART_SIZE (512 * 1024 * 1024)
32 #define NV44_GART_PAGE ( 4 * 1024)
34 /*******************************************************************************
35 * VM map/unmap callbacks
36 ******************************************************************************/
39 nv44_vm_fill(struct nvkm_memory
*pgt
, dma_addr_t null
,
40 dma_addr_t
*list
, u32 pte
, u32 cnt
)
42 u32 base
= (pte
<< 2) & ~0x0000000f;
45 tmp
[0] = nvkm_ro32(pgt
, base
+ 0x0);
46 tmp
[1] = nvkm_ro32(pgt
, base
+ 0x4);
47 tmp
[2] = nvkm_ro32(pgt
, base
+ 0x8);
48 tmp
[3] = nvkm_ro32(pgt
, base
+ 0xc);
51 u32 addr
= list
? (*list
++ >> 12) : (null
>> 12);
52 switch (pte
++ & 0x3) {
54 tmp
[0] &= ~0x07ffffff;
58 tmp
[0] &= ~0xf8000000;
60 tmp
[1] &= ~0x003fffff;
64 tmp
[1] &= ~0xffc00000;
66 tmp
[2] &= ~0x0001ffff;
70 tmp
[2] &= ~0xfffe0000;
72 tmp
[3] &= ~0x00000fff;
78 nvkm_wo32(pgt
, base
+ 0x0, tmp
[0]);
79 nvkm_wo32(pgt
, base
+ 0x4, tmp
[1]);
80 nvkm_wo32(pgt
, base
+ 0x8, tmp
[2]);
81 nvkm_wo32(pgt
, base
+ 0xc, tmp
[3] | 0x40000000);
85 nv44_vm_map_sg(struct nvkm_vma
*vma
, struct nvkm_memory
*pgt
,
86 struct nvkm_mem
*mem
, u32 pte
, u32 cnt
, dma_addr_t
*list
)
93 u32 max
= 4 - (pte
& 3);
94 u32 part
= (cnt
> max
) ? max
: cnt
;
95 nv44_vm_fill(pgt
, vma
->vm
->null
, list
, pte
, part
);
102 for (i
= 0; i
< 4; i
++)
103 tmp
[i
] = *list
++ >> 12;
104 nvkm_wo32(pgt
, pte
++ * 4, tmp
[0] >> 0 | tmp
[1] << 27);
105 nvkm_wo32(pgt
, pte
++ * 4, tmp
[1] >> 5 | tmp
[2] << 22);
106 nvkm_wo32(pgt
, pte
++ * 4, tmp
[2] >> 10 | tmp
[3] << 17);
107 nvkm_wo32(pgt
, pte
++ * 4, tmp
[3] >> 15 | 0x40000000);
112 nv44_vm_fill(pgt
, vma
->vm
->null
, list
, pte
, cnt
);
117 nv44_vm_unmap(struct nvkm_vma
*vma
, struct nvkm_memory
*pgt
, u32 pte
, u32 cnt
)
121 u32 max
= 4 - (pte
& 3);
122 u32 part
= (cnt
> max
) ? max
: cnt
;
123 nv44_vm_fill(pgt
, vma
->vm
->null
, NULL
, pte
, part
);
129 nvkm_wo32(pgt
, pte
++ * 4, 0x00000000);
130 nvkm_wo32(pgt
, pte
++ * 4, 0x00000000);
131 nvkm_wo32(pgt
, pte
++ * 4, 0x00000000);
132 nvkm_wo32(pgt
, pte
++ * 4, 0x00000000);
137 nv44_vm_fill(pgt
, vma
->vm
->null
, NULL
, pte
, cnt
);
142 nv44_vm_flush(struct nvkm_vm
*vm
)
144 struct nvkm_device
*device
= vm
->mmu
->subdev
.device
;
145 nvkm_wr32(device
, 0x100814, vm
->mmu
->limit
- NV44_GART_PAGE
);
146 nvkm_wr32(device
, 0x100808, 0x00000020);
147 nvkm_msec(device
, 2000,
148 if (nvkm_rd32(device
, 0x100808) & 0x00000001)
151 nvkm_wr32(device
, 0x100808, 0x00000000);
154 /*******************************************************************************
156 ******************************************************************************/
159 nv44_mmu_oneinit(struct nvkm_mmu
*mmu
)
161 mmu
->vmm
->pgt
[0].mem
[0] = mmu
->vmm
->pd
->pt
[0]->memory
;
162 mmu
->vmm
->pgt
[0].refcount
[0] = 1;
167 nv44_mmu_init(struct nvkm_mmu
*mmu
)
169 struct nvkm_device
*device
= mmu
->subdev
.device
;
170 struct nvkm_memory
*gart
= mmu
->vmm
->pgt
[0].mem
[0];
173 /* calculate vram address of this PRAMIN block, object must be
174 * allocated on 512KiB alignment, and not exceed a total size
175 * of 512KiB for this to work correctly
177 addr
= nvkm_rd32(device
, 0x10020c);
178 addr
-= ((nvkm_memory_addr(gart
) >> 19) + 1) << 19;
180 nvkm_wr32(device
, 0x100850, 0x80000000);
181 nvkm_wr32(device
, 0x100818, mmu
->vmm
->null
);
182 nvkm_wr32(device
, 0x100804, NV44_GART_SIZE
);
183 nvkm_wr32(device
, 0x100850, 0x00008000);
184 nvkm_mask(device
, 0x10008c, 0x00000200, 0x00000200);
185 nvkm_wr32(device
, 0x100820, 0x00000000);
186 nvkm_wr32(device
, 0x10082c, 0x00000001);
187 nvkm_wr32(device
, 0x100800, addr
| 0x00000010);
190 static const struct nvkm_mmu_func
192 .oneinit
= nv44_mmu_oneinit
,
193 .init
= nv44_mmu_init
,
194 .limit
= NV44_GART_SIZE
,
199 .map_sg
= nv44_vm_map_sg
,
200 .unmap
= nv44_vm_unmap
,
201 .flush
= nv44_vm_flush
,
202 .vmm
= {{ -1, -1, NVIF_CLASS_VMM_NV04
}, nv44_vmm_new
, true },
206 nv44_mmu_new(struct nvkm_device
*device
, int index
, struct nvkm_mmu
**pmmu
)
208 if (device
->type
== NVKM_DEVICE_AGP
||
209 !nvkm_boolopt(device
->cfgopt
, "NvPCIE", true))
210 return nv04_mmu_new(device
, index
, pmmu
);
212 return nvkm_mmu_new_(&nv44_mmu
, device
, index
, pmmu
);