drm/vmwgfx: switch the TTM backends to self alloc
Similar to the TTM range manager. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20210602100914.46246-9-christian.koenig@amd.com
This commit is contained in:
parent
beb4c86521
commit
d3bcb4b02f
2 changed files with 31 additions and 24 deletions
|
@ -57,6 +57,12 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
|
||||||
struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
|
struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
mem->mm_node = kmalloc(sizeof(*mem), GFP_KERNEL);
|
||||||
|
if (!mem->mm_node)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
ttm_resource_init(bo, place, mem->mm_node);
|
||||||
|
|
||||||
id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
|
id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
return id;
|
return id;
|
||||||
|
@ -87,13 +93,11 @@ static void vmw_gmrid_man_put_node(struct ttm_resource_manager *man,
|
||||||
{
|
{
|
||||||
struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
|
struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
|
||||||
|
|
||||||
if (mem->mm_node) {
|
ida_free(&gman->gmr_ida, mem->start);
|
||||||
ida_free(&gman->gmr_ida, mem->start);
|
spin_lock(&gman->lock);
|
||||||
spin_lock(&gman->lock);
|
gman->used_gmr_pages -= mem->num_pages;
|
||||||
gman->used_gmr_pages -= mem->num_pages;
|
spin_unlock(&gman->lock);
|
||||||
spin_unlock(&gman->lock);
|
kfree(mem->mm_node);
|
||||||
mem->mm_node = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct ttm_resource_manager_func vmw_gmrid_manager_func;
|
static const struct ttm_resource_manager_func vmw_gmrid_manager_func;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "vmwgfx_drv.h"
|
#include "vmwgfx_drv.h"
|
||||||
#include <drm/ttm/ttm_bo_driver.h>
|
#include <drm/ttm/ttm_bo_driver.h>
|
||||||
#include <drm/ttm/ttm_placement.h>
|
#include <drm/ttm/ttm_placement.h>
|
||||||
|
#include <drm/ttm/ttm_range_manager.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct vmw_thp_manager - Range manager implementing huge page alignment
|
* struct vmw_thp_manager - Range manager implementing huge page alignment
|
||||||
|
@ -54,16 +55,18 @@ static int vmw_thp_get_node(struct ttm_resource_manager *man,
|
||||||
{
|
{
|
||||||
struct vmw_thp_manager *rman = to_thp_manager(man);
|
struct vmw_thp_manager *rman = to_thp_manager(man);
|
||||||
struct drm_mm *mm = &rman->mm;
|
struct drm_mm *mm = &rman->mm;
|
||||||
struct drm_mm_node *node;
|
struct ttm_range_mgr_node *node;
|
||||||
unsigned long align_pages;
|
unsigned long align_pages;
|
||||||
unsigned long lpfn;
|
unsigned long lpfn;
|
||||||
enum drm_mm_insert_mode mode = DRM_MM_INSERT_BEST;
|
enum drm_mm_insert_mode mode = DRM_MM_INSERT_BEST;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
node = kzalloc(sizeof(*node), GFP_KERNEL);
|
node = kzalloc(struct_size(node, mm_nodes, 1), GFP_KERNEL);
|
||||||
if (!node)
|
if (!node)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
ttm_resource_init(bo, place, &node->base);
|
||||||
|
|
||||||
lpfn = place->lpfn;
|
lpfn = place->lpfn;
|
||||||
if (!lpfn)
|
if (!lpfn)
|
||||||
lpfn = man->size;
|
lpfn = man->size;
|
||||||
|
@ -76,8 +79,9 @@ static int vmw_thp_get_node(struct ttm_resource_manager *man,
|
||||||
if (IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) {
|
if (IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) {
|
||||||
align_pages = (HPAGE_PUD_SIZE >> PAGE_SHIFT);
|
align_pages = (HPAGE_PUD_SIZE >> PAGE_SHIFT);
|
||||||
if (mem->num_pages >= align_pages) {
|
if (mem->num_pages >= align_pages) {
|
||||||
ret = vmw_thp_insert_aligned(bo, mm, node, align_pages,
|
ret = vmw_thp_insert_aligned(bo, mm, &node->mm_nodes[0],
|
||||||
place, mem, lpfn, mode);
|
align_pages, place, mem,
|
||||||
|
lpfn, mode);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
goto found_unlock;
|
goto found_unlock;
|
||||||
}
|
}
|
||||||
|
@ -85,14 +89,15 @@ static int vmw_thp_get_node(struct ttm_resource_manager *man,
|
||||||
|
|
||||||
align_pages = (HPAGE_PMD_SIZE >> PAGE_SHIFT);
|
align_pages = (HPAGE_PMD_SIZE >> PAGE_SHIFT);
|
||||||
if (mem->num_pages >= align_pages) {
|
if (mem->num_pages >= align_pages) {
|
||||||
ret = vmw_thp_insert_aligned(bo, mm, node, align_pages, place,
|
ret = vmw_thp_insert_aligned(bo, mm, &node->mm_nodes[0],
|
||||||
mem, lpfn, mode);
|
align_pages, place, mem, lpfn,
|
||||||
|
mode);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
goto found_unlock;
|
goto found_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = drm_mm_insert_node_in_range(mm, node, mem->num_pages,
|
ret = drm_mm_insert_node_in_range(mm, &node->mm_nodes[0],
|
||||||
bo->page_alignment, 0,
|
mem->num_pages, bo->page_alignment, 0,
|
||||||
place->fpfn, lpfn, mode);
|
place->fpfn, lpfn, mode);
|
||||||
found_unlock:
|
found_unlock:
|
||||||
spin_unlock(&rman->lock);
|
spin_unlock(&rman->lock);
|
||||||
|
@ -100,8 +105,8 @@ found_unlock:
|
||||||
if (unlikely(ret)) {
|
if (unlikely(ret)) {
|
||||||
kfree(node);
|
kfree(node);
|
||||||
} else {
|
} else {
|
||||||
mem->mm_node = node;
|
mem->mm_node = &node->mm_nodes[0];
|
||||||
mem->start = node->start;
|
mem->start = node->mm_nodes[0].start;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -113,15 +118,13 @@ static void vmw_thp_put_node(struct ttm_resource_manager *man,
|
||||||
struct ttm_resource *mem)
|
struct ttm_resource *mem)
|
||||||
{
|
{
|
||||||
struct vmw_thp_manager *rman = to_thp_manager(man);
|
struct vmw_thp_manager *rman = to_thp_manager(man);
|
||||||
|
struct ttm_range_mgr_node * node = mem->mm_node;
|
||||||
|
|
||||||
if (mem->mm_node) {
|
spin_lock(&rman->lock);
|
||||||
spin_lock(&rman->lock);
|
drm_mm_remove_node(&node->mm_nodes[0]);
|
||||||
drm_mm_remove_node(mem->mm_node);
|
spin_unlock(&rman->lock);
|
||||||
spin_unlock(&rman->lock);
|
|
||||||
|
|
||||||
kfree(mem->mm_node);
|
kfree(node);
|
||||||
mem->mm_node = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int vmw_thp_init(struct vmw_private *dev_priv)
|
int vmw_thp_init(struct vmw_private *dev_priv)
|
||||||
|
|
Loading…
Add table
Reference in a new issue