35 #include <linux/wait.h>
36 #include <linux/slab.h>
38 #include <linux/module.h>
46 bool evict,
bool no_wait_reserve,
120 if (!bdev->
driver->io_mem_reserve)
123 return bdev->
driver->io_mem_reserve(bdev, mem);
125 if (bdev->
driver->io_mem_reserve &&
126 mem->
bus.io_reserved_count++ == 0) {
128 ret = bdev->
driver->io_mem_reserve(bdev, mem);
130 ret = ttm_mem_io_evict(man);
146 if (bdev->
driver->io_mem_reserve &&
147 --mem->
bus.io_reserved_count == 0 &&
148 bdev->
driver->io_mem_free)
149 bdev->
driver->io_mem_free(bdev, mem);
158 if (!mem->
bus.io_reserved_vm) {
162 ret = ttm_mem_io_reserve(bo->
bdev, mem);
165 mem->
bus.io_reserved_vm =
true;
177 if (mem->
bus.io_reserved_vm) {
178 mem->
bus.io_reserved_vm =
false;
180 ttm_mem_io_free(bo->
bdev, mem);
193 ret = ttm_mem_io_reserve(bdev, mem);
195 if (ret || !mem->
bus.is_iomem)
199 addr = mem->
bus.addr;
207 ttm_mem_io_free(bdev, mem);
223 if (
virtual && mem->
bus.addr ==
NULL)
226 ttm_mem_io_free(bdev, mem);
230 static int ttm_copy_io_page(
void *
dst,
void *
src,
unsigned long page)
243 static int ttm_copy_io_ttm_page(
struct ttm_tt *ttm,
void *src,
253 src = (
void *)((
unsigned long)src + (page <<
PAGE_SHIFT));
259 dst =
vmap(&d, 1, 0, prot);
280 static int ttm_copy_ttm_io_page(
struct ttm_tt *ttm,
void *dst,
290 dst = (
void *)((
unsigned long)dst + (page <<
PAGE_SHIFT));
295 src =
vmap(&s, 1, 0, prot);
317 bool evict,
bool no_wait_reserve,
bool no_wait_gpu,
330 unsigned long add = 0;
340 if (old_iomap ==
NULL && new_iomap ==
NULL)
342 if (old_iomap ==
NULL && ttm ==
NULL)
345 if (ttm->
state == tt_unpopulated) {
346 ret = ttm->
bdev->driver->ttm_tt_populate(ttm);
361 page = i * dir +
add;
362 if (old_iomap ==
NULL) {
365 ret = ttm_copy_ttm_io_page(ttm, new_iomap, page,
367 }
else if (new_iomap ==
NULL) {
370 ret = ttm_copy_io_ttm_page(ttm, old_iomap, page,
373 ret = ttm_copy_io_page(new_iomap, old_iomap, page);
438 INIT_LIST_HEAD(&fbo->
lru);
439 INIT_LIST_HEAD(&fbo->
swap);
446 kref_init(&fbo->
kref);
447 fbo->
destroy = &ttm_transfered_destroy;
456 #if defined(__i386__) || defined(__x86_64__)
462 #elif defined(__powerpc__)
469 #if defined(__ia64__)
470 if (caching_flags & TTM_PL_FLAG_WC)
475 #if defined(__sparc__) || defined(__mips__)
476 if (!(caching_flags & TTM_PL_FLAG_CACHED))
490 if (bo->
mem.bus.addr) {
506 unsigned long start_page,
517 ret = ttm->
bdev->driver->ttm_tt_populate(ttm);
547 unsigned long start_page,
unsigned long num_pages,
551 &bo->
bdev->man[bo->
mem.mem_type];
563 if (num_pages > 1 && !
DRM_SUSER(DRM_CURPROC))
567 ret = ttm_mem_io_reserve(bo->
bdev, &bo->
mem);
571 if (!bo->
mem.bus.is_iomem) {
572 return ttm_bo_kmap_ttm(bo, start_page, num_pages, map);
576 return ttm_bo_ioremap(bo, offset, size, map);
585 &bo->
bdev->man[bo->
mem.mem_type];
590 case ttm_bo_map_iomap:
593 case ttm_bo_map_vmap:
596 case ttm_bo_map_kmap:
599 case ttm_bo_map_premapped:
605 ttm_mem_io_free(map->
bo->bdev, &map->
bo->mem);
615 bool evict,
bool no_wait_reserve,
625 void *tmp_obj =
NULL;
663 ret = ttm_buffer_object_transfer(bo, &ghost_obj);