]> git.karo-electronics.de Git - linux-beck.git/commitdiff
drm/ttm: move fpfn and lpfn into each placement v2
authorChristian König <christian.koenig@amd.com>
Wed, 27 Aug 2014 11:16:04 +0000 (13:16 +0200)
committerChristian König <christian.koenig@amd.com>
Wed, 27 Aug 2014 11:16:04 +0000 (13:16 +0200)
This allows us to more fine grained specify where to place the buffer object.

v2: rebased on drm-next, add bochs changes as well

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
26 files changed:
drivers/gpu/drm/ast/ast_drv.h
drivers/gpu/drm/ast/ast_ttm.c
drivers/gpu/drm/bochs/bochs.h
drivers/gpu/drm/bochs/bochs_mm.c
drivers/gpu/drm/cirrus/cirrus_drv.h
drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/mgag200/mgag200_drv.h
drivers/gpu/drm/mgag200/mgag200_ttm.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/nouveau/nouveau_bo.h
drivers/gpu/drm/nouveau/nouveau_ttm.c
drivers/gpu/drm/qxl/qxl_drv.h
drivers/gpu/drm/qxl/qxl_object.c
drivers/gpu/drm/qxl/qxl_ttm.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_object.c
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/radeon/radeon_uvd.c
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/ttm/ttm_bo_manager.c
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
include/drm/ttm/ttm_bo_api.h
include/drm/ttm/ttm_bo_driver.h

index 957d4fabf1e1c2c8e58348a9af7f6ba6fcdd63c6..cb91c2acc3cbaf4624ee21e5fbaa1dd6ed48b5d7 100644 (file)
@@ -316,7 +316,7 @@ struct ast_bo {
        struct ttm_placement placement;
        struct ttm_bo_kmap_obj kmap;
        struct drm_gem_object gem;
-       u32 placements[3];
+       struct ttm_place placements[3];
        int pin_count;
 };
 #define gem_to_ast_bo(gobj) container_of((gobj), struct ast_bo, gem)
