2 * Copyright 2017 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.
24 #include <nvif/if000d.h>
25 #include <nvif/unpack.h>
28 nv04_vmm_pgt_pte(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
29 u32 ptei, u32 ptes, struct nvkm_vmm_map *map, u64 addr)
31 u32 data = addr | 0x00000003; /* PRESENT, RW. */
33 VMM_WO032(pt, vmm, 8 + ptei++ * 4, data);
39 nv04_vmm_pgt_sgl(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
40 u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
42 VMM_MAP_ITER_SGL(vmm, pt, ptei, ptes, map, nv04_vmm_pgt_pte);
46 nv04_vmm_pgt_dma(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
47 u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
50 nvkm_kmap(pt->memory);
52 VMM_WO032(pt, vmm, 8 + (ptei++ * 4), *map->dma++ | 0x00000003);
53 nvkm_done(pt->memory);
55 VMM_MAP_ITER_DMA(vmm, pt, ptei, ptes, map, nv04_vmm_pgt_pte);
60 nv04_vmm_pgt_unmap(struct nvkm_vmm *vmm,
61 struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
63 VMM_FO032(pt, vmm, 8 + (ptei * 4), 0, ptes);
66 static const struct nvkm_vmm_desc_func
68 .unmap = nv04_vmm_pgt_unmap,
69 .dma = nv04_vmm_pgt_dma,
70 .sgl = nv04_vmm_pgt_sgl,
73 static const struct nvkm_vmm_desc
74 nv04_vmm_desc_12[] = {
75 { PGT, 15, 4, 0x1000, &nv04_vmm_desc_pgt },
80 nv04_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
81 struct nvkm_vmm_map *map)
84 struct nv04_vmm_map_vn vn;
87 if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
88 VMM_DEBUG(vmm, "args");
92 static const struct nvkm_vmm_func
94 .valid = nv04_vmm_valid,
96 { 12, &nv04_vmm_desc_12[0], NVKM_VMM_PAGE_HOST },
102 nv04_vmm_new_(const struct nvkm_vmm_func *func, struct nvkm_mmu *mmu,
103 u32 pd_header, bool managed, u64 addr, u64 size,
104 void *argv, u32 argc, struct lock_class_key *key,
105 const char *name, struct nvkm_vmm **pvmm)
108 struct nv04_vmm_vn vn;
112 ret = nvkm_vmm_new_(func, mmu, pd_header, managed, addr, size,
117 return nvif_unvers(-ENOSYS, &argv, &argc, args->vn);
121 nv04_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
122 void *argv, u32 argc, struct lock_class_key *key, const char *name,
123 struct nvkm_vmm **pvmm)
125 struct nvkm_memory *mem;
126 struct nvkm_vmm *vmm;
129 ret = nv04_vmm_new_(&nv04_vmm, mmu, 8, managed, addr, size,
130 argv, argc, key, name, &vmm);
135 mem = vmm->pd->pt[0]->memory;
137 nvkm_wo32(mem, 0x00000, 0x0002103d); /* PCI, RW, PT, !LN */
138 nvkm_wo32(mem, 0x00004, vmm->limit - 1);