drm/nouveau: require reservations for nouveau_fence_sync and nouveau_bo_fence
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nouveau_bo.c
index d9e7c4023677180d7b05ea4c3dbd35135f9ff8c0..ed966f51e29b5c3c32d6be1b0307a28a0d0bde52 100644 (file)
  *         Jeremy Kolb  <jkolb@brandeis.edu>
  */
 
-#include <core/engine.h>
+#include <linux/dma-mapping.h>
 #include <linux/swiotlb.h>
 
-#include <subdev/fb.h>
-#include <subdev/vm.h>
-#include <subdev/bar.h>
-
 #include "nouveau_drm.h"
 #include "nouveau_dma.h"
 #include "nouveau_fence.h"
@@ -52,7 +48,7 @@ nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg,
 {
        struct nouveau_drm *drm = nouveau_drm(dev);
        int i = reg - drm->tile.reg;
-       struct nouveau_fb *pfb = nouveau_fb(drm->device);
+       struct nouveau_fb *pfb = nvkm_fb(&drm->device);
        struct nouveau_fb_tile *tile = &pfb->tile.region[i];
        struct nouveau_engine *engine;
 
@@ -109,7 +105,7 @@ nv10_bo_set_tiling(struct drm_device *dev, u32 addr,
                   u32 size, u32 pitch, u32 flags)
 {
        struct nouveau_drm *drm = nouveau_drm(dev);
-       struct nouveau_fb *pfb = nouveau_fb(drm->device);
+       struct nouveau_fb *pfb = nvkm_fb(&drm->device);
        struct nouveau_drm_tile *tile, *found = NULL;
        int i;
 
@@ -153,23 +149,23 @@ nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags,
                       int *align, int *size)
 {
        struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
-       struct nouveau_device *device = nv_device(drm->device);
+       struct nvif_device *device = &drm->device;
 
-       if (device->card_type < NV_50) {
+       if (device->info.family < NV_DEVICE_INFO_V0_TESLA) {
                if (nvbo->tile_mode) {
-                       if (device->chipset >= 0x40) {
+                       if (device->info.chipset >= 0x40) {
                                *align = 65536;
                                *size = roundup(*size, 64 * nvbo->tile_mode);
 
-                       } else if (device->chipset >= 0x30) {
+                       } else if (device->info.chipset >= 0x30) {
                                *align = 32768;
                                *size = roundup(*size, 64 * nvbo->tile_mode);
 
-                       } else if (device->chipset >= 0x20) {
+                       } else if (device->info.chipset >= 0x20) {
                                *align = 16384;
                                *size = roundup(*size, 64 * nvbo->tile_mode);
 
-                       } else if (device->chipset >= 0x10) {
+                       } else if (device->info.chipset >= 0x10) {
                                *align = 16384;
                                *size = roundup(*size, 32 * nvbo->tile_mode);
                        }
@@ -201,7 +197,7 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
        max_size = INT_MAX & ~((1 << lpg_shift) - 1);
 
        if (size <= 0 || size > max_size) {
-               nv_warn(drm, "skipped size %x\n", (u32)size);
+               NV_WARN(drm, "skipped size %x\n", (u32)size);
                return -EINVAL;
        }
 
@@ -245,27 +241,26 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
 }
 
 static void
-set_placement_list(uint32_t *pl, unsigned *n, uint32_t type, uint32_t flags)
+set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t type, uint32_t flags)
 {
        *n = 0;
 
        if (type & TTM_PL_FLAG_VRAM)
-               pl[(*n)++] = TTM_PL_FLAG_VRAM | flags;
+               pl[(*n)++].flags = TTM_PL_FLAG_VRAM | flags;
        if (type & TTM_PL_FLAG_TT)
-               pl[(*n)++] = TTM_PL_FLAG_TT | flags;
+               pl[(*n)++].flags = TTM_PL_FLAG_TT | flags;
        if (type & TTM_PL_FLAG_SYSTEM)
-               pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags;
+               pl[(*n)++].flags = TTM_PL_FLAG_SYSTEM | flags;
 }
 
 static void
 set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
 {
        struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
-       struct nouveau_fb *pfb = nouveau_fb(drm->device);
-       u32 vram_pages = pfb->ram->size >> PAGE_SHIFT;
+       u32 vram_pages = drm->device.info.ram_size >> PAGE_SHIFT;
+       unsigned i, fpfn, lpfn;
 
-       if ((nv_device(drm->device)->card_type == NV_10 ||
-            nv_device(drm->device)->card_type == NV_11) &&
+       if (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
            nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) &&
            nvbo->bo.mem.num_pages < vram_pages / 4) {
                /*
@@ -275,11 +270,19 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
                 * at the same time.
                 */
                if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) {
-                       nvbo->placement.fpfn = vram_pages / 2;
-                       nvbo->placement.lpfn = ~0;
+                       fpfn = vram_pages / 2;
+                       lpfn = ~0;
                } else {
-                       nvbo->placement.fpfn = 0;
-                       nvbo->placement.lpfn = vram_pages / 2;
+                       fpfn = 0;
+                       lpfn = vram_pages / 2;
+               }
+               for (i = 0; i < nvbo->placement.num_placement; ++i) {
+                       nvbo->placements[i].fpfn = fpfn;
+                       nvbo->placements[i].lpfn = lpfn;
+               }
+               for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
+                       nvbo->busy_placements[i].fpfn = fpfn;
+                       nvbo->busy_placements[i].lpfn = lpfn;
                }
        }
 }
@@ -506,9 +509,9 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
                                         TTM_PL_FLAG_WC;
                man->default_caching = TTM_PL_FLAG_WC;
 
-               if (nv_device(drm->device)->card_type >= NV_50) {
+               if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
                        /* Some BARs do not support being ioremapped WC */
-                       if (nouveau_bar(drm->device)->iomap_uncached) {
+                       if (nvkm_bar(&drm->device)->iomap_uncached) {
                                man->available_caching = TTM_PL_FLAG_UNCACHED;
                                man->default_caching = TTM_PL_FLAG_UNCACHED;
                        }
@@ -521,7 +524,7 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
                }
                break;
        case TTM_PL_TT:
-               if (nv_device(drm->device)->card_type >= NV_50)
+               if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
                        man->func = &nouveau_gart_manager;
                else
                if (drm->agp.stat != ENABLED)
@@ -770,9 +773,9 @@ nv50_bo_move_init(struct nouveau_channel *chan, u32 handle)
                BEGIN_NV04(chan, NvSubCopy, 0x0000, 1);
                OUT_RING  (chan, handle);
                BEGIN_NV04(chan, NvSubCopy, 0x0180, 3);
-               OUT_RING  (chan, NvNotify0);
-               OUT_RING  (chan, NvDmaFB);
-               OUT_RING  (chan, NvDmaFB);
+               OUT_RING  (chan, chan->drm->ntfy.handle);
+               OUT_RING  (chan, chan->vram.handle);
+               OUT_RING  (chan, chan->vram.handle);
        }
 
        return ret;
@@ -859,7 +862,7 @@ nv04_bo_move_init(struct nouveau_channel *chan, u32 handle)
                BEGIN_NV04(chan, NvSubCopy, 0x0000, 1);
                OUT_RING  (chan, handle);
                BEGIN_NV04(chan, NvSubCopy, 0x0180, 1);
-               OUT_RING  (chan, NvNotify0);
+               OUT_RING  (chan, chan->drm->ntfy.handle);
        }
 
        return ret;
@@ -871,7 +874,7 @@ nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo,
 {
        if (mem->mem_type == TTM_PL_TT)
                return NvDmaTT;
-       return NvDmaFB;
+       return chan->vram.handle;
 }
 
 static int
@@ -952,6 +955,7 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,
 {
        struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
        struct nouveau_channel *chan = drm->ttm.chan;
+       struct nouveau_cli *cli = (void *)nvif_client(&chan->device->base);
        struct nouveau_fence *fence;
        int ret;
 
@@ -959,13 +963,13 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,
         * old nouveau_mem node, these will get cleaned up after ttm has
         * destroyed the ttm_mem_reg
         */
-       if (nv_device(drm->device)->card_type >= NV_50) {
+       if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
                ret = nouveau_bo_move_prep(drm, bo, new_mem);
                if (ret)
                        return ret;
        }
 
-       mutex_lock_nested(&chan->cli->mutex, SINGLE_DEPTH_NESTING);
+       mutex_lock_nested(&cli->mutex, SINGLE_DEPTH_NESTING);
        ret = nouveau_fence_sync(bo->sync_obj, chan);
        if (ret == 0) {
                ret = drm->ttm.move(chan, bo, &bo->mem, new_mem);
@@ -980,7 +984,7 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,
                        }
                }
        }
