Commit 9d6f4484 authored by Gerd Hoffmann's avatar Gerd Hoffmann

drm/ttm: turn ttm_bo_device.vma_manager into a pointer

Rename the embedded struct vma_offset_manager, new name is _vma_manager.
ttm_bo_device.vma_manager changed to a pointer.

The ttm_bo_device_init() function gets an additional vma_manager
argument which allows to initialize ttm with a different vma manager.
When passing NULL the embedded _vma_manager is used.

All callers are updated to pass NULL, so the behavior doesn't change.
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190905070509.22407-2-kraxel@redhat.com
parent 4f7f1973
...@@ -1728,6 +1728,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) ...@@ -1728,6 +1728,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
r = ttm_bo_device_init(&adev->mman.bdev, r = ttm_bo_device_init(&adev->mman.bdev,
&amdgpu_bo_driver, &amdgpu_bo_driver,
adev->ddev->anon_inode->i_mapping, adev->ddev->anon_inode->i_mapping,
NULL,
adev->need_dma32); adev->need_dma32);
if (r) { if (r) {
DRM_ERROR("failed initializing buffer object driver(%d).\n", r); DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
......
...@@ -228,6 +228,7 @@ int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, ...@@ -228,6 +228,7 @@ int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
ret = ttm_bo_device_init(&vmm->bdev, &bo_driver, ret = ttm_bo_device_init(&vmm->bdev, &bo_driver,
dev->anon_inode->i_mapping, dev->anon_inode->i_mapping,
NULL,
true); true);
if (ret) if (ret)
return ret; return ret;
......
...@@ -236,6 +236,7 @@ nouveau_ttm_init(struct nouveau_drm *drm) ...@@ -236,6 +236,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
ret = ttm_bo_device_init(&drm->ttm.bdev, ret = ttm_bo_device_init(&drm->ttm.bdev,
&nouveau_bo_driver, &nouveau_bo_driver,
dev->anon_inode->i_mapping, dev->anon_inode->i_mapping,
NULL,
drm->client.mmu.dmabits <= 32 ? true : false); drm->client.mmu.dmabits <= 32 ? true : false);
if (ret) { if (ret) {
NV_ERROR(drm, "error initialising bo driver, %d\n", ret); NV_ERROR(drm, "error initialising bo driver, %d\n", ret);
......
...@@ -325,6 +325,7 @@ int qxl_ttm_init(struct qxl_device *qdev) ...@@ -325,6 +325,7 @@ int qxl_ttm_init(struct qxl_device *qdev)
r = ttm_bo_device_init(&qdev->mman.bdev, r = ttm_bo_device_init(&qdev->mman.bdev,
&qxl_bo_driver, &qxl_bo_driver,
qdev->ddev.anon_inode->i_mapping, qdev->ddev.anon_inode->i_mapping,
NULL,
false); false);
if (r) { if (r) {
DRM_ERROR("failed initializing buffer object driver(%d).\n", r); DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
......
...@@ -794,6 +794,7 @@ int radeon_ttm_init(struct radeon_device *rdev) ...@@ -794,6 +794,7 @@ int radeon_ttm_init(struct radeon_device *rdev)
r = ttm_bo_device_init(&rdev->mman.bdev, r = ttm_bo_device_init(&rdev->mman.bdev,
&radeon_bo_driver, &radeon_bo_driver,
rdev->ddev->anon_inode->i_mapping, rdev->ddev->anon_inode->i_mapping,
NULL,
rdev->need_dma32); rdev->need_dma32);
if (r) { if (r) {
DRM_ERROR("failed initializing buffer object driver(%d).\n", r); DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
......
...@@ -672,7 +672,7 @@ static void ttm_bo_release(struct kref *kref) ...@@ -672,7 +672,7 @@ static void ttm_bo_release(struct kref *kref)
struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_device *bdev = bo->bdev;
struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type]; struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
drm_vma_offset_remove(&bdev->vma_manager, &bo->base.vma_node); drm_vma_offset_remove(bdev->vma_manager, &bo->base.vma_node);
ttm_mem_io_lock(man, false); ttm_mem_io_lock(man, false);
ttm_mem_io_free_vm(bo); ttm_mem_io_free_vm(bo);
ttm_mem_io_unlock(man); ttm_mem_io_unlock(man);
...@@ -1353,7 +1353,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, ...@@ -1353,7 +1353,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
*/ */
if (bo->type == ttm_bo_type_device || if (bo->type == ttm_bo_type_device ||
bo->type == ttm_bo_type_sg) bo->type == ttm_bo_type_sg)
ret = drm_vma_offset_add(&bdev->vma_manager, &bo->base.vma_node, ret = drm_vma_offset_add(bdev->vma_manager, &bo->base.vma_node,
bo->mem.num_pages); bo->mem.num_pages);
/* passed reservation objects should already be locked, /* passed reservation objects should already be locked,
...@@ -1704,7 +1704,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) ...@@ -1704,7 +1704,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
pr_debug("Swap list %d was clean\n", i); pr_debug("Swap list %d was clean\n", i);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
drm_vma_offset_manager_destroy(&bdev->vma_manager); drm_vma_offset_manager_destroy(&bdev->_vma_manager);
if (!ret) if (!ret)
ttm_bo_global_release(); ttm_bo_global_release();
...@@ -1716,11 +1716,15 @@ EXPORT_SYMBOL(ttm_bo_device_release); ...@@ -1716,11 +1716,15 @@ EXPORT_SYMBOL(ttm_bo_device_release);
int ttm_bo_device_init(struct ttm_bo_device *bdev, int ttm_bo_device_init(struct ttm_bo_device *bdev,
struct ttm_bo_driver *driver, struct ttm_bo_driver *driver,
struct address_space *mapping, struct address_space *mapping,
struct drm_vma_offset_manager *vma_manager,
bool need_dma32) bool need_dma32)
{ {
struct ttm_bo_global *glob = &ttm_bo_glob; struct ttm_bo_global *glob = &ttm_bo_glob;
int ret; int ret;
if (!vma_manager)
vma_manager = &bdev->_vma_manager;
ret = ttm_bo_global_init(); ret = ttm_bo_global_init();
if (ret) if (ret)
return ret; return ret;
...@@ -1737,7 +1741,8 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, ...@@ -1737,7 +1741,8 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out_no_sys; goto out_no_sys;
drm_vma_offset_manager_init(&bdev->vma_manager, bdev->vma_manager = vma_manager;
drm_vma_offset_manager_init(&bdev->_vma_manager,
DRM_FILE_PAGE_OFFSET_START, DRM_FILE_PAGE_OFFSET_START,
DRM_FILE_PAGE_OFFSET_SIZE); DRM_FILE_PAGE_OFFSET_SIZE);
INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue); INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue);
......
...@@ -409,16 +409,16 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev, ...@@ -409,16 +409,16 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
struct drm_vma_offset_node *node; struct drm_vma_offset_node *node;
struct ttm_buffer_object *bo = NULL; struct ttm_buffer_object *bo = NULL;
drm_vma_offset_lock_lookup(&bdev->vma_manager); drm_vma_offset_lock_lookup(bdev->vma_manager);
node = drm_vma_offset_lookup_locked(&bdev->vma_manager, offset, pages); node = drm_vma_offset_lookup_locked(bdev->vma_manager, offset, pages);
if (likely(node)) { if (likely(node)) {
bo = container_of(node, struct ttm_buffer_object, bo = container_of(node, struct ttm_buffer_object,
base.vma_node); base.vma_node);
bo = ttm_bo_get_unless_zero(bo); bo = ttm_bo_get_unless_zero(bo);
} }
drm_vma_offset_unlock_lookup(&bdev->vma_manager); drm_vma_offset_unlock_lookup(bdev->vma_manager);
if (!bo) if (!bo)
pr_err("Could not find buffer object to map\n"); pr_err("Could not find buffer object to map\n");
......
...@@ -830,6 +830,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) ...@@ -830,6 +830,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
ret = ttm_bo_device_init(&dev_priv->bdev, ret = ttm_bo_device_init(&dev_priv->bdev,
&vmw_bo_driver, &vmw_bo_driver,
dev->anon_inode->i_mapping, dev->anon_inode->i_mapping,
NULL,
false); false);
if (unlikely(ret != 0)) { if (unlikely(ret != 0)) {
DRM_ERROR("Failed initializing TTM buffer object driver.\n"); DRM_ERROR("Failed initializing TTM buffer object driver.\n");
......
...@@ -441,7 +441,8 @@ extern struct ttm_bo_global { ...@@ -441,7 +441,8 @@ extern struct ttm_bo_global {
* *
* @driver: Pointer to a struct ttm_bo_driver struct setup by the driver. * @driver: Pointer to a struct ttm_bo_driver struct setup by the driver.
* @man: An array of mem_type_managers. * @man: An array of mem_type_managers.
* @vma_manager: Address space manager * @vma_manager: Address space manager (pointer)
* @_vma_manager: Address space manager (enbedded)
* lru_lock: Spinlock that protects the buffer+device lru lists and * lru_lock: Spinlock that protects the buffer+device lru lists and
* ddestroy lists. * ddestroy lists.
* @dev_mapping: A pointer to the struct address_space representing the * @dev_mapping: A pointer to the struct address_space representing the
...@@ -464,7 +465,8 @@ struct ttm_bo_device { ...@@ -464,7 +465,8 @@ struct ttm_bo_device {
/* /*
* Protected by internal locks. * Protected by internal locks.
*/ */
struct drm_vma_offset_manager vma_manager; struct drm_vma_offset_manager *vma_manager;
struct drm_vma_offset_manager _vma_manager;
/* /*
* Protected by the global:lru lock. * Protected by the global:lru lock.
...@@ -585,6 +587,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev); ...@@ -585,6 +587,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev);
* @glob: A pointer to an initialized struct ttm_bo_global. * @glob: A pointer to an initialized struct ttm_bo_global.
* @driver: A pointer to a struct ttm_bo_driver set up by the caller. * @driver: A pointer to a struct ttm_bo_driver set up by the caller.
* @mapping: The address space to use for this bo. * @mapping: The address space to use for this bo.
* @vma_manager: A pointer to a vma manager or NULL.
* @file_page_offset: Offset into the device address space that is available * @file_page_offset: Offset into the device address space that is available
* for buffer data. This ensures compatibility with other users of the * for buffer data. This ensures compatibility with other users of the
* address space. * address space.
...@@ -596,6 +599,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev); ...@@ -596,6 +599,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev);
int ttm_bo_device_init(struct ttm_bo_device *bdev, int ttm_bo_device_init(struct ttm_bo_device *bdev,
struct ttm_bo_driver *driver, struct ttm_bo_driver *driver,
struct address_space *mapping, struct address_space *mapping,
struct drm_vma_offset_manager *vma_manager,
bool need_dma32); bool need_dma32);
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment