/* * 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
*/ #include"ummu.h" #include"vmm.h"
/* If there were no free slots in the parent allocation before, * there will be now, so return PTP to the cache.
*/ if (!ptp->free)
list_add(&ptp->head, &mmu->ptp.list);
ptp->free |= BIT(slot);
/* If there's no more sub-allocations, destroy PTP. */ if (ptp->free == ptp->mask) {
nvkm_mmu_ptc_put(mmu, force, &ptp->pt);
list_del(&ptp->head);
kfree(ptp);
}
if (!(pt = kzalloc(sizeof(*pt), GFP_KERNEL))) return NULL;
ptp = list_first_entry_or_null(&mmu->ptp.list, typeof(*ptp), head); if (!ptp) { /* Need to allocate a new parent to sub-allocate from. */ if (!(ptp = kmalloc(sizeof(*ptp), GFP_KERNEL))) {
kfree(pt); return NULL;
}
/* Sub-allocate from parent object, removing PTP from cache * if there's no more free slots left.
*/
slot = __ffs(ptp->free);
ptp->free &= ~BIT(slot); if (!ptp->free)
list_del(&ptp->head);
/* Lookup cache for this page table size. */
mutex_lock(&mmu->ptc.mutex);
ptc = nvkm_mmu_ptc_find(mmu, size); if (!ptc) {
mutex_unlock(&mmu->ptc.mutex); return NULL;
}
/* If there's a free PT in the cache, reuse it. */
pt = list_first_entry_or_null(&ptc->item, typeof(*pt), head); if (pt) { if (zero)
nvkm_fo64(pt->memory, 0, 0, size >> 3);
list_del(&pt->head);
ptc->refs--;
mutex_unlock(&mmu->ptc.mutex); return pt;
}
mutex_unlock(&mmu->ptc.mutex);
/* No such luck, we need to allocate. */ if (!(pt = kmalloc(sizeof(*pt), GFP_KERNEL))) return NULL;
pt->ptc = ptc;
pt->sub = false;
ret = nvkm_memory_new(mmu->subdev.device, NVKM_MEM_TARGET_INST,
size, align, zero, &pt->memory); if (ret) {
kfree(pt); return NULL;
}
/* Non-coherent, cached, system memory. * * Block-linear mappings of system memory must be done through * BAR1, and cannot be supported on systems where we're unable * to map BAR1 with write-combining.
*/
type |= NVKM_MEM_MAPPABLE; if (!device->bar || device->bar->iomap_uncached)
nvkm_mmu_type(mmu, heap, type & ~NVKM_MEM_KIND); else
nvkm_mmu_type(mmu, heap, type);
/* Coherent, cached, system memory. * * Unsupported on systems that aren't able to support snooped * mappings, and also for block-linear mappings which must be * done through BAR1.
*/
type |= NVKM_MEM_COHERENT; if (device->func->cpu_coherent)
nvkm_mmu_type(mmu, heap, type & ~NVKM_MEM_KIND);
/* Uncached system memory. */
nvkm_mmu_type(mmu, heap, type |= NVKM_MEM_UNCACHED);
}
/* Add non-mappable VRAM types first so that they're preferred * over anything else. Mixed-memory will be slower than other * heaps, it's prioritised last.
*/
nvkm_mmu_type(mmu, heapU, type);
nvkm_mmu_type(mmu, heapN, type);
nvkm_mmu_type(mmu, heapM, type);
/* Add host memory types next, under the assumption that users * wanting mappable memory want to use them as staging buffers * or the like.
*/
nvkm_mmu_host(mmu);
/* Mappable VRAM types go last, as they're basically the worst * possible type to ask for unless there's no other choice.
*/ if (device->bar) { /* Write-combined BAR1 access. */
type |= NVKM_MEM_MAPPABLE; if (!device->bar->iomap_uncached) {
nvkm_mmu_type(mmu, heapN, type);
nvkm_mmu_type(mmu, heapM, type);
}
/* Uncached BAR1 access. */
type |= NVKM_MEM_COHERENT;
type |= NVKM_MEM_UNCACHED;
nvkm_mmu_type(mmu, heapN, type);
nvkm_mmu_type(mmu, heapM, type);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.