Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2017 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  */
0022 #include "vmm.h"
0023 
0024 #include <nvif/if000d.h>
0025 #include <nvif/unpack.h>
0026 
0027 static inline void
0028 nv04_vmm_pgt_pte(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
0029          u32 ptei, u32 ptes, struct nvkm_vmm_map *map, u64 addr)
0030 {
0031     u32 data = addr | 0x00000003; /* PRESENT, RW. */
0032     while (ptes--) {
0033         VMM_WO032(pt, vmm, 8 + ptei++ * 4, data);
0034         data += 0x00001000;
0035     }
0036 }
0037 
0038 static void
0039 nv04_vmm_pgt_sgl(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
0040          u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
0041 {
0042     VMM_MAP_ITER_SGL(vmm, pt, ptei, ptes, map, nv04_vmm_pgt_pte);
0043 }
0044 
0045 static void
0046 nv04_vmm_pgt_dma(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
0047          u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
0048 {
0049 #if PAGE_SHIFT == 12
0050     nvkm_kmap(pt->memory);
0051     while (ptes--)
0052         VMM_WO032(pt, vmm, 8 + (ptei++ * 4), *map->dma++ | 0x00000003);
0053     nvkm_done(pt->memory);
0054 #else
0055     VMM_MAP_ITER_DMA(vmm, pt, ptei, ptes, map, nv04_vmm_pgt_pte);
0056 #endif
0057 }
0058 
0059 static void
0060 nv04_vmm_pgt_unmap(struct nvkm_vmm *vmm,
0061            struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
0062 {
0063     VMM_FO032(pt, vmm, 8 + (ptei * 4), 0, ptes);
0064 }
0065 
0066 static const struct nvkm_vmm_desc_func
0067 nv04_vmm_desc_pgt = {
0068     .unmap = nv04_vmm_pgt_unmap,
0069     .dma = nv04_vmm_pgt_dma,
0070     .sgl = nv04_vmm_pgt_sgl,
0071 };
0072 
0073 static const struct nvkm_vmm_desc
0074 nv04_vmm_desc_12[] = {
0075     { PGT, 15, 4, 0x1000, &nv04_vmm_desc_pgt },
0076     {}
0077 };
0078 
0079 int
0080 nv04_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
0081            struct nvkm_vmm_map *map)
0082 {
0083     union {
0084         struct nv04_vmm_map_vn vn;
0085     } *args = argv;
0086     int ret = -ENOSYS;
0087     if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
0088         VMM_DEBUG(vmm, "args");
0089     return ret;
0090 }
0091 
0092 static const struct nvkm_vmm_func
0093 nv04_vmm = {
0094     .valid = nv04_vmm_valid,
0095     .page = {
0096         { 12, &nv04_vmm_desc_12[0], NVKM_VMM_PAGE_HOST },
0097         {}
0098     }
0099 };
0100 
0101 int
0102 nv04_vmm_new_(const struct nvkm_vmm_func *func, struct nvkm_mmu *mmu,
0103           u32 pd_header, bool managed, u64 addr, u64 size,
0104           void *argv, u32 argc, struct lock_class_key *key,
0105           const char *name, struct nvkm_vmm **pvmm)
0106 {
0107     union {
0108         struct nv04_vmm_vn vn;
0109     } *args = argv;
0110     int ret;
0111 
0112     ret = nvkm_vmm_new_(func, mmu, pd_header, managed, addr, size,
0113                 key, name, pvmm);
0114     if (ret)
0115         return ret;
0116 
0117     return nvif_unvers(-ENOSYS, &argv, &argc, args->vn);
0118 }
0119 
0120 int
0121 nv04_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
0122          void *argv, u32 argc, struct lock_class_key *key, const char *name,
0123          struct nvkm_vmm **pvmm)
0124 {
0125     struct nvkm_memory *mem;
0126     struct nvkm_vmm *vmm;
0127     int ret;
0128 
0129     ret = nv04_vmm_new_(&nv04_vmm, mmu, 8, managed, addr, size,
0130                 argv, argc, key, name, &vmm);
0131     *pvmm = vmm;
0132     if (ret)
0133         return ret;
0134 
0135     mem = vmm->pd->pt[0]->memory;
0136     nvkm_kmap(mem);
0137     nvkm_wo32(mem, 0x00000, 0x0002103d); /* PCI, RW, PT, !LN */
0138     nvkm_wo32(mem, 0x00004, vmm->limit - 1);
0139     nvkm_done(mem);
0140     return 0;
0141 }