All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Alex Deucher <alexdeucher@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics <intel-gfx@lists.freedesktop.org>,
	DRI <dri-devel@lists.freedesktop.org>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Andrey Grodzovsky" <andrey.grodzovsky@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Linux Next Mailing List" <linux-next@vger.kernel.org>
Subject: linux-next: manual merge of the amdgpu tree with the drm-misc tree
Date: Fri, 21 May 2021 11:38:27 +1000	[thread overview]
Message-ID: <20210521113827.675898b8@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 7689 bytes --]

Hi all,

Today's linux-next merge of the amdgpu tree got a conflict in:

  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

between commit:

  35bba8313b95 ("drm/amdgpu: Convert driver sysfs attributes to static attributes")

from the drm-misc tree and commit:

  589939d40116 ("drm/amdgpu: fix coding style and documentation in amdgpu_vram_mgr.c")

from the amdgpu tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index a99d196b05df,a52e17ed3df6..000000000000
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@@ -162,74 -181,6 +181,10 @@@ static struct attribute *amdgpu_vram_mg
  	NULL
  };
  
 +const struct attribute_group amdgpu_vram_mgr_attr_group = {
 +	.attrs = amdgpu_vram_mgr_attributes
 +};
 +
- static const struct ttm_resource_manager_func amdgpu_vram_mgr_func;
- 
- /**
-  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Allocate and initialize the VRAM manager.
-  */
- int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 
- 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
- 
- 	man->func = &amdgpu_vram_mgr_func;
- 
- 	drm_mm_init(&mgr->mm, 0, man->size);
- 	spin_lock_init(&mgr->lock);
- 	INIT_LIST_HEAD(&mgr->reservations_pending);
- 	INIT_LIST_HEAD(&mgr->reserved_pages);
- 
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
- 	ttm_resource_manager_set_used(man, true);
- 	return 0;
- }
- 
- /**
-  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
-  * allocated inside it.
-  */
- void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 	int ret;
- 	struct amdgpu_vram_reservation *rsv, *temp;
- 
- 	ttm_resource_manager_set_used(man, false);
- 
- 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
- 	if (ret)
- 		return;
- 
- 	spin_lock(&mgr->lock);
- 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
- 		kfree(rsv);
- 
- 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
- 		drm_mm_remove_node(&rsv->mm_node);
- 		kfree(rsv);
- 	}
- 	drm_mm_takedown(&mgr->mm);
- 	spin_unlock(&mgr->lock);
- 
- 	ttm_resource_manager_cleanup(man);
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
- }
- 
  /**
   * amdgpu_vram_mgr_vis_size - Calculate visible node size
   *
@@@ -444,10 -396,10 +400,10 @@@ static int amdgpu_vram_mgr_new(struct t
  		pages_per_node = HPAGE_PMD_NR;
  #else
  		/* default to 2MB */
- 		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+ 		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
  #endif
- 		pages_per_node = max((uint32_t)pages_per_node,
- 				     tbo->page_alignment);
+ 		pages_per_node = max_t(uint32_t, pages_per_node,
 -				       mem->page_alignment);
++				       tbo->page_alignment);
  		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
  	}
  
@@@ -465,38 -417,29 +421,29 @@@
  	mem->start = 0;
  	pages_left = mem->num_pages;
  
- 	spin_lock(&mgr->lock);
- 	for (i = 0; pages_left >= pages_per_node; ++i) {
- 		unsigned long pages = rounddown_pow_of_two(pages_left);
- 
- 		/* Limit maximum size to 2GB due to SG table limitations */
- 		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
- 
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
- 						pages_per_node, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
- 			break;
- 
- 		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
- 		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
- 		pages_left -= pages;
- 	}
+ 	/* Limit maximum size to 2GB due to SG table limitations */
+ 	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
  
- 	for (; pages_left; ++i) {
- 		unsigned long pages = min(pages_left, pages_per_node);
+ 	i = 0;
+ 	spin_lock(&mgr->lock);
+ 	while (pages_left) {
 -		uint32_t alignment = mem->page_alignment;
 +		uint32_t alignment = tbo->page_alignment;
  
- 		if (pages == pages_per_node)
+ 		if (pages >= pages_per_node)
  			alignment = pages_per_node;
  
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i],
- 						pages, alignment, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
+ 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+ 						0, place->fpfn, lpfn, mode);
+ 		if (unlikely(r)) {
+ 			if (pages > pages_per_node) {
+ 				if (is_power_of_2(pages))
+ 					pages = pages / 2;
+ 				else
+ 					pages = rounddown_pow_of_two(pages);
+ 				continue;
+ 			}
  			goto error;
+ 		}
  
  		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
  		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