-       mutex_unlock(&chan->cli->mutex);
+       mutex_unlock(&cli->mutex);
        return ret;
 }
 
@@ -1012,9 +1016,7 @@ nouveau_bo_move_init(struct nouveau_drm *drm)
        int ret;
 
        do {
-               struct nouveau_object *object;
                struct nouveau_channel *chan;
-               u32 handle = (mthd->engine << 16) | mthd->oclass;
 
                if (mthd->engine)
                        chan = drm->cechan;
@@ -1023,13 +1025,14 @@ nouveau_bo_move_init(struct nouveau_drm *drm)
                if (chan == NULL)
                        continue;
 
-               ret = nouveau_object_new(nv_object(drm), chan->handle, handle,
-                                        mthd->oclass, NULL, 0, &object);
+               ret = nvif_object_init(chan->object, NULL,
+                                      mthd->oclass | (mthd->engine << 16),
+                                      mthd->oclass, NULL, 0,
+                                      &drm->ttm.copy);
                if (ret == 0) {
-                       ret = mthd->init(chan, handle);
+                       ret = mthd->init(chan, drm->ttm.copy.handle);
                        if (ret) {
-                               nouveau_object_del(nv_object(drm),
-                                                  chan->handle, handle);
+                               nvif_object_fini(&drm->ttm.copy);
                                continue;
                        }
 
@@ -1047,12 +1050,15 @@ static int
 nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
                      bool no_wait_gpu, struct ttm_mem_reg *new_mem)
 {
-       u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
+       struct ttm_place placement_memtype = {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING
+       };
        struct ttm_placement placement;
        struct ttm_mem_reg tmp_mem;
        int ret;
 
-       placement.fpfn = placement.lpfn = 0;
        placement.num_placement = placement.num_busy_placement = 1;
        placement.placement = placement.busy_placement = &placement_memtype;
 
@@ -1080,12 +1086,15 @@ static int
 nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr,
                      bool no_wait_gpu, struct ttm_mem_reg *new_mem)
 {
-       u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
+       struct ttm_place placement_memtype = {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING
+       };
        struct ttm_placement placement;
        struct ttm_mem_reg tmp_mem;
        int ret;
 
-       placement.fpfn = placement.lpfn = 0;
        placement.num_placement = placement.num_busy_placement = 1;
        placement.placement = placement.busy_placement = &placement_memtype;
 
@@ -1142,7 +1151,7 @@ nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem,
        if (new_mem->mem_type != TTM_PL_VRAM)
                return 0;
 
-       if (nv_device(drm->device)->card_type >= NV_10) {
+       if (drm->device.info.family >= NV_DEVICE_INFO_V0_CELSIUS) {
                *new_tile = nv10_bo_set_tiling(dev, offset, new_mem->size,
                                                nvbo->tile_mode,
                                                nvbo->tile_flags);
@@ -1173,7 +1182,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr,
        struct nouveau_drm_tile *new_tile = NULL;
        int ret = 0;
 
-       if (nv_device(drm->device)->card_type < NV_50) {
+       if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
                ret = nouveau_bo_vm_bind(bo, new_mem, &new_tile);
                if (ret)
                        return ret;
@@ -1210,7 +1219,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr,
                ret = ttm_bo_move_memcpy(bo, evict, no_wait_gpu, new_mem);
 
 out:
-       if (nv_device(drm->device)->card_type < NV_50) {
+       if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
                if (ret)
                        nouveau_bo_vm_cleanup(bo, NULL, &new_tile);
                else
@@ -1234,7 +1243,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
        struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
        struct nouveau_drm *drm = nouveau_bdev(bdev);
        struct nouveau_mem *node = mem->mm_node;
-       struct drm_device *dev = drm->dev;
        int ret;
 
        mem->bus.addr = NULL;
@@ -1253,19 +1261,19 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
                if (drm->agp.stat == ENABLED) {
                        mem->bus.offset = mem->start << PAGE_SHIFT;
                        mem->bus.base = drm->agp.base;
-                       mem->bus.is_iomem = !dev->agp->cant_use_aperture;
+                       mem->bus.is_iomem = !drm->dev->agp->cant_use_aperture;
                }
 #endif
-               if (nv_device(drm->device)->card_type < NV_50 || !node->memtype)
+               if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA || !node->memtype)
                        /* untiled */
                        break;
                /* fallthrough, tiled memory */
        case TTM_PL_VRAM:
                mem->bus.offset = mem->start << PAGE_SHIFT;
-               mem->bus.base = nv_device_resource_start(nouveau_dev(dev), 1);
+               mem->bus.base = nv_device_resource_start(nvkm_device(&drm->device), 1);
                mem->bus.is_iomem = true;
-               if (nv_device(drm->device)->card_type >= NV_50) {
-                       struct nouveau_bar *bar = nouveau_bar(drm->device);
+               if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+                       struct nouveau_bar *bar = nvkm_bar(&drm->device);
 
                        ret = bar->umap(bar, node, NV_MEM_ACCESS_RW,
                                        &node->bar_vma);
@@ -1285,7 +1293,7 @@ static void
 nouveau_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
 {
        struct nouveau_drm *drm = nouveau_bdev(bdev);
-       struct nouveau_bar *bar = nouveau_bar(drm->device);
+       struct nouveau_bar *bar = nvkm_bar(&drm->device);
        struct nouveau_mem *node = mem->mm_node;
 
        if (!node->bar_vma.node)
@@ -1299,15 +1307,15 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 {
        struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
        struct nouveau_bo *nvbo = nouveau_bo(bo);
-       struct nouveau_device *device = nv_device(drm->device);
-       u32 mappable = nv_device_resource_len(device, 1) >> PAGE_SHIFT;
-       int ret;
+       struct nvif_device *device = &drm->device;
+       u32 mappable = nv_device_resource_len(nvkm_device(device), 1) >> PAGE_SHIFT;
+       int i, ret;
 
        /* as long as the bo isn't in vram, and isn't tiled, we've got
         * nothing to do here.
         */
        if (bo->mem.mem_type != TTM_PL_VRAM) {
-               if (nv_device(drm->device)->card_type < NV_50 ||
+               if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA ||
                    !nouveau_bo_tile_layout(nvbo))
                        return 0;
 
@@ -1322,13 +1330,20 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
        }
 
        /* make sure bo is in mappable vram */
-       if (nv_device(drm->device)->card_type >= NV_50 ||
+       if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA ||
            bo->mem.start + bo->mem.num_pages < mappable)
                return 0;
 
+       for (i = 0; i < nvbo->placement.num_placement; ++i) {
+               nvbo->placements[i].fpfn = 0;
+               nvbo->placements[i].lpfn = mappable;
+       }
+
+       for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
+               nvbo->busy_placements[i].fpfn = 0;
+               nvbo->busy_placements[i].lpfn = mappable;
+       }
 
-       nvbo->placement.fpfn = 0;
-       nvbo->placement.lpfn = mappable;
        nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_VRAM, 0);
        return nouveau_bo_validate(nvbo, false, false);
 }
@@ -1357,7 +1372,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
        }
 
        drm = nouveau_bdev(ttm->bdev);
-       device = nv_device(drm->device);
+       device = nvkm_device(&drm->device);
        dev = drm->dev;
        pdev = nv_device_base(device);
 
@@ -1414,7 +1429,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
                return;
 
        drm = nouveau_bdev(ttm->bdev);
-       device = nv_device(drm->device);
+       device = nvkm_device(&drm->device);
        dev = drm->dev;
        pdev = nv_device_base(device);
 
@@ -1448,6 +1463,8 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)
        struct nouveau_fence *new_fence = nouveau_fence_ref(fence);
        struct nouveau_fence *old_fence = NULL;
 
+       lockdep_assert_held(&nvbo->bo.resv->lock.base);
+
        spin_lock(&nvbo->bo.bdev->fence_lock);
        old_fence = nvbo->bo.sync_obj;
        nvbo->bo.sync_obj = new_fence;
This page took 0.033271 seconds and 5 git commands to generate.