2010-11-10 14:10:04 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright 2010 Red Hat Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
|
*/
|
2015-01-14 09:57:36 +10:00
|
|
|
#include <subdev/mmu.h>
|
2013-06-11 14:17:25 +02:00
|
|
|
#include <subdev/bar.h>
|
2015-01-14 15:09:19 +10:00
|
|
|
#include <subdev/fb.h>
|
|
|
|
|
#include <subdev/ltc.h>
|
|
|
|
|
#include <subdev/timer.h>
|
2010-11-10 14:10:04 +10:00
|
|
|
|
2015-01-14 15:09:19 +10:00
|
|
|
#include <core/gpuobj.h>
|
|
|
|
|
|
|
|
|
|
struct gf100_mmu_priv {
|
|
|
|
|
struct nvkm_mmu base;
|
2012-07-14 19:09:17 +10:00
|
|
|
};
|
|
|
|
|
|
2013-03-27 22:16:53 +01:00
|
|
|
|
|
|
|
|
/* Map from compressed to corresponding uncompressed storage type.
|
|
|
|
|
* The value 0xff represents an invalid storage type.
|
|
|
|
|
*/
|
2015-01-14 15:09:19 +10:00
|
|
|
const u8 gf100_pte_storage_type_map[256] =
|
2013-03-27 22:16:53 +01:00
|
|
|
{
|
|
|
|
|
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0xff, 0x01, /* 0x00 */
|
|
|
|
|
0x01, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0x11, 0xff, 0xff, 0xff, 0xff, 0xff, 0x11, /* 0x10 */
|
|
|
|
|
0x11, 0x11, 0x11, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x26, 0x27, /* 0x20 */
|
|
|
|
|
0x28, 0x29, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30 */
|
|
|
|
|
0xff, 0xff, 0x26, 0x27, 0x28, 0x29, 0x26, 0x27,
|
|
|
|
|
0x28, 0x29, 0xff, 0xff, 0xff, 0xff, 0x46, 0xff, /* 0x40 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0x46, 0x46, 0x46, 0x46, 0xff, 0xff, 0xff, /* 0x50 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70 */
|
|
|
|
|
0xff, 0xff, 0xff, 0x7b, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0x7b, /* 0x80 */
|
|
|
|
|
0x7b, 0x7b, 0xff, 0x8b, 0x8c, 0x8d, 0x8e, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0x8b, 0x8c, 0x8d, 0x8e, 0xa7, /* 0xa0 */
|
|
|
|
|
0xa8, 0xa9, 0xaa, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa7,
|
|
|
|
|
0xa8, 0xa9, 0xaa, 0xc3, 0xff, 0xff, 0xff, 0xff, /* 0xc0 */
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xc3, 0xc3,
|
|
|
|
|
0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0 */
|
|
|
|
|
0xfe, 0xff, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
|
|
|
|
|
0xfe, 0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, /* 0xe0 */
|
|
|
|
|
0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xfe, 0xff,
|
|
|
|
|
0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf0 */
|
|
|
|
|
0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xfd, 0xfe, 0xff
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 23:00:00 +02:00
|
|
|
static void
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_map_pgt(struct nvkm_gpuobj *pgd, u32 index, struct nvkm_gpuobj *pgt[2])
|
2010-11-10 14:10:04 +10:00
|
|
|
{
|
|
|
|
|
u32 pde[2] = { 0, 0 };
|
|
|
|
|
|
|
|
|
|
if (pgt[0])
|
2012-07-14 19:09:17 +10:00
|
|
|
pde[1] = 0x00000001 | (pgt[0]->addr >> 8);
|
2010-11-10 14:10:04 +10:00
|
|
|
if (pgt[1])
|
2012-07-14 19:09:17 +10:00
|
|
|
pde[0] = 0x00000001 | (pgt[1]->addr >> 8);
|
2010-11-10 14:10:04 +10:00
|
|
|
|
|
|
|
|
nv_wo32(pgd, (index * 8) + 0, pde[0]);
|
|
|
|
|
nv_wo32(pgd, (index * 8) + 4, pde[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u64
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_addr(struct nvkm_vma *vma, u64 phys, u32 memtype, u32 target)
|
2010-11-10 14:10:04 +10:00
|
|
|
{
|
|
|
|
|
phys >>= 8;
|
|
|
|
|
|
|
|
|
|
phys |= 0x00000001; /* present */
|
2011-01-14 10:27:02 +10:00
|
|
|
if (vma->access & NV_MEM_ACCESS_SYS)
|
|
|
|
|
phys |= 0x00000002;
|
2010-11-10 14:10:04 +10:00
|
|
|
|
|
|
|
|
phys |= ((u64)target << 32);
|
|
|
|
|
phys |= ((u64)memtype << 36);
|
|
|
|
|
return phys;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 23:00:00 +02:00
|
|
|
static void
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_map(struct nvkm_vma *vma, struct nvkm_gpuobj *pgt,
|
|
|
|
|
struct nvkm_mem *mem, u32 pte, u32 cnt, u64 phys, u64 delta)
|
2010-11-10 14:10:04 +10:00
|
|
|
{
|
2013-03-27 22:16:53 +01:00
|
|
|
u64 next = 1 << (vma->node->type - 8);
|
2010-11-10 14:10:04 +10:00
|
|
|
|
2015-01-14 15:09:19 +10:00
|
|
|
phys = gf100_vm_addr(vma, phys, mem->memtype, 0);
|
2010-11-10 14:10:04 +10:00
|
|
|
pte <<= 3;
|
2013-03-27 22:16:53 +01:00
|
|
|
|
|
|
|
|
if (mem->tag) {
|
2015-01-14 15:09:19 +10:00
|
|
|
struct nvkm_ltc *ltc = nvkm_ltc(vma->vm->mmu);
|
2013-03-27 22:16:53 +01:00
|
|
|
u32 tag = mem->tag->offset + (delta >> 17);
|
|
|
|
|
phys |= (u64)tag << (32 + 12);
|
|
|
|
|
next |= (u64)1 << (32 + 12);
|
2014-08-10 04:10:28 +10:00
|
|
|
ltc->tags_clear(ltc, tag, cnt);
|
2013-03-27 22:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-10 14:10:04 +10:00
|
|
|
while (cnt--) {
|
|
|
|
|
nv_wo32(pgt, pte + 0, lower_32_bits(phys));
|
|
|
|
|
nv_wo32(pgt, pte + 4, upper_32_bits(phys));
|
|
|
|
|
phys += next;
|
|
|
|
|
pte += 8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 23:00:00 +02:00
|
|
|
static void
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_map_sg(struct nvkm_vma *vma, struct nvkm_gpuobj *pgt,
|
|
|
|
|
struct nvkm_mem *mem, u32 pte, u32 cnt, dma_addr_t *list)
|
2010-11-10 14:10:04 +10:00
|
|
|
{
|
2012-01-12 15:34:54 +10:00
|
|
|
u32 target = (vma->access & NV_MEM_ACCESS_NOSNOOP) ? 7 : 5;
|
2013-03-27 22:16:53 +01:00
|
|
|
/* compressed storage types are invalid for system memory */
|
2015-01-14 15:09:19 +10:00
|
|
|
u32 memtype = gf100_pte_storage_type_map[mem->memtype & 0xff];
|
2012-01-12 15:34:54 +10:00
|
|
|
|
2010-11-10 14:10:04 +10:00
|
|
|
pte <<= 3;
|
|
|
|
|
while (cnt--) {
|
2015-01-14 15:09:19 +10:00
|
|
|
u64 phys = gf100_vm_addr(vma, *list++, memtype, target);
|
2010-11-10 14:10:04 +10:00
|
|
|
nv_wo32(pgt, pte + 0, lower_32_bits(phys));
|
|
|
|
|
nv_wo32(pgt, pte + 4, upper_32_bits(phys));
|
|
|
|
|
pte += 8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 23:00:00 +02:00
|
|
|
static void
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_unmap(struct nvkm_gpuobj *pgt, u32 pte, u32 cnt)
|
2010-11-10 14:10:04 +10:00
|
|
|
{
|
|
|
|
|
pte <<= 3;
|
|
|
|
|
while (cnt--) {
|
|
|
|
|
nv_wo32(pgt, pte + 0, 0x00000000);
|
|
|
|
|
nv_wo32(pgt, pte + 4, 0x00000000);
|
|
|
|
|
pte += 8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 23:00:00 +02:00
|
|
|
static void
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_flush(struct nvkm_vm *vm)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:09:19 +10:00
|
|
|
struct gf100_mmu_priv *priv = (void *)vm->mmu;
|
|
|
|
|
struct nvkm_bar *bar = nvkm_bar(priv);
|
|
|
|
|
struct nvkm_vm_pgd *vpgd;
|
2013-05-13 22:07:16 +10:00
|
|
|
u32 type;
|
2010-11-10 14:10:04 +10:00
|
|
|
|
2013-06-11 14:17:25 +02:00
|
|
|
bar->flush(bar);
|
|
|
|
|
|
2013-05-13 22:07:16 +10:00
|
|
|
type = 0x00000001; /* PAGE_ALL */
|
|
|
|
|
if (atomic_read(&vm->engref[NVDEV_SUBDEV_BAR]))
|
|
|
|
|
type |= 0x00000004; /* HUB_ONLY */
|
|
|
|
|
|
|
|
|
|
mutex_lock(&nv_subdev(priv)->mutex);
|
2010-11-10 14:10:04 +10:00
|
|
|
list_for_each_entry(vpgd, &vm->pgd_list, head) {
|
2013-05-13 22:07:16 +10:00
|
|
|
/* looks like maybe a "free flush slots" counter, the
|
|
|
|
|
* faster you write to 0x100cbc to more it decreases
|
|
|
|
|
*/
|
|
|
|
|
if (!nv_wait_ne(priv, 0x100c80, 0x00ff0000, 0x00000000)) {
|
|
|
|
|
nv_error(priv, "vm timeout 0: 0x%08x %d\n",
|
|
|
|
|
nv_rd32(priv, 0x100c80), type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nv_wr32(priv, 0x100cb8, vpgd->obj->addr >> 8);
|
|
|
|
|
nv_wr32(priv, 0x100cbc, 0x80000000 | type);
|
|
|
|
|
|
|
|
|
|
/* wait for flush to be queued? */
|
|
|
|
|
if (!nv_wait(priv, 0x100c80, 0x00008000, 0x00008000)) {
|
|
|
|
|
nv_error(priv, "vm timeout 1: 0x%08x %d\n",
|
|
|
|
|
nv_rd32(priv, 0x100c80), type);
|
|
|
|
|
}
|
2010-11-10 14:10:04 +10:00
|
|
|
}
|
2013-05-13 22:07:16 +10:00
|
|
|
mutex_unlock(&nv_subdev(priv)->mutex);
|
2010-11-10 14:10:04 +10:00
|
|
|
}
|
2012-07-14 19:09:17 +10:00
|
|
|
|
|
|
|
|
static int
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_vm_create(struct nvkm_mmu *mmu, u64 offset, u64 length, u64 mm_offset,
|
|
|
|
|
struct nvkm_vm **pvm)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:09:19 +10:00
|
|
|
return nvkm_vm_create(mmu, offset, length, mm_offset, 4096, pvm);
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2015-01-14 15:09:19 +10:00
|
|
|
gf100_mmu_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
|
struct nvkm_oclass *oclass, void *data, u32 size,
|
|
|
|
|
struct nvkm_object **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:09:19 +10:00
|
|
|
struct gf100_mmu_priv *priv;
|
2012-07-14 19:09:17 +10:00
|
|
|
int ret;
|
|
|
|
|
|
2015-01-14 15:09:19 +10:00
|
|
|
ret = nvkm_mmu_create(parent, engine, oclass, "VM", "vm", &priv);
|
2012-07-14 19:09:17 +10:00
|
|
|
*pobject = nv_object(priv);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2012-07-20 08:17:34 +10:00
|
|
|
priv->base.limit = 1ULL << 40;
|
2012-09-26 14:37:51 +10:00
|
|
|
priv->base.dma_bits = 40;
|
2012-07-14 19:09:17 +10:00
|
|
|
priv->base.pgt_bits = 27 - 12;
|
|
|
|
|
priv->base.spg_shift = 12;
|
|
|
|
|
priv->base.lpg_shift = 17;
|
2015-01-14 15:09:19 +10:00
|
|
|
priv->base.create = gf100_vm_create;
|
|
|
|
|
priv->base.map_pgt = gf100_vm_map_pgt;
|
|
|
|
|
priv->base.map = gf100_vm_map;
|
|
|
|
|
priv->base.map_sg = gf100_vm_map_sg;
|
|
|
|
|
priv->base.unmap = gf100_vm_unmap;
|
|
|
|
|
priv->base.flush = gf100_vm_flush;
|
2012-07-14 19:09:17 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-14 15:09:19 +10:00
|
|
|
struct nvkm_oclass
|
|
|
|
|
gf100_mmu_oclass = {
|
2015-01-14 09:57:36 +10:00
|
|
|
.handle = NV_SUBDEV(MMU, 0xc0),
|
2015-01-14 15:09:19 +10:00
|
|
|
.ofuncs = &(struct nvkm_ofuncs) {
|
|
|
|
|
.ctor = gf100_mmu_ctor,
|
|
|
|
|
.dtor = _nvkm_mmu_dtor,
|
|
|
|
|
.init = _nvkm_mmu_init,
|
|
|
|
|
.fini = _nvkm_mmu_fini,
|
2012-07-14 19:09:17 +10:00
|
|
|
},
|
|
|
|
|
};
|