@@@ -724,3 -672,73 +676,65 @@@ static const struct ttm_resource_manage
  	.free	= amdgpu_vram_mgr_del,
  	.debug	= amdgpu_vram_mgr_debug
  };
+ 
+ /**
+  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Allocate and initialize the VRAM manager.
+  */
+ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
 -	int ret;
+ 
+ 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
+ 
+ 	man->func = &amdgpu_vram_mgr_func;
+ 
+ 	drm_mm_init(&mgr->mm, 0, man->size);
+ 	spin_lock_init(&mgr->lock);
+ 	INIT_LIST_HEAD(&mgr->reservations_pending);
+ 	INIT_LIST_HEAD(&mgr->reserved_pages);
+ 
 -	/* Add the two VRAM-related sysfs files */
 -	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -	if (ret)
 -		DRM_ERROR("Failed to register sysfs\n");
 -
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
+ 	ttm_resource_manager_set_used(man, true);
+ 	return 0;
+ }
+ 
+ /**
+  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
+  * allocated inside it.
+  */
+ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
+ 	int ret;
+ 	struct amdgpu_vram_reservation *rsv, *temp;
+ 
+ 	ttm_resource_manager_set_used(man, false);
+ 
+ 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
+ 	if (ret)
+ 		return;
+ 
+ 	spin_lock(&mgr->lock);
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
+ 		kfree(rsv);
+ 
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
+ 		drm_mm_remove_node(&rsv->mm_node);
+ 		kfree(rsv);
+ 	}
+ 	drm_mm_takedown(&mgr->mm);
+ 	spin_unlock(&mgr->lock);
+ 
 -	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -
+ 	ttm_resource_manager_cleanup(man);
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
+ }

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Alex Deucher <alexdeucher@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics <intel-gfx@lists.freedesktop.org>,
	DRI <dri-devel@lists.freedesktop.org>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Linux Next Mailing List" <linux-next@vger.kernel.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: linux-next: manual merge of the amdgpu tree with the drm-misc tree
Date: Fri, 21 May 2021 11:38:27 +1000	[thread overview]
Message-ID: <20210521113827.675898b8@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 7689 bytes --]

Hi all,

Today's linux-next merge of the amdgpu tree got a conflict in:

  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

between commit:

  35bba8313b95 ("drm/amdgpu: Convert driver sysfs attributes to static attributes")

from the drm-misc tree and commit:

  589939d40116 ("drm/amdgpu: fix coding style and documentation in amdgpu_vram_mgr.c")

from the amdgpu tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index a99d196b05df,a52e17ed3df6..000000000000
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@@ -162,74 -181,6 +181,10 @@@ static struct attribute *amdgpu_vram_mg
  	NULL
  };
  
 +const struct attribute_group amdgpu_vram_mgr_attr_group = {
 +	.attrs = amdgpu_vram_mgr_attributes
 +};
 +
- static const struct ttm_resource_manager_func amdgpu_vram_mgr_func;
- 
- /**
-  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Allocate and initialize the VRAM manager.
-  */
- int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 
- 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
- 
- 	man->func = &amdgpu_vram_mgr_func;
- 
- 	drm_mm_init(&mgr->mm, 0, man->size);
- 	spin_lock_init(&mgr->lock);
- 	INIT_LIST_HEAD(&mgr->reservations_pending);
- 	INIT_LIST_HEAD(&mgr->reserved_pages);
- 
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
- 	ttm_resource_manager_set_used(man, true);
- 	return 0;
- }
- 
- /**
-  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
-  * allocated inside it.
-  */
- void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 	int ret;
- 	struct amdgpu_vram_reservation *rsv, *temp;
- 
- 	ttm_resource_manager_set_used(man, false);
- 
- 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
- 	if (ret)
- 		return;
- 
- 	spin_lock(&mgr->lock);
- 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
- 		kfree(rsv);
- 
- 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
- 		drm_mm_remove_node(&rsv->mm_node);
- 		kfree(rsv);
- 	}
- 	drm_mm_takedown(&mgr->mm);
- 	spin_unlock(&mgr->lock);
- 
- 	ttm_resource_manager_cleanup(man);
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
- }
- 
  /**
   * amdgpu_vram_mgr_vis_size - Calculate visible node size
   *
@@@ -444,10 -396,10 +400,10 @@@ static int amdgpu_vram_mgr_new(struct t
  		pages_per_node = HPAGE_PMD_NR;
  #else
  		/* default to 2MB */