index b8246227bab009e042ebb46e3a4bb093301ffcec..8008ea0bc76cb01028237528c5f929fb3ed26dc1 100644 (file)
@@ -293,18 +293,22 @@ void ast_mm_fini(struct ast_private *ast)
 void ast_ttm_placement(struct ast_bo *bo, int domain)
 {
        u32 c = 0;
-       bo->placement.fpfn = 0;
-       bo->placement.lpfn = 0;
+       unsigned i;
+
        bo->placement.placement = bo->placements;
        bo->placement.busy_placement = bo->placements;
        if (domain & TTM_PL_FLAG_VRAM)
-               bo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
+               bo->placements[c++].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
        if (domain & TTM_PL_FLAG_SYSTEM)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        if (!c)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        bo->placement.num_placement = c;
        bo->placement.num_busy_placement = c;
+       for (i = 0; i < c; ++i) {
+               bo->placements[i].fpfn = 0;
+               bo->placements[i].lpfn = 0;
+       }
 }
 
 int ast_bo_create(struct drm_device *dev, int size, int align,
@@ -360,7 +364,7 @@ int ast_bo_pin(struct ast_bo *bo, u32 pl_flag, u64 *gpu_addr)
 
        ast_ttm_placement(bo, pl_flag);
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -383,7 +387,7 @@ int ast_bo_unpin(struct ast_bo *bo)
                return 0;
 
        for (i = 0; i < bo->placement.num_placement ; i++)
-               bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -407,7 +411,7 @@ int ast_bo_push_sysram(struct ast_bo *bo)
 
        ast_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
        for (i = 0; i < bo->placement.num_placement ; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret) {
index 7eb52dd44b0109340c7add338c5e0babb175dd79..4f6e7b3a36359c8beeb5882d9d49a6e2f4a257c8 100644 (file)
@@ -99,7 +99,7 @@ struct bochs_bo {
        struct ttm_placement placement;
        struct ttm_bo_kmap_obj kmap;
        struct drm_gem_object gem;
-       u32 placements[3];
+       struct ttm_place placements[3];
        int pin_count;
 };
 
index 1728a1b0b81376ed43e7f39fb5f863cba7563166..2af30e7607d7d071e0d2a46db16cab7ddfcdfc3d 100644 (file)
@@ -257,20 +257,26 @@ void bochs_mm_fini(struct bochs_device *bochs)
 
 static void bochs_ttm_placement(struct bochs_bo *bo, int domain)
 {
+       unsigned i;
        u32 c = 0;
-       bo->placement.fpfn = 0;
-       bo->placement.lpfn = 0;
        bo->placement.placement = bo->placements;
        bo->placement.busy_placement = bo->placements;
        if (domain & TTM_PL_FLAG_VRAM) {
-               bo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED
+               bo->placements[c++].flags = TTM_PL_FLAG_WC
+                       | TTM_PL_FLAG_UNCACHED
                        | TTM_PL_FLAG_VRAM;
        }
        if (domain & TTM_PL_FLAG_SYSTEM) {
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING
+                       | TTM_PL_FLAG_SYSTEM;
        }
        if (!c) {
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING
+                       | TTM_PL_FLAG_SYSTEM;
+       }
+       for (i = 0; i < c; ++i) {
+               bo->placements[i].fpfn = 0;
+               bo->placements[i].lpfn = 0;
        }
        bo->placement.num_placement = c;
        bo->placement.num_busy_placement = c;
@@ -294,7 +300,7 @@ int bochs_bo_pin(struct bochs_bo *bo, u32 pl_flag, u64 *gpu_addr)
 
        bochs_ttm_placement(bo, pl_flag);
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -319,7 +325,7 @@ int bochs_bo_unpin(struct bochs_bo *bo)
                return 0;
 
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
index 401c890b6c6a817011923215706a9f2e259d4d71..dd2cfc9024aa3be943c683773bb8b88c5d365f93 100644 (file)
@@ -163,7 +163,7 @@ struct cirrus_bo {
        struct ttm_placement placement;
        struct ttm_bo_kmap_obj kmap;
        struct drm_gem_object gem;
-       u32 placements[3];
+       struct ttm_place placements[3];
        int pin_count;
 };
 #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
index 92e6b77860970097b30bb745859d7a020661eefa..3e7d758330a9502dcf9d70c5aabceab1e520218b 100644 (file)
@@ -298,18 +298,21 @@ void cirrus_mm_fini(struct cirrus_device *cirrus)
 void cirrus_ttm_placement(struct cirrus_bo *bo, int domain)
 {
        u32 c = 0;
-       bo->placement.fpfn = 0;
-       bo->placement.lpfn = 0;
+       unsigned i;
        bo->placement.placement = bo->placements;
        bo->placement.busy_placement = bo->placements;
        if (domain & TTM_PL_FLAG_VRAM)
-               bo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
+               bo->placements[c++].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
        if (domain & TTM_PL_FLAG_SYSTEM)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        if (!c)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        bo->placement.num_placement = c;
        bo->placement.num_busy_placement = c;
+       for (i = 0; i < c; ++i) {
+               bo->placements[i].fpfn = 0;
+               bo->placements[i].lpfn = 0;
+       }
 }
 
 int cirrus_bo_create(struct drm_device *dev, int size, int align,
@@ -365,7 +368,7 @@ int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
 
        cirrus_ttm_placement(bo, pl_flag);
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -392,7 +395,7 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo)
 
        cirrus_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
        for (i = 0; i < bo->placement.num_placement ; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret) {
index 80de23d9b9c9801daf630611205a2baa768a3341..2e2b76aa4e17df7ffa4e6a8fc1cc733f6fca6452 100644 (file)
@@ -224,7 +224,7 @@ struct mgag200_bo {
        struct ttm_placement placement;
        struct ttm_bo_kmap_obj kmap;
        struct drm_gem_object gem;
-       u32 placements[3];
+       struct ttm_place placements[3];
        int pin_count;
 };
 #define gem_to_mga_bo(gobj) container_of((gobj), struct mgag200_bo, gem)
index 5a00e90696de525129a98d9e4a438ab7b3779a49..be883ef5a1d359b97ecc1c55d622112e52b52e8e 100644 (file)
@@ -293,18 +293,22 @@ void mgag200_mm_fini(struct mga_device *mdev)
 void mgag200_ttm_placement(struct mgag200_bo *bo, int domain)
 {
        u32 c = 0;
-       bo->placement.fpfn = 0;
-       bo->placement.lpfn = 0;
+       unsigned i;
+
        bo->placement.placement = bo->placements;
        bo->placement.busy_placement = bo->placements;
        if (domain & TTM_PL_FLAG_VRAM)
-               bo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
+               bo->placements[c++].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
        if (domain & TTM_PL_FLAG_SYSTEM)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        if (!c)
-               bo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        bo->placement.num_placement = c;
        bo->placement.num_busy_placement = c;
+       for (i = 0; i < c; ++i) {
+               bo->placements[i].fpfn = 0;
+               bo->placements[i].lpfn = 0;
+       }
 }
 
 int mgag200_bo_create(struct drm_device *dev, int size, int align,
@@ -361,7 +365,7 @@ int mgag200_bo_pin(struct mgag200_bo *bo, u32 pl_flag, u64 *gpu_addr)
 
        mgag200_ttm_placement(bo, pl_flag);
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -384,7 +388,7 @@ int mgag200_bo_unpin(struct mgag200_bo *bo)
                return 0;
 
        for (i = 0; i < bo->placement.num_placement ; i++)
-               bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret)
                return ret;
@@ -408,7 +412,7 @@ int mgag200_bo_push_sysram(struct mgag200_bo *bo)
 
        mgag200_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
        for (i = 0; i < bo->placement.num_placement ; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 
        ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
        if (ret) {
index 01da508625f27e4ad1c27393b8eaa928634564aa..0591ca0734e35f941fb20ddff1e074c4058f390d 100644 (file)
@@ -241,16 +241,16 @@ 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
@@ -258,6 +258,7 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
 {
        struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
        u32 vram_pages = drm->device.info.ram_size >> PAGE_SHIFT;
+       unsigned i, fpfn, lpfn;
 
        if (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
            nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) &&
@@ -269,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;
                }
        }
 }
@@ -1041,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;
 
@@ -1074,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;
 
@@ -1294,7 +1309,7 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
        struct nouveau_bo *nvbo = nouveau_bo(bo);
        struct nvif_device *device = &drm->device;
        u32 mappable = nv_device_resource_len(nvkm_device(device), 1) >> PAGE_SHIFT;
-       int ret;
+       int i, ret;
 
        /* as long as the bo isn't in vram, and isn't tiled, we've got
         * nothing to do here.
@@ -1319,9 +1334,16 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
            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);
 }
index ff17c1f432fc9e9312ace42491385bb76226b381..4ef88e84a6943d6c4df0f4420fe717408c4d6d3a 100644 (file)
@@ -9,8 +9,8 @@ struct nouveau_bo {
        struct ttm_buffer_object bo;
        struct ttm_placement placement;
        u32 valid_domains;
-       u32 placements[3];
-       u32 busy_placements[3];
+       struct ttm_place placements[3];
+       struct ttm_place busy_placements[3];
        struct ttm_bo_kmap_obj kmap;
        struct list_head head;
 
index 53874b76b031081b38853a400eaa2f1dc2f199e2..e81d086577cee7fb65c5feeffdcabfda15966510 100644 (file)
@@ -71,8 +71,7 @@ nouveau_vram_manager_del(struct ttm_mem_type_manager *man,
 static int
 nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
                         struct ttm_buffer_object *bo,
-                        struct ttm_placement *placement,
-                        uint32_t flags,
+                        const struct ttm_place *place,
                         struct ttm_mem_reg *mem)
 {
        struct nouveau_drm *drm = nouveau_bdev(man->bdev);
@@ -158,8 +157,7 @@ nouveau_gart_manager_del(struct ttm_mem_type_manager *man,
 static int
 nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
                         struct ttm_buffer_object *bo,
-                        struct ttm_placement *placement,
-                        uint32_t flags,
+                        const struct ttm_place *place,
                         struct ttm_mem_reg *mem)
 {
        struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
@@ -239,8 +237,7 @@ nv04_gart_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *mem)
 static int
 nv04_gart_manager_new(struct ttm_mem_type_manager *man,
                      struct ttm_buffer_object *bo,
-                     struct ttm_placement *placement,
-                     uint32_t flags,
+                     const struct ttm_place *place,
                      struct ttm_mem_reg *mem)
 {
        struct nouveau_mem *node;
index 36ed40ba773f8149d88eacef4c0633614e09eb83..f6022b703645f1bcc081fa8eea50b18d652187b2 100644 (file)
@@ -106,7 +106,7 @@ struct qxl_bo {
        /* Protected by gem.mutex */
        struct list_head                list;
        /* Protected by tbo.reserved */
-       u32                             placements[3];
+       struct ttm_place                placements[3];
        struct ttm_placement            placement;
        struct ttm_buffer_object        tbo;
        struct ttm_bo_kmap_obj          kmap;
index b95f144f0b4934abbb034e22c5d057a065bcecd6..adad12d3037245a7859e7c81e2212c1deb8f2805 100644 (file)
@@ -55,21 +55,24 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned)
 {
        u32 c = 0;
        u32 pflag = pinned ? TTM_PL_FLAG_NO_EVICT : 0;
+       unsigned i;
 
-       qbo->placement.fpfn = 0;
-       qbo->placement.lpfn = 0;
        qbo->placement.placement = qbo->placements;
        qbo->placement.busy_placement = qbo->placements;
        if (domain == QXL_GEM_DOMAIN_VRAM)
-               qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_VRAM | pflag;
+               qbo->placements[c++].flags = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_VRAM | pflag;
        if (domain == QXL_GEM_DOMAIN_SURFACE)
-               qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_PRIV0 | pflag;
+               qbo->placements[c++].flags = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_PRIV0 | pflag;
        if (domain == QXL_GEM_DOMAIN_CPU)
-               qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM | pflag;
+               qbo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM | pflag;
        if (!c)
-               qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               qbo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
        qbo->placement.num_placement = c;
        qbo->placement.num_busy_placement = c;
+       for (i = 0; i < c; ++i) {
+               qbo->placements[i].fpfn = 0;
+               qbo->placements[i].lpfn = 0;
+       }
 }
 
 
@@ -259,7 +262,7 @@ int qxl_bo_unpin(struct qxl_bo *bo)
        if (bo->pin_count)
                return 0;
        for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
+               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
        r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
        if (unlikely(r != 0))
                dev_err(qdev->dev, "%p validate failed for unpin\n", bo);
index 71a1baeac14edc4ceabb8ab397d0dfe2c23b335b..f66c59b222f1a92a9ad88ec714f47ac139e1b284 100644 (file)
@@ -188,11 +188,13 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
                                struct ttm_placement *placement)
 {
        struct qxl_bo *qbo;
-       static u32 placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+       static struct ttm_place placements = {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM
+       };
 
        if (!qxl_ttm_bo_is_qxl_bo(bo)) {
-               placement->fpfn = 0;
-               placement->lpfn = 0;
                placement->placement = &placements;
                placement->busy_placement = &placements;
                placement->num_placement = 1;
index b321ad4dcafd1c78fea6c3cf29512c1004a3e4a9..bb01dab513ddd88ddfdb2be55fab2512e78ab87f 100644 (file)
@@ -469,7 +469,7 @@ struct radeon_bo {
        struct list_head                list;
        /* Protected by tbo.reserved */
        u32                             initial_domain;
-       u32                             placements[3];
+       struct ttm_place                placements[3];
        struct ttm_placement            placement;
        struct ttm_buffer_object        tbo;
        struct ttm_bo_kmap_obj          kmap;
index 287523807989447d91618d02c3bf76575deb3c2e..0129c7efae3b929d854a9c8f6bd69c5f94586a5c 100644 (file)
@@ -97,40 +97,56 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 {
        u32 c = 0, i;
 
-       rbo->placement.fpfn = 0;
-       rbo->placement.lpfn = 0;
        rbo->placement.placement = rbo->placements;
        rbo->placement.busy_placement = rbo->placements;
        if (domain & RADEON_GEM_DOMAIN_VRAM)
-               rbo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
-                                       TTM_PL_FLAG_VRAM;
+               rbo->placements[c++].flags = TTM_PL_FLAG_WC |
+                                            TTM_PL_FLAG_UNCACHED |
+                                            TTM_PL_FLAG_VRAM;
+
        if (domain & RADEON_GEM_DOMAIN_GTT) {
                if (rbo->flags & RADEON_GEM_GTT_UC) {
-                       rbo->placements[c++] = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_TT;
+                       rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
+                               TTM_PL_FLAG_TT;
+
                } else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
                           (rbo->rdev->flags & RADEON_IS_AGP)) {
-                       rbo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
+                       rbo->placements[c++].flags = TTM_PL_FLAG_WC |
+                               TTM_PL_FLAG_UNCACHED |
                                TTM_PL_FLAG_TT;
                } else {
-                       rbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_TT;
+                       rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
+                                                    TTM_PL_FLAG_TT;
                }
        }
+
        if (domain & RADEON_GEM_DOMAIN_CPU) {
                if (rbo->flags & RADEON_GEM_GTT_UC) {
-                       rbo->placements[c++] = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_SYSTEM;
+                       rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
+                               TTM_PL_FLAG_SYSTEM;
+
                } else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
                    rbo->rdev->flags & RADEON_IS_AGP) {
-                       rbo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
+                       rbo->placements[c++].flags = TTM_PL_FLAG_WC |
+                               TTM_PL_FLAG_UNCACHED |
                                TTM_PL_FLAG_SYSTEM;
                } else {
-                       rbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM;
+                       rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
+                                                    TTM_PL_FLAG_SYSTEM;
                }
        }
        if (!c)
-               rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
+               rbo->placements[c++].flags = TTM_PL_MASK_CACHING |
+                                            TTM_PL_FLAG_SYSTEM;
+
        rbo->placement.num_placement = c;
        rbo->placement.num_busy_placement = c;
 
+       for (i = 0; i < c; ++i) {
+               rbo->placements[i].fpfn = 0;
+               rbo->placements[i].lpfn = 0;
+       }
+
        /*
         * Use two-ended allocation depending on the buffer size to
         * improve fragmentation quality.
@@ -138,7 +154,7 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
         */
        if (rbo->tbo.mem.size > 512 * 1024) {
                for (i = 0; i < c; i++) {
-                       rbo->placements[i] |= TTM_PL_FLAG_TOPDOWN;
+                       rbo->placements[i].flags |= TTM_PL_FLAG_TOPDOWN;
                }
        }
 }
@@ -287,21 +303,22 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
                return 0;
        }
        radeon_ttm_placement_from_domain(bo, domain);
-       if (domain == RADEON_GEM_DOMAIN_VRAM) {
+       for (i = 0; i < bo->placement.num_placement; i++) {
+               unsigned lpfn = 0;
+
                /* force to pin into visible video ram */
-               bo->placement.lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
-       }
-       if (max_offset) {
-               u64 lpfn = max_offset >> PAGE_SHIFT;
+               if (bo->placements[i].flags & TTM_PL_FLAG_VRAM)
+                       lpfn = bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
+               else
+                       lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT; /* ??? */
 
-               if (!bo->placement.lpfn)
-                       bo->placement.lpfn = bo->rdev->mc.gtt_size >> PAGE_SHIFT;
+               if (max_offset)
+                       lpfn = min (lpfn, (unsigned)(max_offset >> PAGE_SHIFT));
 
-               if (lpfn < bo->placement.lpfn)
-                       bo->placement.lpfn = lpfn;
+               bo->placements[i].lpfn = lpfn;
+               bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
        }
-       for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
+
        r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
        if (likely(r == 0)) {
                bo->pin_count = 1;
@@ -333,8 +350,10 @@ int radeon_bo_unpin(struct radeon_bo *bo)
        bo->pin_count--;
        if (bo->pin_count)
                return 0;
-       for (i = 0; i < bo->placement.num_placement; i++)
-               bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
+       for (i = 0; i < bo->placement.num_placement; i++) {
+               bo->placements[i].lpfn = 0;
+               bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
+       }
        r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
        if (likely(r == 0)) {
                if (bo->tbo.mem.mem_type == TTM_PL_VRAM)
@@ -735,7 +754,7 @@ int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 
        /* hurrah the memory is not visible ! */
        radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM);
-       rbo->placement.lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
+       rbo->placements[0].lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
        r = ttm_bo_validate(bo, &rbo->placement, false, false);
        if (unlikely(r == -ENOMEM)) {
                radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);
index 12e37b1ddc4004b5948d7d91d8af43b8c47c9107..822eb36300456aee5da04f438a405534df78ace9 100644 (file)
@@ -178,12 +178,15 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
 static void radeon_evict_flags(struct ttm_buffer_object *bo,
                                struct ttm_placement *placement)
 {
+       static struct ttm_place placements = {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM
+       };
+
        struct radeon_bo *rbo;
-       static u32 placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
 
        if (!radeon_ttm_bo_is_radeon_bo(bo)) {
-               placement->fpfn = 0;
-               placement->lpfn = 0;
                placement->placement = &placements;
                placement->busy_placement = &placements;
                placement->num_placement = 1;
@@ -286,20 +289,20 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
        struct radeon_device *rdev;
        struct ttm_mem_reg *old_mem = &bo->mem;
        struct ttm_mem_reg tmp_mem;
-       u32 placements;
+       struct ttm_place placements;
        struct ttm_placement placement;
        int r;
 
        rdev = radeon_get_rdev(bo->bdev);
        tmp_mem = *new_mem;
        tmp_mem.mm_node = NULL;
-       placement.fpfn = 0;
-       placement.lpfn = 0;
        placement.num_placement = 1;
        placement.placement = &placements;
        placement.num_busy_placement = 1;
        placement.busy_placement = &placements;
-       placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
+       placements.fpfn = 0;
+       placements.lpfn = 0;
+       placements.flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
        r = ttm_bo_mem_space(bo, &placement, &tmp_mem,
                             interruptible, no_wait_gpu);
        if (unlikely(r)) {
@@ -334,19 +337,19 @@ static int radeon_move_ram_vram(struct ttm_buffer_object *bo,
        struct ttm_mem_reg *old_mem = &bo->mem;
        struct ttm_mem_reg tmp_mem;
        struct ttm_placement placement;
-       u32 placements;
+       struct ttm_place placements;
        int r;
 
        rdev = radeon_get_rdev(bo->bdev);
        tmp_mem = *new_mem;
        tmp_mem.mm_node = NULL;
-       placement.fpfn = 0;
-       placement.lpfn = 0;
        placement.num_placement = 1;
        placement.placement = &placements;
        placement.num_busy_placement = 1;
        placement.busy_placement = &placements;
-       placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
+       placements.fpfn = 0;
+       placements.lpfn = 0;
+       placements.flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
        r = ttm_bo_mem_space(bo, &placement, &tmp_mem,
                             interruptible, no_wait_gpu);
        if (unlikely(r)) {
index 341848a143761dd8236edc7862f79482d5d2d19d..25c8a1fd152c4b33600ec951b60d529721474118 100644 (file)
@@ -233,8 +233,12 @@ int radeon_uvd_resume(struct radeon_device *rdev)
 
 void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo)
 {
-       rbo->placement.fpfn = 0 >> PAGE_SHIFT;
-       rbo->placement.lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
+       int i;
+
+       for (i = 0; i < rbo->placement.num_placement; ++i) {
+               rbo->placements[i].fpfn = 0 >> PAGE_SHIFT;
+               rbo->placements[i].lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
+       }
 }
 
 void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
index 3da89d5dab60493ebc0b06811cab2800c266967e..b992ec3c318a2bb7ddb0ca5064d374186cb6bbd6 100644 (file)
@@ -53,12 +53,13 @@ static struct attribute ttm_bo_count = {
        .mode = S_IRUGO
 };
 
-static inline int ttm_mem_type_from_flags(uint32_t flags, uint32_t *mem_type)
+static inline int ttm_mem_type_from_place(const struct ttm_place *place,
+                                         uint32_t *mem_type)
 {
        int i;
 
        for (i = 0; i <= TTM_PL_PRIV5; i++)
-               if (flags & (1 << i)) {
+               if (place->flags & (1 << i)) {
                        *mem_type = i;
                        return 0;
                }
@@ -89,12 +90,12 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo,
               bo, bo->mem.num_pages, bo->mem.size >> 10,
               bo->mem.size >> 20);
        for (i = 0; i < placement->num_placement; i++) {
-               ret = ttm_mem_type_from_flags(placement->placement[i],
+               ret = ttm_mem_type_from_place(&placement->placement[i],
                                                &mem_type);
                if (ret)
                        return;
                pr_err("  placement[%d]=0x%08X (%d)\n",
-                      i, placement->placement[i], mem_type);
+                      i, placement->placement[i].flags, mem_type);
                ttm_mem_type_debug(bo->bdev, mem_type);
        }
 }
@@ -685,8 +686,6 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
        evict_mem.bus.io_reserved_vm = false;
        evict_mem.bus.io_reserved_count = 0;
 
-       placement.fpfn = 0;
-       placement.lpfn = 0;
        placement.num_placement = 0;
        placement.num_busy_placement = 0;
        bdev->driver->evict_flags(bo, &placement);
@@ -774,7 +773,7 @@ EXPORT_SYMBOL(ttm_bo_mem_put);
  */
 static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
                                        uint32_t mem_type,
-                                       struct ttm_placement *placement,
+                                       const struct ttm_place *place,
                                        struct ttm_mem_reg *mem,
                                        bool interruptible,
                                        bool no_wait_gpu)
@@ -784,7 +783,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
        int ret;
 
        do {
-               ret = (*man->func->get_node)(man, bo, placement, 0, mem);
+               ret = (*man->func->get_node)(man, bo, place, mem);
                if (unlikely(ret != 0))
                        return ret;
                if (mem->mm_node)
@@ -827,18 +826,18 @@ static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man,
 
 static bool ttm_bo_mt_compatible(struct ttm_mem_type_manager *man,
                                 uint32_t mem_type,
-                                uint32_t proposed_placement,
+                                const struct ttm_place *place,
                                 uint32_t *masked_placement)
 {
        uint32_t cur_flags = ttm_bo_type_flags(mem_type);
 
-       if ((cur_flags & proposed_placement & TTM_PL_MASK_MEM) == 0)
+       if ((cur_flags & place->flags & TTM_PL_MASK_MEM) == 0)
                return false;
 
-       if ((proposed_placement & man->available_caching) == 0)
+       if ((place->flags & man->available_caching) == 0)
                return false;
 
-       cur_flags |= (proposed_placement & man->available_caching);
+       cur_flags |= (place->flags & man->available_caching);
 
        *masked_placement = cur_flags;
        return true;
@@ -869,15 +868,14 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 
        mem->mm_node = NULL;
        for (i = 0; i < placement->num_placement; ++i) {
-               ret = ttm_mem_type_from_flags(placement->placement[i],
-                                               &mem_type);
+               const struct ttm_place *place = &placement->placement[i];
+
+               ret = ttm_mem_type_from_place(place, &mem_type);
                if (ret)
                        return ret;
                man = &bdev->man[mem_type];
 
-               type_ok = ttm_bo_mt_compatible(man,
-                                               mem_type,
-                                               placement->placement[i],
+               type_ok = ttm_bo_mt_compatible(man, mem_type, place,
                                                &cur_flags);
 
                if (!type_ok)
@@ -889,7 +887,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                 * Use the access and other non-mapping-related flag bits from
                 * the memory placement flags to the current flags
                 */
-               ttm_flag_masked(&cur_flags, placement->placement[i],
+               ttm_flag_masked(&cur_flags, place->flags,
                                ~TTM_PL_MASK_MEMTYPE);
 
                if (mem_type == TTM_PL_SYSTEM)
@@ -897,8 +895,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 
                if (man->has_type && man->use_type) {
                        type_found = true;
-                       ret = (*man->func->get_node)(man, bo, placement,
-                                                    cur_flags, mem);
+                       ret = (*man->func->get_node)(man, bo, place, mem);
                        if (unlikely(ret))
                                return ret;
                }
@@ -916,17 +913,15 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                return -EINVAL;
 
        for (i = 0; i < placement->num_busy_placement; ++i) {
-               ret = ttm_mem_type_from_flags(placement->busy_placement[i],
-                                               &mem_type);
+               const struct ttm_place *place = &placement->busy_placement[i];
+
+               ret = ttm_mem_type_from_place(place, &mem_type);
                if (ret)
                        return ret;
                man = &bdev->man[mem_type];
                if (!man->has_type)
                        continue;
-               if (!ttm_bo_mt_compatible(man,
-                                               mem_type,
-                                               placement->busy_placement[i],
-                                               &cur_flags))
+               if (!ttm_bo_mt_compatible(man, mem_type, place, &cur_flags))
                        continue;
 
                cur_flags = ttm_bo_select_caching(man, bo->mem.placement,
@@ -935,7 +930,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                 * Use the access and other non-mapping-related flag bits from
                 * the memory placement flags to the current flags
                 */
-               ttm_flag_masked(&cur_flags, placement->busy_placement[i],
+               ttm_flag_masked(&cur_flags, place->flags,
                                ~TTM_PL_MASK_MEMTYPE);
 
                if (mem_type == TTM_PL_SYSTEM) {
@@ -945,7 +940,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
                        return 0;
                }
 
-               ret = ttm_bo_mem_force_space(bo, mem_type, placement, mem,
+               ret = ttm_bo_mem_force_space(bo, mem_type, place, mem,
                                                interruptible, no_wait_gpu);
                if (ret == 0 && mem->mm_node) {
                        mem->placement = cur_flags;
@@ -1006,20 +1001,27 @@ static bool ttm_bo_mem_compat(struct ttm_placement *placement,
 {
        int i;
 
-       if (mem->mm_node && placement->lpfn != 0 &&
-           (mem->start < placement->fpfn ||
-            mem->start + mem->num_pages > placement->lpfn))
-               return false;
-
        for (i = 0; i < placement->num_placement; i++) {
-               *new_flags = placement->placement[i];
+               const struct ttm_place *heap = &placement->placement[i];
+               if (mem->mm_node && heap->lpfn != 0 &&
+                   (mem->start < heap->fpfn ||
+                    mem->start + mem->num_pages > heap->lpfn))
+                       continue;
+
+               *new_flags = heap->flags;
                if ((*new_flags & mem->placement & TTM_PL_MASK_CACHING) &&
                    (*new_flags & mem->placement & TTM_PL_MASK_MEM))
                        return true;
        }
 
        for (i = 0; i < placement->num_busy_placement; i++) {
-               *new_flags = placement->busy_placement[i];
+               const struct ttm_place *heap = &placement->busy_placement[i];
+               if (mem->mm_node && heap->lpfn != 0 &&
+                   (mem->start < heap->fpfn ||
+                    mem->start + mem->num_pages > heap->lpfn))
+                       continue;
+
+               *new_flags = heap->flags;
                if ((*new_flags & mem->placement & TTM_PL_MASK_CACHING) &&
                    (*new_flags & mem->placement & TTM_PL_MASK_MEM))
                        return true;
@@ -1037,11 +1039,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
        uint32_t new_flags;
 
        lockdep_assert_held(&bo->resv->lock.base);
-       /* Check that range is valid */
-       if (placement->lpfn || placement->fpfn)
-               if (placement->fpfn > placement->lpfn ||
-                       (placement->lpfn - placement->fpfn) < bo->num_pages)
-                       return -EINVAL;
        /*
         * Check whether we need to move buffer.
         */
@@ -1070,15 +1067,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 }
 EXPORT_SYMBOL(ttm_bo_validate);
 
-int ttm_bo_check_placement(struct ttm_buffer_object *bo,
-                               struct ttm_placement *placement)
-{
-       BUG_ON((placement->fpfn || placement->lpfn) &&
-              (bo->mem.num_pages > (placement->lpfn - placement->fpfn)));
-
-       return 0;
-}
-
 int ttm_bo_init(struct ttm_bo_device *bdev,
                struct ttm_buffer_object *bo,
                unsigned long size,
@@ -1147,15 +1135,12 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
        atomic_inc(&bo->glob->bo_count);
        drm_vma_node_reset(&bo->vma_node);
 
-       ret = ttm_bo_check_placement(bo, placement);
-
        /*
         * For ttm_bo_type_device buffers, allocate
         * address space from the device.
         */
-       if (likely(!ret) &&
-           (bo->type == ttm_bo_type_device ||
-            bo->type == ttm_bo_type_sg))
+       if (bo->type == ttm_bo_type_device ||
+           bo->type == ttm_bo_type_sg)
                ret = drm_vma_offset_add(&bdev->vma_manager, &bo->vma_node,
                                         bo->mem.num_pages);
 
index 9e103a4875c820d07d8a99484a865e40f9ec3850..964387fc5c8f860544704ae3ce21d50084448361 100644 (file)
@@ -49,8 +49,7 @@ struct ttm_range_manager {
 
 static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
                               struct ttm_buffer_object *bo,
-                              struct ttm_placement *placement,
-                              uint32_t flags,
+                              const struct ttm_place *place,
                               struct ttm_mem_reg *mem)
 {
        struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
@@ -60,7 +59,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
        unsigned long lpfn;
        int ret;
 
-       lpfn = placement->lpfn;
+       lpfn = place->lpfn;
        if (!lpfn)
                lpfn = man->size;
 
@@ -68,13 +67,13 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
        if (!node)
                return -ENOMEM;
 
-       if (flags & TTM_PL_FLAG_TOPDOWN)
+       if (place->flags & TTM_PL_FLAG_TOPDOWN)
                aflags = DRM_MM_CREATE_TOP;
 
        spin_lock(&rman->lock);
        ret = drm_mm_insert_node_in_range_generic(mm, node, mem->num_pages,
                                          mem->page_alignment, 0,
-                                         placement->fpfn, lpfn,
+                                         place->fpfn, lpfn,
                                          DRM_MM_SEARCH_BEST,
                                          aflags);
        spin_unlock(&rman->lock);
index 6327cfc36805f46364402a004ce76cd9bb19ecd5..37c093c0c7b899186df324b8355a177932ec1163 100644 (file)
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_page_alloc.h>
 
-static uint32_t vram_placement_flags = TTM_PL_FLAG_VRAM |
-       TTM_PL_FLAG_CACHED;
-
-static uint32_t vram_ne_placement_flags = TTM_PL_FLAG_VRAM |
-       TTM_PL_FLAG_CACHED |
-       TTM_PL_FLAG_NO_EVICT;
+static struct ttm_place vram_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED
+};
 
-static uint32_t sys_placement_flags = TTM_PL_FLAG_SYSTEM |
-       TTM_PL_FLAG_CACHED;
+static struct ttm_place vram_ne_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT
+};
 
-static uint32_t sys_ne_placement_flags = TTM_PL_FLAG_SYSTEM |
-       TTM_PL_FLAG_CACHED |
-       TTM_PL_FLAG_NO_EVICT;
+static struct ttm_place sys_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED
+};
 
-static uint32_t gmr_placement_flags = VMW_PL_FLAG_GMR |
-       TTM_PL_FLAG_CACHED;
+static struct ttm_place sys_ne_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT
+};
 
-static uint32_t gmr_ne_placement_flags = VMW_PL_FLAG_GMR |
-       TTM_PL_FLAG_CACHED |
-       TTM_PL_FLAG_NO_EVICT;
+static struct ttm_place gmr_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED
+};
 
-static uint32_t mob_placement_flags = VMW_PL_FLAG_MOB |
-       TTM_PL_FLAG_CACHED;
+static struct ttm_place gmr_ne_placement_flags = {
+       .fpfn = 0,
+       .lpfn = 0,
+       .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT
+};
 
-struct ttm_placement vmw_vram_placement = {
+static struct ttm_place mob_placement_flags = {
        .fpfn = 0,
        .lpfn = 0,
+       .flags = VMW_PL_FLAG_MOB | TTM_PL_FLAG_CACHED
+};
+
+struct ttm_placement vmw_vram_placement = {
        .num_placement = 1,
        .placement = &vram_placement_flags,
        .num_busy_placement = 1,
        .busy_placement = &vram_placement_flags
 };
 
-static uint32_t vram_gmr_placement_flags[] = {
-       TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED,
-       VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED
+static struct ttm_place vram_gmr_placement_flags[] = {
+       {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED
+       }
 };
 
-static uint32_t gmr_vram_placement_flags[] = {
-       VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED,
-       TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED
+static struct ttm_place gmr_vram_placement_flags[] = {
+       {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED
+       }
 };
 
 struct ttm_placement vmw_vram_gmr_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 2,
        .placement = vram_gmr_placement_flags,
        .num_busy_placement = 1,
        .busy_placement = &gmr_placement_flags
 };
 
-static uint32_t vram_gmr_ne_placement_flags[] = {
-       TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT,
-       VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT
+static struct ttm_place vram_gmr_ne_placement_flags[] = {
+       {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED |
+                        TTM_PL_FLAG_NO_EVICT
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED |
+                        TTM_PL_FLAG_NO_EVICT
+       }
 };
 
 struct ttm_placement vmw_vram_gmr_ne_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 2,
        .placement = vram_gmr_ne_placement_flags,
        .num_busy_placement = 1,
@@ -97,8 +132,6 @@ struct ttm_placement vmw_vram_gmr_ne_placement = {
 };
 
 struct ttm_placement vmw_vram_sys_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .placement = &vram_placement_flags,
        .num_busy_placement = 1,
@@ -106,8 +139,6 @@ struct ttm_placement vmw_vram_sys_placement = {
 };
 
 struct ttm_placement vmw_vram_ne_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .placement = &vram_ne_placement_flags,
        .num_busy_placement = 1,
@@ -115,8 +146,6 @@ struct ttm_placement vmw_vram_ne_placement = {
 };
 
 struct ttm_placement vmw_sys_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .placement = &sys_placement_flags,
        .num_busy_placement = 1,
@@ -124,24 +153,33 @@ struct ttm_placement vmw_sys_placement = {
 };
 
 struct ttm_placement vmw_sys_ne_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .placement = &sys_ne_placement_flags,
        .num_busy_placement = 1,
        .busy_placement = &sys_ne_placement_flags
 };
 
-static uint32_t evictable_placement_flags[] = {
-       TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED,
-       TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED,
-       VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED,
-       VMW_PL_FLAG_MOB | TTM_PL_FLAG_CACHED
+static struct ttm_place evictable_placement_flags[] = {
+       {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED
+       }, {
+               .fpfn = 0,
+               .lpfn = 0,
+               .flags = VMW_PL_FLAG_MOB | TTM_PL_FLAG_CACHED
+       }
 };
 
 struct ttm_placement vmw_evictable_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 4,
        .placement = evictable_placement_flags,
        .num_busy_placement = 1,
@@ -149,8 +187,6 @@ struct ttm_placement vmw_evictable_placement = {
 };
 
 struct ttm_placement vmw_srf_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .num_busy_placement = 2,
        .placement = &gmr_placement_flags,
@@ -158,8 +194,6 @@ struct ttm_placement vmw_srf_placement = {
 };
 
 struct ttm_placement vmw_mob_placement = {
-       .fpfn = 0,
-       .lpfn = 0,
        .num_placement = 1,
        .num_busy_placement = 1,
        .placement = &mob_placement_flags,
index ed1d51006ab1e3054dc8cab075db1b776d204cc7..914b375763dcaf753da1763bba14b1718f37fa9b 100644 (file)
@@ -198,13 +198,19 @@ int vmw_dmabuf_to_start_of_vram(struct vmw_private *dev_priv,
 {
        struct ttm_buffer_object *bo = &buf->base;
        struct ttm_placement placement;
+       struct ttm_place place;
        int ret = 0;
 
        if (pin)
-               placement = vmw_vram_ne_placement;
+               place = vmw_vram_ne_placement.placement[0];
        else
-               placement = vmw_vram_placement;
-       placement.lpfn = bo->num_pages;
+               place = vmw_vram_placement.placement[0];
+       place.lpfn = bo->num_pages;
+
+       placement.num_placement = 1;
+       placement.placement = &place;
+       placement.num_busy_placement = 1;
+       placement.busy_placement = &place;
 
        ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
        if (unlikely(ret != 0))
@@ -293,21 +299,23 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo,
  */
 void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin)
 {
-       uint32_t pl_flags;
+       struct ttm_place pl;
        struct ttm_placement placement;
        uint32_t old_mem_type = bo->mem.mem_type;
        int ret;
 
        lockdep_assert_held(&bo->resv->lock.base);
 
-       pl_flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB
+       pl.fpfn = 0;
+       pl.lpfn = 0;
+       pl.flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB
                | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED;
        if (pin)
-               pl_flags |= TTM_PL_FLAG_NO_EVICT;
+               pl.flags |= TTM_PL_FLAG_NO_EVICT;
 
        memset(&placement, 0, sizeof(placement));
        placement.num_placement = 1;
-       placement.placement = &pl_flags;
+       placement.placement = &pl;
 
        ret = ttm_bo_validate(bo, &placement, false, true);
 
index b031b48dbb3cdcbbd48824096ac82650aa08ec87..0a474f391fad0157d8a51e5aa2e50d6c4aec69ec 100644 (file)
@@ -374,10 +374,16 @@ static int vmw_fb_create_bo(struct vmw_private *vmw_priv,
                            size_t size, struct vmw_dma_buffer **out)
 {
        struct vmw_dma_buffer *vmw_bo;
-       struct ttm_placement ne_placement = vmw_vram_ne_placement;
+       struct ttm_place ne_place = vmw_vram_ne_placement.placement[0];
+       struct ttm_placement ne_placement;
        int ret;
 
-       ne_placement.lpfn = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       ne_placement.num_placement = 1;
+       ne_placement.placement = &ne_place;
+       ne_placement.num_busy_placement = 1;
+       ne_placement.busy_placement = &ne_place;
+
+       ne_place.lpfn = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
        (void) ttm_write_lock(&vmw_priv->reservation_sem, false);
 
index 26f8bdde3529b8a5b222a52aa34ebc8da185232a..170b61be1e4ece3069a9f9c20e7c90d1f9558ae9 100644 (file)
@@ -46,8 +46,7 @@ struct vmwgfx_gmrid_man {
 
 static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
                                  struct ttm_buffer_object *bo,
-                                 struct ttm_placement *placement,
-                                 uint32_t flags,
+                                 const struct ttm_place *place,
                                  struct ttm_mem_reg *mem)
 {
        struct vmwgfx_gmrid_man *gman =
index 7526c5bf56105e95e6e614f4ea1517f1ac6ee64d..e3d39c80a091450a490005ff1aab665735cc6a40 100644 (file)
@@ -45,12 +45,24 @@ struct ttm_bo_device;
 
 struct drm_mm_node;
 
+/**
+ * struct ttm_place
+ *
+ * @fpfn:      first valid page frame number to put the object
+ * @lpfn:      last valid page frame number to put the object
+ * @flags:     memory domain and caching flags for the object
+ *
+ * Structure indicating a possible place to put an object.
+ */
+struct ttm_place {
+       unsigned        fpfn;
+       unsigned        lpfn;
+       uint32_t        flags;
+};
 
 /**
  * struct ttm_placement
  *
- * @fpfn:              first valid page frame number to put the object
- * @lpfn:              last valid page frame number to put the object
  * @num_placement:     number of preferred placements
  * @placement:         preferred placements
  * @num_busy_placement:        number of preferred placements when need to evict buffer
@@ -59,12 +71,10 @@ struct drm_mm_node;
  * Structure indicating the placement you request for an object.
  */
 struct ttm_placement {
-       unsigned        fpfn;
-       unsigned        lpfn;
-       unsigned        num_placement;
-       const uint32_t  *placement;
-       unsigned        num_busy_placement;
-       const uint32_t  *busy_placement;
+       unsigned                num_placement;
+       const struct ttm_place  *placement;
+       unsigned                num_busy_placement;
+       const struct ttm_place  *busy_placement;
 };
 
 /**
@@ -518,20 +528,6 @@ extern int ttm_bo_create(struct ttm_bo_device *bdev,
                                struct file *persistent_swap_storage,
                                struct ttm_buffer_object **p_bo);
 
-/**
- * ttm_bo_check_placement
- *
- * @bo:                the buffer object.
- * @placement: placements
- *
- * Performs minimal validity checking on an intended change of
- * placement flags.
- * Returns
- * -EINVAL: Intended change is invalid or not allowed.
- */
-extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
-                                       struct ttm_placement *placement);
-
 /**
  * ttm_bo_init_mm
  *
index 1d9f0f1ff52d2c01cd4b42cc4113a70a90ffa0a8..5c8bb5699a6f35a520949c793069d41ed20d4364 100644 (file)
@@ -208,8 +208,7 @@ struct ttm_mem_type_manager_func {
         */
        int  (*get_node)(struct ttm_mem_type_manager *man,
                         struct ttm_buffer_object *bo,
-                        struct ttm_placement *placement,
-                        uint32_t flags,
+                        const struct ttm_place *place,
                         struct ttm_mem_reg *mem);
 
        /**