forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c
....@@ -178,15 +178,19 @@
178178 };
179179
180180 void
181
-gf100_vmm_flush_(struct nvkm_vmm *vmm, int depth)
181
+gf100_vmm_invalidate_pdb(struct nvkm_vmm *vmm, u64 addr)
182
+{
183
+ struct nvkm_device *device = vmm->mmu->subdev.device;
184
+ nvkm_wr32(device, 0x100cb8, addr);
185
+}
186
+
187
+void
188
+gf100_vmm_invalidate(struct nvkm_vmm *vmm, u32 type)
182189 {
183190 struct nvkm_subdev *subdev = &vmm->mmu->subdev;
184191 struct nvkm_device *device = subdev->device;
185
- u32 type = depth << 24;
186
-
187
- type = 0x00000001; /* PAGE_ALL */
188
- if (atomic_read(&vmm->engref[NVKM_SUBDEV_BAR]))
189
- type |= 0x00000004; /* HUB_ONLY */
192
+ struct nvkm_mmu_pt *pd = vmm->pd->pt[0];
193
+ u64 addr = 0;
190194
191195 mutex_lock(&subdev->mutex);
192196 /* Looks like maybe a "free flush slots" counter, the
....@@ -197,7 +201,20 @@
197201 break;
198202 );
199203
200
- nvkm_wr32(device, 0x100cb8, vmm->pd->pt[0]->addr >> 8);
204
+ if (!(type & 0x00000002) /* ALL_PDB. */) {
205
+ switch (nvkm_memory_target(pd->memory)) {
206
+ case NVKM_MEM_TARGET_VRAM: addr |= 0x00000000; break;
207
+ case NVKM_MEM_TARGET_HOST: addr |= 0x00000002; break;
208
+ case NVKM_MEM_TARGET_NCOH: addr |= 0x00000003; break;
209
+ default:
210
+ WARN_ON(1);
211
+ break;
212
+ }
213
+ addr |= (vmm->pd->pt[0]->addr >> 12) << 4;
214
+
215
+ vmm->func->invalidate_pdb(vmm, addr);
216
+ }
217
+
201218 nvkm_wr32(device, 0x100cbc, 0x80000000 | type);
202219
203220 /* Wait for flush to be queued? */
....@@ -211,7 +228,10 @@
211228 void
212229 gf100_vmm_flush(struct nvkm_vmm *vmm, int depth)
213230 {
214
- gf100_vmm_flush_(vmm, 0);
231
+ u32 type = 0x00000001; /* PAGE_ALL */
232
+ if (atomic_read(&vmm->engref[NVKM_SUBDEV_BAR]))
233
+ type |= 0x00000004; /* HUB_ONLY */
234
+ gf100_vmm_invalidate(vmm, type);
215235 }
216236
217237 int
....@@ -227,7 +247,7 @@
227247 } *args = argv;
228248 struct nvkm_device *device = vmm->mmu->subdev.device;
229249 struct nvkm_memory *memory = map->memory;
230
- u8 kind, priv, ro, vol;
250
+ u8 kind, kind_inv, priv, ro, vol;
231251 int kindn, aper, ret = -ENOSYS;
232252 const u8 *kindm;
233253
....@@ -254,8 +274,8 @@
254274 if (WARN_ON(aper < 0))
255275 return aper;
256276
257
- kindm = vmm->mmu->func->kind(vmm->mmu, &kindn);
258
- if (kind >= kindn || kindm[kind] == 0xff) {
277
+ kindm = vmm->mmu->func->kind(vmm->mmu, &kindn, &kind_inv);
278
+ if (kind >= kindn || kindm[kind] == kind_inv) {
259279 VMM_DEBUG(vmm, "kind %02x", kind);
260280 return -EINVAL;
261281 }
....@@ -354,6 +374,7 @@
354374 .aper = gf100_vmm_aper,
355375 .valid = gf100_vmm_valid,
356376 .flush = gf100_vmm_flush,
377
+ .invalidate_pdb = gf100_vmm_invalidate_pdb,
357378 .page = {
358379 { 17, &gf100_vmm_desc_17_17[0], NVKM_VMM_PAGE_xVxC },
359380 { 12, &gf100_vmm_desc_17_12[0], NVKM_VMM_PAGE_xVHx },
....@@ -368,6 +389,7 @@
368389 .aper = gf100_vmm_aper,
369390 .valid = gf100_vmm_valid,
370391 .flush = gf100_vmm_flush,
392
+ .invalidate_pdb = gf100_vmm_invalidate_pdb,
371393 .page = {
372394 { 16, &gf100_vmm_desc_16_16[0], NVKM_VMM_PAGE_xVxC },
373395 { 12, &gf100_vmm_desc_16_12[0], NVKM_VMM_PAGE_xVHx },
....@@ -378,14 +400,14 @@
378400 int
379401 gf100_vmm_new_(const struct nvkm_vmm_func *func_16,
380402 const struct nvkm_vmm_func *func_17,
381
- struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
382
- struct lock_class_key *key, const char *name,
383
- struct nvkm_vmm **pvmm)
403
+ struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
404
+ void *argv, u32 argc, struct lock_class_key *key,
405
+ const char *name, struct nvkm_vmm **pvmm)
384406 {
385407 switch (mmu->subdev.device->fb->page) {
386
- case 16: return nv04_vmm_new_(func_16, mmu, 0, addr, size,
408
+ case 16: return nv04_vmm_new_(func_16, mmu, 0, managed, addr, size,
387409 argv, argc, key, name, pvmm);
388
- case 17: return nv04_vmm_new_(func_17, mmu, 0, addr, size,
410
+ case 17: return nv04_vmm_new_(func_17, mmu, 0, managed, addr, size,
389411 argv, argc, key, name, pvmm);
390412 default:
391413 WARN_ON(1);
....@@ -394,10 +416,10 @@
394416 }
395417
396418 int
397
-gf100_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
398
- struct lock_class_key *key, const char *name,
399
- struct nvkm_vmm **pvmm)
419
+gf100_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
420
+ void *argv, u32 argc, struct lock_class_key *key,
421
+ const char *name, struct nvkm_vmm **pvmm)
400422 {
401
- return gf100_vmm_new_(&gf100_vmm_16, &gf100_vmm_17, mmu, addr,
423
+ return gf100_vmm_new_(&gf100_vmm_16, &gf100_vmm_17, mmu, managed, addr,
402424 size, argv, argc, key, name, pvmm);
403425 }