- 		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+ 		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
  #endif
- 		pages_per_node = max((uint32_t)pages_per_node,
- 				     tbo->page_alignment);
+ 		pages_per_node = max_t(uint32_t, pages_per_node,
 -				       mem->page_alignment);
++				       tbo->page_alignment);
  		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
  	}
  
@@@ -465,38 -417,29 +421,29 @@@
  	mem->start = 0;
  	pages_left = mem->num_pages;
  
- 	spin_lock(&mgr->lock);
- 	for (i = 0; pages_left >= pages_per_node; ++i) {
- 		unsigned long pages = rounddown_pow_of_two(pages_left);
- 
- 		/* Limit maximum size to 2GB due to SG table limitations */
- 		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
- 
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
- 						pages_per_node, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
- 			break;
- 
- 		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
- 		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
- 		pages_left -= pages;
- 	}
+ 	/* Limit maximum size to 2GB due to SG table limitations */
+ 	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
  
- 	for (; pages_left; ++i) {
- 		unsigned long pages = min(pages_left, pages_per_node);
+ 	i = 0;
+ 	spin_lock(&mgr->lock);
+ 	while (pages_left) {
 -		uint32_t alignment = mem->page_alignment;
 +		uint32_t alignment = tbo->page_alignment;
  
- 		if (pages == pages_per_node)
+ 		if (pages >= pages_per_node)
  			alignment = pages_per_node;
  
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i],
- 						pages, alignment, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
+ 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+ 						0, place->fpfn, lpfn, mode);
+ 		if (unlikely(r)) {
+ 			if (pages > pages_per_node) {
+ 				if (is_power_of_2(pages))
+ 					pages = pages / 2;
+ 				else
+ 					pages = rounddown_pow_of_two(pages);
+ 				continue;
+ 			}
  			goto error;
+ 		}
  
  		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
  		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
@@@ -724,3 -672,73 +676,65 @@@ static const struct ttm_resource_manage
  	.free	= amdgpu_vram_mgr_del,
  	.debug	= amdgpu_vram_mgr_debug
  };
+ 
+ /**
+  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Allocate and initialize the VRAM manager.
+  */
+ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
 -	int ret;
+ 
+ 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
+ 
+ 	man->func = &amdgpu_vram_mgr_func;
+ 
+ 	drm_mm_init(&mgr->mm, 0, man->size);
+ 	spin_lock_init(&mgr->lock);
+ 	INIT_LIST_HEAD(&mgr->reservations_pending);
+ 	INIT_LIST_HEAD(&mgr->reserved_pages);
+ 
 -	/* Add the two VRAM-related sysfs files */
 -	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -	if (ret)
 -		DRM_ERROR("Failed to register sysfs\n");
 -
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
+ 	ttm_resource_manager_set_used(man, true);
+ 	return 0;
+ }
+ 
+ /**
+  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
+  * allocated inside it.
+  */
+ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
+ 	int ret;
+ 	struct amdgpu_vram_reservation *rsv, *temp;
+ 
+ 	ttm_resource_manager_set_used(man, false);
+ 
+ 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
+ 	if (ret)
+ 		return;
+ 
+ 	spin_lock(&mgr->lock);
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
+ 		kfree(rsv);
+ 
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
+ 		drm_mm_remove_node(&rsv->mm_node);
+ 		kfree(rsv);
+ 	}
+ 	drm_mm_takedown(&mgr->mm);
+ 	spin_unlock(&mgr->lock);
+ 
 -	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -
+ 	ttm_resource_manager_cleanup(man);
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
+ }

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Alex Deucher <alexdeucher@gmail.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics <intel-gfx@lists.freedesktop.org>,
	DRI <dri-devel@lists.freedesktop.org>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Andrey Grodzovsky" <andrey.grodzovsky@amd.com>,
	"Linux Next Mailing List" <linux-next@vger.kernel.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: [Intel-gfx] linux-next: manual merge of the amdgpu tree with the drm-misc tree
Date: Fri, 21 May 2021 11:38:27 +1000	[thread overview]
Message-ID: <20210521113827.675898b8@canb.auug.org.au> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 7689 bytes --]

Hi all,

Today's linux-next merge of the amdgpu tree got a conflict in:

  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

between commit:

  35bba8313b95 ("drm/amdgpu: Convert driver sysfs attributes to static attributes")

from the drm-misc tree and commit:

  589939d40116 ("drm/amdgpu: fix coding style and documentation in amdgpu_vram_mgr.c")

from the amdgpu tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index a99d196b05df,a52e17ed3df6..000000000000
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@@ -162,74 -181,6 +181,10 @@@ static struct attribute *amdgpu_vram_mg
  	NULL
  };
  
 +const struct attribute_group amdgpu_vram_mgr_attr_group = {
 +	.attrs = amdgpu_vram_mgr_attributes
 +};
 +
- static const struct ttm_resource_manager_func amdgpu_vram_mgr_func;
- 
- /**
-  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Allocate and initialize the VRAM manager.
-  */
- int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 
- 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
- 
- 	man->func = &amdgpu_vram_mgr_func;
- 
- 	drm_mm_init(&mgr->mm, 0, man->size);
- 	spin_lock_init(&mgr->lock);
- 	INIT_LIST_HEAD(&mgr->reservations_pending);
- 	INIT_LIST_HEAD(&mgr->reserved_pages);
- 
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
- 	ttm_resource_manager_set_used(man, true);
- 	return 0;
- }
- 
- /**
-  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
-  *
-  * @adev: amdgpu_device pointer
-  *
-  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
-  * allocated inside it.
-  */
- void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
- {
- 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
- 	struct ttm_resource_manager *man = &mgr->manager;
- 	int ret;
- 	struct amdgpu_vram_reservation *rsv, *temp;
- 
- 	ttm_resource_manager_set_used(man, false);
- 
- 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
- 	if (ret)
- 		return;
- 
- 	spin_lock(&mgr->lock);
- 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
- 		kfree(rsv);
- 
- 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
- 		drm_mm_remove_node(&rsv->mm_node);
- 		kfree(rsv);
- 	}
- 	drm_mm_takedown(&mgr->mm);
- 	spin_unlock(&mgr->lock);
- 
- 	ttm_resource_manager_cleanup(man);
- 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
- }
- 
  /**
   * amdgpu_vram_mgr_vis_size - Calculate visible node size
   *
@@@ -444,10 -396,10 +400,10 @@@ static int amdgpu_vram_mgr_new(struct t
  		pages_per_node = HPAGE_PMD_NR;
  #else
  		/* default to 2MB */
- 		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+ 		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
  #endif
- 		pages_per_node = max((uint32_t)pages_per_node,
- 				     tbo->page_alignment);
+ 		pages_per_node = max_t(uint32_t, pages_per_node,
 -				       mem->page_alignment);
++				       tbo->page_alignment);
  		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
  	}
  
@@@ -465,38 -417,29 +421,29 @@@
  	mem->start = 0;
  	pages_left = mem->num_pages;
  
- 	spin_lock(&mgr->lock);
- 	for (i = 0; pages_left >= pages_per_node; ++i) {
- 		unsigned long pages = rounddown_pow_of_two(pages_left);
- 
- 		/* Limit maximum size to 2GB due to SG table limitations */
- 		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
- 
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
- 						pages_per_node, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
- 			break;
- 
- 		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
- 		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
- 		pages_left -= pages;
- 	}
+ 	/* Limit maximum size to 2GB due to SG table limitations */
+ 	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
  
- 	for (; pages_left; ++i) {
- 		unsigned long pages = min(pages_left, pages_per_node);
+ 	i = 0;
+ 	spin_lock(&mgr->lock);
+ 	while (pages_left) {
 -		uint32_t alignment = mem->page_alignment;
 +		uint32_t alignment = tbo->page_alignment;
  
- 		if (pages == pages_per_node)
+ 		if (pages >= pages_per_node)
  			alignment = pages_per_node;
  
- 		r = drm_mm_insert_node_in_range(mm, &nodes[i],
- 						pages, alignment, 0,
- 						place->fpfn, lpfn,
- 						mode);
- 		if (unlikely(r))
+ 		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+ 						0, place->fpfn, lpfn, mode);
+ 		if (unlikely(r)) {
+ 			if (pages > pages_per_node) {
+ 				if (is_power_of_2(pages))
+ 					pages = pages / 2;
+ 				else
+ 					pages = rounddown_pow_of_two(pages);
+ 				continue;
+ 			}
  			goto error;
+ 		}
  
  		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
  		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
@@@ -724,3 -672,73 +676,65 @@@ static const struct ttm_resource_manage
  	.free	= amdgpu_vram_mgr_del,
  	.debug	= amdgpu_vram_mgr_debug
  };
+ 
+ /**
+  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Allocate and initialize the VRAM manager.
+  */
+ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
 -	int ret;
+ 
+ 	ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
+ 
+ 	man->func = &amdgpu_vram_mgr_func;
+ 
+ 	drm_mm_init(&mgr->mm, 0, man->size);
+ 	spin_lock_init(&mgr->lock);
+ 	INIT_LIST_HEAD(&mgr->reservations_pending);
+ 	INIT_LIST_HEAD(&mgr->reserved_pages);
+ 
 -	/* Add the two VRAM-related sysfs files */
 -	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -	if (ret)
 -		DRM_ERROR("Failed to register sysfs\n");
 -
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
+ 	ttm_resource_manager_set_used(man, true);
+ 	return 0;
+ }
+ 
+ /**
+  * amdgpu_vram_mgr_fini - free and destroy VRAM manager
+  *
+  * @adev: amdgpu_device pointer
+  *
+  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
+  * allocated inside it.
+  */
+ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
+ {
+ 	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+ 	struct ttm_resource_manager *man = &mgr->manager;
+ 	int ret;
+ 	struct amdgpu_vram_reservation *rsv, *temp;
+ 
+ 	ttm_resource_manager_set_used(man, false);
+ 
+ 	ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
+ 	if (ret)
+ 		return;
+ 
+ 	spin_lock(&mgr->lock);
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node)
+ 		kfree(rsv);
+ 
+ 	list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) {
+ 		drm_mm_remove_node(&rsv->mm_node);
+ 		kfree(rsv);
+ 	}
+ 	drm_mm_takedown(&mgr->mm);
+ 	spin_unlock(&mgr->lock);
+ 
 -	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 -
+ 	ttm_resource_manager_cleanup(man);
+ 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
+ }

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2021-05-21  1:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21  1:38 Stephen Rothwell [this message]
2021-05-21  1:38 ` [Intel-gfx] linux-next: manual merge of the amdgpu tree with the drm-misc tree Stephen Rothwell
2021-05-21  1:38 ` Stephen Rothwell
  -- strict thread matches above, loose matches on Subject: below --
2023-05-15  1:18 Stephen Rothwell
2023-05-15  1:18 ` Stephen Rothwell
2023-01-16  0:48 Stephen Rothwell
2023-01-16  0:48 ` Stephen Rothwell
2022-11-16  0:09 Stephen Rothwell
2022-11-16  0:09 ` Stephen Rothwell
2022-04-06  0:34 Stephen Rothwell
2022-04-06  0:34 ` Stephen Rothwell
2022-04-13  0:10 ` Stephen Rothwell
2022-04-13  0:10   ` Stephen Rothwell
2022-04-29  1:13   ` Stephen Rothwell
2022-04-29  1:13     ` Stephen Rothwell
2022-04-29 10:38     ` Christian König
2022-04-29 10:38       ` Christian König
2021-12-13 15:08 broonie
2021-06-03  2:48 Stephen Rothwell
2021-06-03  2:48 ` Stephen Rothwell
2021-06-03  2:55 ` Stephen Rothwell
2021-06-03  2:55   ` Stephen Rothwell
2021-06-04  2:33 ` Stephen Rothwell
2021-06-04  2:33   ` Stephen Rothwell
2021-05-21  1:42 Stephen Rothwell
2021-05-21  1:42 ` Stephen Rothwell
2021-05-21  1:20 Stephen Rothwell
2021-05-21  1:20 ` Stephen Rothwell
2021-05-21  1:16 Stephen Rothwell
2021-05-21  1:16 ` Stephen Rothwell
2021-05-12  0:20 Stephen Rothwell
2021-05-12  0:20 ` Stephen Rothwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210521113827.675898b8@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=alexander.deucher@amd.com \
    --cc=alexdeucher@gmail.com \
    --cc=andrey.grodzovsky@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.