Re: [PATCH 03/49] drm/ttm: split the mm manager init code

2020-07-30 Thread Dave Airlie
On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg  wrote:
>
> Hi Dave.
>
> On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > From: Dave Airlie 
> >
> > This will allow the driver to control the ordering here better.
> >
> > Eventually the old path will be removed.
> >
> > Signed-off-by: Dave Airlie 
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo.c| 34 +++--
> >  include/drm/ttm/ttm_bo_api.h|  4 
> >  include/drm/ttm/ttm_bo_driver.h |  6 ++
> >  3 files changed, 30 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 041a0e73cd1b..a658fd584c6d 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, 
> > unsigned mem_type)
> >  }
> >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> >
> > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > - unsigned long p_size)
> > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > +  struct ttm_mem_type_manager *man,
> > +  unsigned long p_size)
> >  {
>
> General comment for all the ttm/* changes.
> It would be very nice with some nice explanations for the exported
> functions, preferably in kernel-doc style.
> In case someone that are more or less clueless (like me) would like
> to understand how a function is to be used or maybe reviewing some
> random code.

Good point, I just need to make sure I don't add anything for
something I remove later, but I should definitely add some for the new
interfaces.

Dave.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 03/49] drm/ttm: split the mm manager init code

2020-07-30 Thread Sam Ravnborg
Hi Dave.

On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> From: Dave Airlie 
> 
> This will allow the driver to control the ordering here better.
> 
> Eventually the old path will be removed.
> 
> Signed-off-by: Dave Airlie 
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c| 34 +++--
>  include/drm/ttm/ttm_bo_api.h|  4 
>  include/drm/ttm/ttm_bo_driver.h |  6 ++
>  3 files changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 041a0e73cd1b..a658fd584c6d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, 
> unsigned mem_type)
>  }
>  EXPORT_SYMBOL(ttm_bo_evict_mm);
>  
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> - unsigned long p_size)
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +  struct ttm_mem_type_manager *man,
> +  unsigned long p_size)
>  {

General comment for all the ttm/* changes.
It would be very nice with some nice explanations for the exported
functions, preferably in kernel-doc style.
In case someone that are more or less clueless (like me) would like
to understand how a function is to be used or maybe reviewing some
random code.

Sam


> - int ret;
> - struct ttm_mem_type_manager *man;
>   unsigned i;
>  
> - BUG_ON(type >= TTM_NUM_MEM_TYPES);
> - man = >man[type];
>   BUG_ON(man->has_type);
>   man->use_io_reserve_lru = false;
>   mutex_init(>io_reserve_mutex);
>   spin_lock_init(>move_lock);
>   INIT_LIST_HEAD(>io_reserve_lru);
>   man->bdev = bdev;
> -
> - if (type != TTM_PL_SYSTEM) {
> - ret = (*man->func->init)(man, p_size);
> - if (ret)
> - return ret;
> - }
> - man->has_type = true;
> - man->use_type = true;
>   man->size = p_size;
>  
>   for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>   INIT_LIST_HEAD(>lru[i]);
>   man->move = NULL;
> +}
> +EXPORT_SYMBOL(ttm_bo_init_mm_base);
>  
> +int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> + unsigned long p_size)
> +{
> + int ret;
> + struct ttm_mem_type_manager *man;
> +
> + BUG_ON(type >= TTM_NUM_MEM_TYPES);
> + ttm_bo_init_mm_base(bdev, >man[type], p_size);
> +
> + if (type != TTM_PL_SYSTEM) {
> + ret = (*man->func->init)(man, p_size);
> + if (ret)
> + return ret;
> + }
> + ttm_bo_use_mm(man);
>   return 0;
>  }
>  EXPORT_SYMBOL(ttm_bo_init_mm);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a9e13b252820..0060925f507a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned 
> long size,
>   * -ENOMEM: Not enough memory.
>   * May also return driver-specified errors.
>   */
> +struct ttm_mem_type_manager;
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +  struct ttm_mem_type_manager *man,
> +  unsigned long p_size);
>  int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>  unsigned long p_size);
>  
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7958e411269a..68e75c3b8c7a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct 
> ttm_buffer_object *bo)
>   dma_resv_unlock(bo->base.resv);
>  }
>  
> +static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +{
> + man->has_type = true;
> + man->use_type = true;
> +}
> +
>  /*
>   * ttm_bo_util.c
>   */
> -- 
> 2.26.2
> 
> ___
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] vgacon: Fix an out-of-bounds in vgacon_scrollback_update()

2020-07-30 Thread Jiri Slaby
Hi,

On 31. 07. 20, 5:23, Yang Yingliang wrote:
> void execute_one(void)
> {
>   intptr_t res = 0;
>   res = syz_open_dev(0xc, 4, 1);

open(/dev/tty1)

>   if (res != -1)
>   r[0] = res;
> *(uint16_t*)0x2000 = 0xc;
> *(uint16_t*)0x2002 = 0x373;
> *(uint16_t*)0x2004 = 0x1442;
>   syscall(__NR_ioctl, r[0], 0x5609ul, 0x2000ul);

VT_RESIZE(12, 883)

> memcpy((void*)0x20003500, "\x7f\x45\x4c\x46\x00\x00\x00...
>   syscall(__NR_write, r[0], 0x20003500ul, 0x381ul);

Write 381 bytes of some ELF to the tty.

OK, that's it. Thanks.

-- 
js
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [git pull] drm fixes for 5.8-rc8 (part 2)

2020-07-30 Thread pr-tracker-bot
The pull request you sent on Fri, 31 Jul 2020 13:44:54 +1000:

> git://anongit.freedesktop.org/drm/drm tags/drm-fixes-2020-07-31

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/d8b9faec54ae4bc2fff68bcd0befa93ace8256ce

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 47/49] drm/ttm: drop list of memory managers from device.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

The driver now controls these, the core just controls the system
memory one.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c| 2 --
 include/drm/ttm/ttm_bo_driver.h | 6 --
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f2b41c4d7d51..f35548ff17e8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1608,8 +1608,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
bdev->driver = driver;
 
-   memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
-
ttm_bo_init_sysman(bdev);
 
bdev->vma_manager = vma_manager;
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index bfc549782775..b2ffeaed94e7 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -414,7 +414,7 @@ struct ttm_bo_device {
/*
 * access via ttm_manager_type.
 */
-   struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
+   struct ttm_mem_type_manager sysman; /* move to global */
struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
/*
 * Protected by internal locks.
@@ -446,9 +446,11 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct 
ttm_bo_device *bdev,
int mem_type)
 {
+   if (mem_type == TTM_PL_SYSTEM)
+   return >sysman;
if (bdev->man_drv[mem_type])
return bdev->man_drv[mem_type];
-   return >man_priv[mem_type];
+   return NULL;
 }
 
 static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 42/49] drm/vmwgfx/gmrid: convert to driver controlled allocation.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 33 +++
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 2db99f0449b0..14430c243ce5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -37,6 +37,7 @@
 #include 
 
 struct vmwgfx_gmrid_man {
+   struct ttm_mem_type_manager manager;
spinlock_t lock;
struct ida gmr_ida;
uint32_t max_gmr_ids;
@@ -44,13 +45,17 @@ struct vmwgfx_gmrid_man {
uint32_t used_gmr_pages;
 };
 
+static struct vmwgfx_gmrid_man *to_gmrid_manager(struct ttm_mem_type_manager 
*man)
+{
+   return container_of(man, struct vmwgfx_gmrid_man, manager);
+}
+
 static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
  struct ttm_buffer_object *bo,
  const struct ttm_place *place,
  struct ttm_mem_reg *mem)
 {
-   struct vmwgfx_gmrid_man *gman =
-   (struct vmwgfx_gmrid_man *)man->priv;
+   struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
int id;
 
id = ida_alloc_max(>gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
@@ -82,8 +87,7 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager 
*man,
 static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
   struct ttm_mem_reg *mem)
 {
-   struct vmwgfx_gmrid_man *gman =
-   (struct vmwgfx_gmrid_man *)man->priv;
+   struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 
if (mem->mm_node) {
ida_free(>gmr_ida, mem->start);
@@ -98,13 +102,15 @@ static const struct ttm_mem_type_manager_func 
vmw_gmrid_manager_func;
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
type);
+   struct ttm_mem_type_manager *man;
struct vmwgfx_gmrid_man *gman =
kzalloc(sizeof(*gman), GFP_KERNEL);
 
if (unlikely(!gman))
return -ENOMEM;
 
+   man = >manager;
+
man->func = _gmrid_manager_func;
man->available_caching = TTM_PL_FLAG_CACHED;
man->default_caching = TTM_PL_FLAG_CACHED;
@@ -127,26 +133,27 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int 
type)
default:
BUG();
}
-   man->priv = (void *) gman;
+
+   ttm_set_driver_manager(_priv->bdev, type, >manager);
+   ttm_bo_use_mm(man);
return 0;
 }
 
 void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
type);
-   struct vmwgfx_gmrid_man *gman =
-   (struct vmwgfx_gmrid_man *)man->priv;
+   struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 
ttm_bo_disable_mm(man);
 
ttm_bo_force_list_clean(_priv->bdev, man);
 
-   if (gman) {
-   ida_destroy(>gmr_ida);
-   kfree(gman);
-   }
-
ttm_bo_man_cleanup(man);
+
+   ttm_set_driver_manager(_priv->bdev, type, NULL);
+   ida_destroy(>gmr_ida);
+   kfree(gman);
+
 }
 
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 41/49] drm/vmwgfx/ttm: move thp to driver managed

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 33 +++--
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index 0dd619c9d207..d2dde8159c3d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -16,10 +16,16 @@
  * @lock: Manager lock.
  */
 struct vmw_thp_manager {
+   struct ttm_mem_type_manager manager;
struct drm_mm mm;
spinlock_t lock;
 };
 
+static struct vmw_thp_manager *to_thp_manager(struct ttm_mem_type_manager *man)
+{
+   return container_of(man, struct vmw_thp_manager, manager);
+}
+
 static int vmw_thp_insert_aligned(struct drm_mm *mm, struct drm_mm_node *node,
  unsigned long align_pages,
  const struct ttm_place *place,
@@ -43,7 +49,7 @@ static int vmw_thp_get_node(struct ttm_mem_type_manager *man,
const struct ttm_place *place,
struct ttm_mem_reg *mem)
 {
-   struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+   struct vmw_thp_manager *rman = to_thp_manager(man);
struct drm_mm *mm = >mm;
struct drm_mm_node *node;
unsigned long align_pages;
@@ -103,7 +109,7 @@ static int vmw_thp_get_node(struct ttm_mem_type_manager 
*man,
 static void vmw_thp_put_node(struct ttm_mem_type_manager *man,
 struct ttm_mem_reg *mem)
 {
-   struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+   struct vmw_thp_manager *rman = to_thp_manager(man);
 
if (mem->mm_node) {
spin_lock(>lock);
@@ -117,20 +123,25 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager 
*man,
 
 int vmw_thp_init(struct vmw_private *dev_priv)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
+   struct ttm_mem_type_manager *man;
struct vmw_thp_manager *rman;
+
+   rman = kzalloc(sizeof(*rman), GFP_KERNEL);
+   if (!rman)
+   return -ENOMEM;
+
+   man = >manager;
man->available_caching = TTM_PL_FLAG_CACHED;
man->default_caching = TTM_PL_FLAG_CACHED;
 
ttm_bo_init_mm_base(_priv->bdev, man,
dev_priv->vram_size >> PAGE_SHIFT);
-   rman = kzalloc(sizeof(*rman), GFP_KERNEL);
-   if (!rman)
-   return -ENOMEM;
+
 
drm_mm_init(>mm, 0, man->size);
spin_lock_init(>lock);
-   man->priv = rman;
+
+   ttm_set_driver_manager(_priv->bdev, TTM_PL_VRAM, >manager);
ttm_bo_use_mm(man);
return 0;
 }
@@ -138,7 +149,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 void vmw_thp_takedown(struct vmw_private *dev_priv)
 {
struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
-   struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+   struct vmw_thp_manager *rman = to_thp_manager(man);
struct drm_mm *mm = >mm;
int ret;
 
@@ -151,15 +162,15 @@ void vmw_thp_takedown(struct vmw_private *dev_priv)
drm_mm_clean(mm);
drm_mm_takedown(mm);
spin_unlock(>lock);
-   kfree(rman);
-   man->priv = NULL;
ttm_bo_man_cleanup(man);
+   ttm_set_driver_manager(_priv->bdev, TTM_PL_VRAM, NULL);
+   kfree(rman);
 }
 
 static void vmw_thp_debug(struct ttm_mem_type_manager *man,
  struct drm_printer *printer)
 {
-   struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+   struct vmw_thp_manager *rman = to_thp_manager(man);
 
spin_lock(>lock);
drm_mm_print(>mm, printer);
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 46/49] drm/ttm: drop man->bdev link.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This link isn't needed anymore, drop it from the init interface.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 6 ++
 drivers/gpu/drm/ttm/ttm_bo.c  | 6 ++
 drivers/gpu/drm/ttm/ttm_bo_manager.c  | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c   | 2 +-
 include/drm/ttm/ttm_bo_api.h  | 3 +--
 include/drm/ttm/ttm_bo_driver.h   | 2 --
 9 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 83d88ee73468..b4480ca30988 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -108,7 +108,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
 
-   ttm_bo_init_mm_base(>mman.bdev, man, gtt_size >> PAGE_SHIFT);
+   ttm_bo_init_mm_base(man, gtt_size >> PAGE_SHIFT);
 
start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index d451851c8689..f0e65a6fdf88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -190,7 +190,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
man->default_caching = TTM_PL_FLAG_WC;
 
-   ttm_bo_init_mm_base(>mman.bdev, man, adev->gmc.real_vram_size >> 
PAGE_SHIFT);
+   ttm_bo_init_mm_base(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
 
man->func = _vram_mgr_func;
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 5b0af2065ad9..89521d3ed9da 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -174,8 +174,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 
man->func = _vram_manager;
man->use_io_reserve_lru = true;
-   ttm_bo_init_mm_base(>ttm.bdev, man,
-   drm->gem.vram_available >> PAGE_SHIFT);
+   ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_VRAM, man);
ttm_bo_use_mm(man);
return 0;
@@ -236,8 +235,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
man->available_caching = available_caching;
man->default_caching = default_caching;
man->use_tt = true;
-   ttm_bo_init_mm_base(>ttm.bdev, man,
-   size_pages);
+   ttm_bo_init_mm_base(man, size_pages);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_TT, man);
ttm_bo_use_mm(man);
return 0;
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 1e8fda1c9b3a..f2b41c4d7d51 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1464,8 +1464,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
-struct ttm_mem_type_manager *man,
+void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
 unsigned long p_size)
 {
unsigned i;
@@ -1475,7 +1474,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
mutex_init(>io_reserve_mutex);
spin_lock_init(>move_lock);
INIT_LIST_HEAD(>io_reserve_lru);
-   man->bdev = bdev;
man->size = p_size;
 
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
@@ -1588,7 +1586,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
 
-   ttm_bo_init_mm_base(bdev, man, 0);
+   ttm_bo_init_mm_base(man, 0);
ttm_bo_use_mm(man);
 }
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 2782ccff9b66..6c6eedf84ca6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -133,7 +133,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 
man->func = _bo_manager_func;
 
-   ttm_bo_init_mm_base(bdev, man, p_size);
+   ttm_bo_init_mm_base(man, p_size);
 
drm_mm_init(>mm, 0, p_size);
spin_lock_init(>lock);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 14430c243ce5..2b60957f7c4a 100644
--- 

[PATCH 48/49] drm/ttm: drop type manager has_type

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

under driver control, this flag isn't needed anymore

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c| 6 ++
 include/drm/ttm/ttm_bo_driver.h | 5 -
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f35548ff17e8..bfc20cb27ed6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -82,7 +82,6 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, 
struct drm_printer *p
 {
struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
 
-   drm_printf(p, "has_type: %d\n", man->has_type);
drm_printf(p, "use_type: %d\n", man->use_type);
drm_printf(p, "use_tt: %d\n", man->use_tt);
drm_printf(p, "size: %llu\n", man->size);
@@ -997,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object 
*bo,
return ret;
 
man = ttm_manager_type(bdev, mem_type);
-   if (!man->has_type || !man->use_type)
+   if (!man || !man->use_type)
return -EBUSY;
 
if (!ttm_bo_mt_compatible(man, mem_type, place, _flags))
@@ -1455,7 +1454,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
return -EINVAL;
}
 
-   if (!man->has_type) {
+   if (!man) {
pr_err("Memory type %u has not been initialized\n", mem_type);
return 0;
}
@@ -1469,7 +1468,6 @@ void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
 {
unsigned i;
 
-   BUG_ON(man->has_type);
man->use_io_reserve_lru = false;
mutex_init(>io_reserve_mutex);
spin_lock_init(>move_lock);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index b2ffeaed94e7..702b3b056eda 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -111,7 +111,6 @@ struct ttm_mem_type_manager_func {
 /**
  * struct ttm_mem_type_manager
  *
- * @has_type: The memory type has been initialized.
  * @use_type: The memory type is enabled.
  * @flags: TTM_MEMTYPE_XX flags identifying the traits of the memory
  * managed by this memory type.
@@ -141,8 +140,6 @@ struct ttm_mem_type_manager {
/*
 * No protection. Constant from start.
 */
-
-   bool has_type;
bool use_type;
bool use_tt;
uint64_t size;
@@ -673,13 +670,11 @@ static inline void ttm_bo_unreserve(struct 
ttm_buffer_object *bo)
 
 static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
 {
-   man->has_type = true;
man->use_type = true;
 }
 
 static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
 {
-   man->has_type = false;
man->use_type = false;
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 23/49] drm/vmwgfx: fix gmrid takedown paths to new interface

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   | 10 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h   |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 11 ---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 7d65f9121cd7..b27f8b3699cf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -994,9 +994,9 @@ static int vmw_driver_load(struct drm_device *dev, unsigned 
long chipset)
vmw_kms_close(dev_priv);
 out_no_kms:
if (dev_priv->has_mob)
-   (void) ttm_bo_clean_mm(_priv->bdev, VMW_PL_MOB);
+   vmw_gmrid_man_takedown(dev_priv, VMW_PL_MOB);
if (dev_priv->has_gmr)
-   (void) ttm_bo_clean_mm(_priv->bdev, VMW_PL_GMR);
+   vmw_gmrid_man_takedown(dev_priv, VMW_PL_GMR);
vmw_takedown_vram_manager(dev_priv);
 out_no_vram:
(void)ttm_bo_device_release(_priv->bdev);
@@ -1045,12 +1045,12 @@ static void vmw_driver_unload(struct drm_device *dev)
vmw_overlay_close(dev_priv);
 
if (dev_priv->has_gmr)
-   (void)ttm_bo_clean_mm(_priv->bdev, VMW_PL_GMR);
-   (void)ttm_bo_clean_mm(_priv->bdev, TTM_PL_VRAM);
+   vmw_gmrid_man_takedown(dev_priv, VMW_PL_GMR);
+   vmw_takedown_vram_manager(dev_priv);
 
vmw_release_device_early(dev_priv);
if (dev_priv->has_mob)
-   (void) ttm_bo_clean_mm(_priv->bdev, VMW_PL_MOB);
+   vmw_gmrid_man_takedown(dev_priv, VMW_PL_MOB);
(void) ttm_bo_device_release(_priv->bdev);
drm_vma_offset_manager_destroy(_priv->vma_manager);
vmw_release_device_late(dev_priv);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index b20056fdd042..d37af7929189 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1222,6 +1222,7 @@ int vmw_overlay_num_free_overlays(struct vmw_private 
*dev_priv);
  */
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
+void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type);
 
 /**
  * Prime - vmwgfx_prime.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index e79d2c8abad2..2522927b75da 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -131,16 +131,22 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int 
type)
return 0;
 }
 
-static int vmw_gmrid_man_takedown(struct ttm_mem_type_manager *man)
+void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
+   struct ttm_mem_type_manager *man = _priv->bdev.man[type];
struct vmwgfx_gmrid_man *gman =
(struct vmwgfx_gmrid_man *)man->priv;
 
+   ttm_bo_disable_mm(man);
+
+   ttm_bo_force_list_clean(_priv->bdev, man);
+
if (gman) {
ida_destroy(>gmr_ida);
kfree(gman);
}
-   return 0;
+
+   ttm_bo_man_cleanup(man);
 }
 
 static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
@@ -150,7 +156,6 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager 
*man,
 }
 
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-   .takedown = vmw_gmrid_man_takedown,
.get_node = vmw_gmrid_man_get_node,
.put_node = vmw_gmrid_man_put_node,
.debug = vmw_gmrid_man_debug
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 43/49] drm/nouveau/ttm: move to driver allocated manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 41 ++-
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 225f9af2eaa1..5b0af2065ad9 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -157,12 +157,12 @@ static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
struct nvif_mmu *mmu = >client.mmu;
-
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
-   struct ttm_mem_type_manager *man = 
ttm_manager_type(>ttm.bdev, TTM_PL_VRAM);
-
/* Some BARs do not support being ioremapped WC */
const u8 type = mmu->type[drm->ttm.type_vram].type;
+   struct ttm_mem_type_manager *man = kzalloc(sizeof(struct 
ttm_mem_type_manager), GFP_KERNEL);
+   if (!man)
+   return -ENOMEM;
 
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
man->default_caching = TTM_PL_FLAG_WC;
@@ -176,6 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
man->use_io_reserve_lru = true;
ttm_bo_init_mm_base(>ttm.bdev, man,
drm->gem.vram_available >> PAGE_SHIFT);
+   ttm_set_driver_manager(>ttm.bdev, TTM_PL_VRAM, man);
ttm_bo_use_mm(man);
return 0;
} else {
@@ -195,6 +196,8 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
ttm_bo_disable_mm(man);
ttm_bo_force_list_clean(>ttm.bdev, man);
ttm_bo_man_cleanup(man);
+   ttm_set_driver_manager(>ttm.bdev, TTM_PL_VRAM, NULL);
+   kfree(man);
} else
ttm_bo_man_takedown(>ttm.bdev, TTM_PL_VRAM);
 }
@@ -202,30 +205,40 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_TT);
+   struct ttm_mem_type_manager *man;
unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
-   man->use_tt = true;
+   unsigned available_caching, default_caching;
+   const struct ttm_mem_type_manager_func *func = NULL;
if (drm->agp.bridge) {
-   man->available_caching = TTM_PL_FLAG_UNCACHED |
+   available_caching = TTM_PL_FLAG_UNCACHED |
TTM_PL_FLAG_WC;
-   man->default_caching = TTM_PL_FLAG_WC;
+   default_caching = TTM_PL_FLAG_WC;
} else {
-   man->available_caching = TTM_PL_MASK_CACHING;
-   man->default_caching = TTM_PL_FLAG_CACHED;
+   available_caching = TTM_PL_MASK_CACHING;
+   default_caching = TTM_PL_FLAG_CACHED;
}
 
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
-   man->func = _gart_manager;
+   func = _gart_manager;
else if (!drm->agp.bridge)
-   man->func = _gart_manager;
+   func = _gart_manager;
else
return ttm_bo_man_init(>ttm.bdev, TTM_PL_TT,
-  TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
-  TTM_PL_FLAG_WC, true,
+  available_caching, default_caching,
+  true,
   size_pages);
 
+   man = kzalloc(sizeof(struct ttm_mem_type_manager), GFP_KERNEL);
+   if (!man)
+   return -ENOMEM;
+
+   man->func = func;
+   man->available_caching = available_caching;
+   man->default_caching = default_caching;
+   man->use_tt = true;
ttm_bo_init_mm_base(>ttm.bdev, man,
size_pages);
+   ttm_set_driver_manager(>ttm.bdev, TTM_PL_TT, man);
ttm_bo_use_mm(man);
return 0;
 }
@@ -242,6 +255,8 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
ttm_bo_disable_mm(man);
ttm_bo_force_list_clean(>ttm.bdev, man);
ttm_bo_man_cleanup(man);
+   ttm_set_driver_manager(>ttm.bdev, TTM_PL_TT, NULL);
+   kfree(man);
}
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Just store the device in the private so the link
can be removed from the manager

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 9d4a13926b8c..d451851c8689 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -34,6 +34,7 @@ struct amdgpu_vram_mgr {
spinlock_t lock;
atomic64_t usage;
atomic64_t vis_usage;
+   struct amdgpu_device *adev;
 };
 
 static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_mem_type_manager 
*man)
@@ -196,6 +197,8 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
drm_mm_init(>mm, 0, man->size);
spin_lock_init(>lock);
 
+   mgr->adev = adev;
+
/* Add the two VRAM-related sysfs files */
ret = sysfs_create_files(>dev->kobj, amdgpu_vram_mgr_attributes);
if (ret)
@@ -323,8 +326,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager 
*man,
   const struct ttm_place *place,
   struct ttm_mem_reg *mem)
 {
-   struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
+   struct amdgpu_device *adev = mgr->adev;
struct drm_mm *mm = >mm;
struct drm_mm_node *nodes;
enum drm_mm_insert_mode mode;
@@ -439,8 +442,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager 
*man,
 static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
struct ttm_mem_reg *mem)
 {
-   struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
+   struct amdgpu_device *adev = mgr->adev;
struct drm_mm_node *nodes = mem->mm_node;
uint64_t usage = 0, vis_usage = 0;
unsigned pages = mem->num_pages;
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 30/49] drm/qxl/ttm: use wrapper to access memory manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/qxl/qxl_ttm.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index acc4497887a6..9aea35a66e25 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -219,7 +219,7 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
 unsigned int type,
 uint64_t size)
 {
-   struct ttm_mem_type_manager *man = >mman.bdev.man[type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
type);
 
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
@@ -266,8 +266,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
 
 void qxl_ttm_fini(struct qxl_device *qdev)
 {
-   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_VRAM]);
-   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_PRIV]);
+   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, TTM_PL_VRAM));
+   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, TTM_PL_PRIV));
ttm_bo_device_release(>mman.bdev);
DRM_INFO("qxl: ttm finalized\n");
 }
@@ -302,9 +302,9 @@ void qxl_ttm_debugfs_init(struct qxl_device *qdev)
qxl_mem_types_list[i].show = _mm_dump_table;
qxl_mem_types_list[i].driver_features = 0;
if (i == 0)
-   qxl_mem_types_list[i].data = 
>mman.bdev.man[TTM_PL_VRAM];
+   qxl_mem_types_list[i].data = 
ttm_manager_type(>mman.bdev, TTM_PL_VRAM);
else
-   qxl_mem_types_list[i].data = 
>mman.bdev.man[TTM_PL_PRIV];
+   qxl_mem_types_list[i].data = 
ttm_manager_type(>mman.bdev, TTM_PL_PRIV);
 
}
qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Allow the takedown path callback to be optional as well.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c |  8 +---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 21 +++--
 include/drm/ttm/ttm_bo_driver.h  |  5 -
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f584e5e94383..f0f0f3101bd1 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1401,8 +1401,8 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_create);
 
-static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-  struct ttm_mem_type_manager *man)
+int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man)
 {
struct ttm_operation_ctx ctx = {
.interruptible = false,
@@ -1444,6 +1444,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device 
*bdev,
 
return 0;
 }
+EXPORT_SYMBOL(ttm_bo_force_list_clean);
 
 int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 {
@@ -1472,7 +1473,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
return ret;
}
 
-   ret = (*man->func->takedown)(man);
+   if (man->func->takedown)
+   ret = (*man->func->takedown)(man);
}
 
ttm_bo_man_cleanup(man);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 1877425abdf0..1127868274b3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -129,7 +129,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_man_init);
 
-static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
+static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
 {
struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
struct drm_mm *mm = >mm;
@@ -146,6 +146,23 @@ static int ttm_bo_man_takedown(struct ttm_mem_type_manager 
*man)
return -EBUSY;
 }
 
+int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man)
+{
+   int ret;
+
+   ttm_bo_disable_mm(man);
+
+   ret = ttm_bo_force_list_clean(bdev, man);
+   if (ret)
+   return ret;
+
+   ttm_bo_man_takedown_private(man);
+   ttm_bo_man_cleanup(man);
+   return 0;
+}
+EXPORT_SYMBOL(ttm_bo_man_takedown);
+
 static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 struct drm_printer *printer)
 {
@@ -157,7 +174,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager 
*man,
 }
 
 static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-   .takedown = ttm_bo_man_takedown,
+   .takedown = ttm_bo_man_takedown_private,
.get_node = ttm_bo_man_get_node,
.put_node = ttm_bo_man_put_node,
.debug = ttm_bo_man_debug
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 92bb54cce633..2ef33b407167 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -683,6 +683,8 @@ static inline void ttm_bo_man_cleanup(struct 
ttm_mem_type_manager *man)
man->move = NULL;
 }
 
+int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man);
 /*
  * ttm_bo_util.c
  */
@@ -801,5 +803,6 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
struct ttm_mem_type_manager *man,
unsigned long p_size);
-
+int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man);
 #endif
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 44/49] drm/ttm: drop priv pointer in memory manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This isn't needed anymore by any drivers.

Signed-off-by: Dave Airlie 
---
 include/drm/ttm/ttm_bo_driver.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 6319d85d7270..a38704fe0737 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -123,7 +123,6 @@ struct ttm_mem_type_manager_func {
  * @default_caching: The default caching policy used for a buffer object
  * placed in this memory type if the user doesn't provide one.
  * @func: structure pointer implementing the range manager. See above
- * @priv: Driver private closure for @func.
  * @io_reserve_mutex: Mutex optionally protecting shared io_reserve structures
  * @use_io_reserve_lru: Use an lru list to try to unreserve io_mem_regions
  * reserved by the TTM vm system.
@@ -152,7 +151,6 @@ struct ttm_mem_type_manager {
uint32_t available_caching;
uint32_t default_caching;
const struct ttm_mem_type_manager_func *func;
-   void *priv;
struct mutex io_reserve_mutex;
bool use_io_reserve_lru;
spinlock_t move_lock;
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This makes it easier to move these to a driver allocated system

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 15 +--
 drivers/gpu/drm/drm_gem_vram_helper.c   | 10 
 drivers/gpu/drm/nouveau/nouveau_ttm.c   | 21 ++--
 drivers/gpu/drm/qxl/qxl_ttm.c   | 12 +++--
 drivers/gpu/drm/radeon/radeon_ttm.c | 33 -
 drivers/gpu/drm/ttm/ttm_bo_manager.c| 19 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 13 +++---
 include/drm/ttm/ttm_bo_driver.h |  7 --
 8 files changed, 67 insertions(+), 63 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 4beec1c4e037..d4d81f808b01 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -67,12 +67,9 @@ static int amdgpu_ttm_init_on_chip(struct amdgpu_device 
*adev,
unsigned int type,
uint64_t size)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
type);
-
-   man->available_caching = TTM_PL_FLAG_UNCACHED;
-   man->default_caching = TTM_PL_FLAG_UNCACHED;
-
-   return ttm_bo_man_init(>mman.bdev, man, size >> PAGE_SHIFT);
+   return ttm_bo_man_init(>mman.bdev, type,
+  TTM_PL_FLAG_UNCACHED, TTM_PL_FLAG_UNCACHED,
+  false, size >> PAGE_SHIFT);
 }
 
 /**
@@ -2014,9 +2011,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 
amdgpu_vram_mgr_fini(adev);
amdgpu_gtt_mgr_fini(adev);
-   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, AMDGPU_PL_GDS));
-   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, AMDGPU_PL_GWS));
-   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, AMDGPU_PL_OA));
+   ttm_bo_man_takedown(>mman.bdev, AMDGPU_PL_GDS);
+   ttm_bo_man_takedown(>mman.bdev, AMDGPU_PL_GWS);
+   ttm_bo_man_takedown(>mman.bdev, AMDGPU_PL_OA);
ttm_bo_device_release(>mman.bdev);
adev->mman.initialized = false;
DRM_INFO("amdgpu: ttm finalized\n");
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index 08fbfa32540a..b98af8daa540 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1103,7 +1103,6 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
 static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
uint64_t vram_base, size_t vram_size)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(>bdev, 
TTM_PL_VRAM);
int ret;
 
vmm->vram_base = vram_base;
@@ -1116,9 +1115,10 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, 
struct drm_device *dev,
if (ret)
return ret;
 
-   man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-   man->default_caching = TTM_PL_FLAG_WC;
-   ret = ttm_bo_man_init(>bdev, man, vram_size >> PAGE_SHIFT);
+   ret = ttm_bo_man_init(>bdev, TTM_PL_VRAM,
+ TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
+ TTM_PL_FLAG_WC, false,
+ vram_size >> PAGE_SHIFT);
if (ret)
return ret;
 
@@ -1127,7 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, 
struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
-   ttm_bo_man_takedown(>bdev, ttm_manager_type(>bdev, 
TTM_PL_VRAM));
+   ttm_bo_man_takedown(>bdev, TTM_PL_VRAM);
ttm_bo_device_release(>bdev);
 }
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 1b9d9362132d..225f9af2eaa1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -156,16 +156,17 @@ nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
 static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_VRAM);
struct nvif_mmu *mmu = >client.mmu;
 
-   man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-   man->default_caching = TTM_PL_FLAG_WC;
-
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+   struct ttm_mem_type_manager *man = 
ttm_manager_type(>ttm.bdev, TTM_PL_VRAM);
+
/* Some BARs do not support being ioremapped WC */
const u8 type = mmu->type[drm->ttm.type_vram].type;
 
+   man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
+   man->default_caching = TTM_PL_FLAG_WC;
+
if (type & NVIF_MEM_UNCACHED) {
man->available_caching = TTM_PL_FLAG_UNCACHED;
man->default_caching = TTM_PL_FLAG_UNCACHED;
@@ -178,7 +179,9 @@ 

[PATCH 27/49] drm/amdgfx/ttm: use wrapper to get ttm memory managers

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   |  5 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 12 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c  | 21 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c  | 12 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 12 +--
 8 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 1b865fed74ca..e24f421e5553 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -517,8 +517,9 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int 
dma_buf_fd,
 uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+   struct ttm_mem_type_manager *vram_man = 
ttm_manager_type(>mman.bdev, TTM_PL_VRAM);
 
-   return amdgpu_vram_mgr_usage(>mman.bdev.man[TTM_PL_VRAM]);
+   return amdgpu_vram_mgr_usage(vram_man);
 }
 
 uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index a512ccbc4dea..9829640e1769 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -299,7 +299,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct 
amdgpu_device *adev,
 {
s64 time_us, increment_us;
u64 free_vram, total_vram, used_vram;
-
+   struct ttm_mem_type_manager *vram_man = 
ttm_manager_type(>mman.bdev, TTM_PL_VRAM);
/* Allow a maximum of 200 accumulated ms. This is basically per-IB
 * throttling.
 *
@@ -316,7 +316,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct 
amdgpu_device *adev,
}
 
total_vram = adev->gmc.real_vram_size - 
atomic64_read(>vram_pin_size);
-   used_vram = amdgpu_vram_mgr_usage(>mman.bdev.man[TTM_PL_VRAM]);
+   used_vram = amdgpu_vram_mgr_usage(vram_man);
free_vram = used_vram >= total_vram ? 0 : total_vram - used_vram;
 
spin_lock(>mm_stats.lock);
@@ -363,7 +363,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct 
amdgpu_device *adev,
if (!amdgpu_gmc_vram_full_visible(>gmc)) {
u64 total_vis_vram = adev->gmc.visible_vram_size;
u64 used_vis_vram =
-   
amdgpu_vram_mgr_vis_usage(>mman.bdev.man[TTM_PL_VRAM]);
+ amdgpu_vram_mgr_vis_usage(vram_man);
 
if (used_vis_vram < total_vis_vram) {
u64 free_vis_vram = total_vis_vram - used_vis_vram;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index aa5b54e5a1d7..d551e7c5e69d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3880,7 +3880,7 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device 
*adev,
 
amdgpu_virt_init_data_exchange(adev);
/* we need recover gart prior to run SMC/CP/SDMA resume */
-   amdgpu_gtt_mgr_recover(>mman.bdev.man[TTM_PL_TT]);
+   amdgpu_gtt_mgr_recover(ttm_manager_type(>mman.bdev, TTM_PL_TT));
 
r = amdgpu_device_fw_loading(adev);
if (r)
@@ -4079,8 +4079,7 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info 
*hive,
amdgpu_inc_vram_lost(tmp_adev);
}
 
-   r = amdgpu_gtt_mgr_recover(
-   _adev->mman.bdev.man[TTM_PL_TT]);
+   r = 
amdgpu_gtt_mgr_recover(ttm_manager_type(_adev->mman.bdev, TTM_PL_TT));
if (r)
goto out;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index f4c870b2f348..0b0d09d19b4f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -48,9 +48,9 @@ static ssize_t amdgpu_mem_info_gtt_total_show(struct device 
*dev,
 {
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = ddev->dev_private;
-
+   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
TTM_PL_TT);
return snprintf(buf, PAGE_SIZE, "%llu\n",
-   (adev->mman.bdev.man[TTM_PL_TT].size) * PAGE_SIZE);
+   man->size * PAGE_SIZE);
 }
 
 /**
@@ -66,9 +66,9 @@ static ssize_t amdgpu_mem_info_gtt_used_show(struct device 
*dev,
 {
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = ddev->dev_private;
-
+   struct ttm_mem_type_manager *man = 

[PATCH 37/49] drm/ttm: allow drivers to provide their own manager subclasses

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This will get removed eventually and all drivers will use this.

Signed-off-by: Dave Airlie 
---
 include/drm/ttm/ttm_bo_driver.h | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 419b088253cf..723171fd94da 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -419,7 +419,7 @@ struct ttm_bo_device {
 * access via ttm_manager_type.
 */
struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
-
+   struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
/*
 * Protected by internal locks.
 */
@@ -450,9 +450,18 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct 
ttm_bo_device *bdev,
int mem_type)
 {
+   if (bdev->man_drv[mem_type])
+   return bdev->man_drv[mem_type];
return >man_priv[mem_type];
 }
 
+static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,
+ int type,
+ struct ttm_mem_type_manager *manager)
+{
+   bdev->man_drv[type] = manager;
+}
+
 /**
  * struct ttm_lru_bulk_move_pos
  *
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 31/49] drm/radeon/ttm: use wrapper to access memory manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/radeon/radeon_gem.c |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c | 13 ++---
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
b/drivers/gpu/drm/radeon/radeon_gem.c
index 44157ada9b0e..3ec028dba739 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -226,7 +226,7 @@ int radeon_gem_info_ioctl(struct drm_device *dev, void 
*data,
struct drm_radeon_gem_info *args = data;
struct ttm_mem_type_manager *man;
 
-   man = >mman.bdev.man[TTM_PL_VRAM];
+   man = ttm_manager_type(>mman.bdev, TTM_PL_VRAM);
 
args->vram_size = (u64)man->size << PAGE_SHIFT;
args->vram_visible = rdev->mc.visible_vram_size;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index e65297b4b678..3849d0e852bc 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -68,7 +68,7 @@ struct radeon_device *radeon_get_rdev(struct ttm_bo_device 
*bdev)
 
 static int radeon_ttm_init_vram(struct radeon_device *rdev)
 {
-   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
TTM_PL_VRAM);
 
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
man->default_caching = TTM_PL_FLAG_WC;
@@ -79,7 +79,7 @@ static int radeon_ttm_init_vram(struct radeon_device *rdev)
 
 static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 {
-   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_TT];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
TTM_PL_TT);
 
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
@@ -379,7 +379,6 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, 
bool evict,
 
 static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct 
ttm_mem_reg *mem)
 {
-   struct ttm_mem_type_manager *man = >man[mem->mem_type];
struct radeon_device *rdev = radeon_get_rdev(bdev);
 
mem->bus.addr = NULL;
@@ -826,8 +825,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
}
radeon_bo_unref(>stolen_vga_memory);
}
-   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_VRAM]);
-   ttm_bo_man_takedown(>mman.bdev, >mman.bdev.man[TTM_PL_TT]);
+   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, TTM_PL_VRAM));
+   ttm_bo_man_takedown(>mman.bdev, 
ttm_manager_type(>mman.bdev, TTM_PL_TT));
ttm_bo_device_release(>mman.bdev);
radeon_gart_fini(rdev);
rdev->mman.initialized = false;
@@ -843,7 +842,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device 
*rdev, u64 size)
if (!rdev->mman.initialized)
return;
 
-   man = >mman.bdev.man[TTM_PL_VRAM];
+   man = ttm_manager_type(>mman.bdev, TTM_PL_VRAM);
/* this just adjusts TTM size idea, which sets lpfn to the correct 
value */
man->size = size >> PAGE_SHIFT;
 }
@@ -897,7 +896,7 @@ static int radeon_mm_dump_table(struct seq_file *m, void 
*data)
unsigned ttm_pl = *(int*)node->info_ent->data;
struct drm_device *dev = node->minor->dev;
struct radeon_device *rdev = dev->dev_private;
-   struct ttm_mem_type_manager *man = >mman.bdev.man[ttm_pl];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
ttm_pl);
struct drm_printer p = drm_seq_file_printer(m);
 
man->func->debug(man, );
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 28/49] drm/vram-helper: use wrapper to access memory managers

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index c6cc90d42f56..08fbfa32540a 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1075,7 +1075,7 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void 
*data)
 {
struct drm_info_node *node = (struct drm_info_node *) m->private;
struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
-   struct ttm_mem_type_manager *man = >bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>bdev, 
TTM_PL_VRAM);
struct drm_printer p = drm_seq_file_printer(m);
 
man->func->debug(man, );
@@ -1103,7 +1103,7 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
 static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
uint64_t vram_base, size_t vram_size)
 {
-   struct ttm_mem_type_manager *man = >bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>bdev, 
TTM_PL_VRAM);
int ret;
 
vmm->vram_base = vram_base;
@@ -1127,7 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, 
struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
-   ttm_bo_man_takedown(>bdev, >bdev.man[TTM_PL_VRAM]);
+   ttm_bo_man_takedown(>bdev, ttm_manager_type(>bdev, 
TTM_PL_VRAM));
ttm_bo_device_release(>bdev);
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This is probably something we could consider removing, vmwgfx
is the only user, and we might be able to faciliate it another way

but for now just consolidate it all into accessors.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_ttm.c |  8 
 drivers/gpu/drm/ttm/ttm_bo.c  |  6 +++---
 drivers/gpu/drm/ttm/ttm_bo_manager.c  |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   | 14 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c   |  4 ++--
 include/drm/ttm/ttm_bo_driver.h   |  8 
 9 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index b4480ca30988..7e84aa2c0064 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -128,7 +128,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
}
 
ttm_set_driver_manager(>mman.bdev, TTM_PL_TT, >manager);
-   ttm_bo_use_mm(man);
+   ttm_mm_set_use(man, true);
return 0;
 }
 
@@ -146,7 +146,7 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
int ret;
 
-   ttm_bo_disable_mm(man);
+   ttm_mm_set_use(man, false);
 
ret = ttm_bo_force_list_clean(>mman.bdev, man);
if (ret)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index f0e65a6fdf88..50949aa968fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -205,7 +205,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
DRM_ERROR("Failed to register sysfs\n");
 
ttm_set_driver_manager(>mman.bdev, TTM_PL_VRAM, >manager);
-   ttm_bo_use_mm(man);
+   ttm_mm_set_use(man, true);
return 0;
 }
 
@@ -223,7 +223,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
int ret;
 
-   ttm_bo_disable_mm(man);
+   ttm_mm_set_use(man, false);
 
ret = ttm_bo_force_list_clean(>mman.bdev, man);
if (ret)
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 89521d3ed9da..32ce930d1bd8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -176,7 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
man->use_io_reserve_lru = true;
ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_VRAM, man);
-   ttm_bo_use_mm(man);
+   ttm_mm_set_use(man, true);
return 0;
} else {
return ttm_bo_man_init(>ttm.bdev, TTM_PL_VRAM,
@@ -192,7 +192,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_VRAM);
 
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
-   ttm_bo_disable_mm(man);
+   ttm_mm_set_use(man, false);
ttm_bo_force_list_clean(>ttm.bdev, man);
ttm_bo_man_cleanup(man);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_VRAM, NULL);
@@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
man->use_tt = true;
ttm_bo_init_mm_base(man, size_pages);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_TT, man);
-   ttm_bo_use_mm(man);
+   ttm_mm_set_use(man, true);
return 0;
 }
 
@@ -250,7 +250,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
drm->agp.bridge)
ttm_bo_man_takedown(>ttm.bdev, TTM_PL_TT);
else {
-   ttm_bo_disable_mm(man);
+   ttm_mm_set_use(man, false);
ttm_bo_force_list_clean(>ttm.bdev, man);
ttm_bo_man_cleanup(man);
ttm_set_driver_manager(>ttm.bdev, TTM_PL_TT, NULL);
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bfc20cb27ed6..3bec6e4bc87d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object 
*bo,
return ret;
 
man = ttm_manager_type(bdev, mem_type);
-   if (!man || !man->use_type)
+   if (!man || !ttm_mm_used(man))
return -EBUSY;
 
if (!ttm_bo_mt_compatible(man, mem_type, place, _flags))
@@ -1548,7 +1548,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
struct ttm_mem_type_manager *man;
 
man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
-   

[PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 32 +---
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 2f5fa44b6474..2782ccff9b66 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -44,16 +44,22 @@
  */
 
 struct ttm_range_manager {
+   struct ttm_mem_type_manager manager;
struct drm_mm mm;
spinlock_t lock;
 };
 
+static inline struct ttm_range_manager *to_range_manager(struct 
ttm_mem_type_manager *man)
+{
+   return container_of(man, struct ttm_range_manager, manager);
+}
+
 static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
   struct ttm_buffer_object *bo,
   const struct ttm_place *place,
   struct ttm_mem_reg *mem)
 {
-   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+   struct ttm_range_manager *rman = to_range_manager(man);
struct drm_mm *mm = >mm;
struct drm_mm_node *node;
enum drm_mm_insert_mode mode;
@@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager 
*man,
 static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
struct ttm_mem_reg *mem)
 {
-   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+   struct ttm_range_manager *rman = to_range_manager(man);
 
if (mem->mm_node) {
spin_lock(>lock);
@@ -113,25 +119,26 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
bool use_tt,
unsigned long p_size)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
+   struct ttm_mem_type_manager *man;
struct ttm_range_manager *rman;
 
-   man->available_caching = available_caching;
-   man->default_caching = default_caching;
-   man->use_tt = use_tt;
-
rman = kzalloc(sizeof(*rman), GFP_KERNEL);
if (!rman)
return -ENOMEM;
 
+   man = >manager;
+   man->available_caching = available_caching;
+   man->default_caching = default_caching;
+   man->use_tt = use_tt;
+
man->func = _bo_manager_func;
 
ttm_bo_init_mm_base(bdev, man, p_size);
 
drm_mm_init(>mm, 0, p_size);
spin_lock_init(>lock);
-   man->priv = rman;
 
+   ttm_set_driver_manager(bdev, type, >manager);
ttm_bo_use_mm(man);
return 0;
 }
@@ -141,7 +148,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
unsigned type)
 {
struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
-   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+   struct ttm_range_manager *rman = to_range_manager(man);
struct drm_mm *mm = >mm;
int ret;
 
@@ -155,10 +162,11 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
drm_mm_clean(mm);
drm_mm_takedown(mm);
spin_unlock(>lock);
-   kfree(rman);
-   man->priv = NULL;
 
ttm_bo_man_cleanup(man);
+   ttm_set_driver_manager(bdev, type, NULL);
+   kfree(rman);
+
return 0;
 }
 EXPORT_SYMBOL(ttm_bo_man_takedown);
@@ -166,7 +174,7 @@ EXPORT_SYMBOL(ttm_bo_man_takedown);
 static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 struct drm_printer *printer)
 {
-   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+   struct ttm_range_manager *rman = to_range_manager(man);
 
spin_lock(>lock);
drm_mm_print(>mm, printer);
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless ttm debug callback

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 3fa809b5e3bd..2db99f0449b0 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -149,14 +149,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, 
int type)
ttm_bo_man_cleanup(man);
 }
 
-static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
-   struct drm_printer *printer)
-{
-   drm_printf(printer, "No debug info available for the GMR id manager\n");
-}
-
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
.get_node = vmw_gmrid_man_get_node,
.put_node = vmw_gmrid_man_put_node,
-   .debug = vmw_gmrid_man_debug
 };
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 35 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 36 +---
 2 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 0b0d09d19b4f..83d88ee73468 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -25,11 +25,17 @@
 #include "amdgpu.h"
 
 struct amdgpu_gtt_mgr {
+   struct ttm_mem_type_manager manager;
struct drm_mm mm;
spinlock_t lock;
atomic64_t available;
 };
 
+static inline struct amdgpu_gtt_mgr *to_gtt_mgr(struct ttm_mem_type_manager 
*man)
+{
+   return container_of(man, struct amdgpu_gtt_mgr, manager);
+}
+
 struct amdgpu_gtt_node {
struct drm_mm_node node;
struct ttm_buffer_object *tbo;
@@ -87,11 +93,16 @@ static const struct ttm_mem_type_manager_func 
amdgpu_gtt_mgr_func;
  */
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 {
-   struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
TTM_PL_TT);
+   struct ttm_mem_type_manager *man;
struct amdgpu_gtt_mgr *mgr;
uint64_t start, size;
int ret;
 
+   mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
+   if (!mgr)
+   return -ENOMEM;
+
+   man = >manager;
man->use_tt = true;
man->func = _gtt_mgr_func;
man->available_caching = TTM_PL_MASK_CACHING;
@@ -99,16 +110,11 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
 
ttm_bo_init_mm_base(>mman.bdev, man, gtt_size >> PAGE_SHIFT);
 
-   mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-   if (!mgr)
-   return -ENOMEM;
-
start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
drm_mm_init(>mm, start, size);
spin_lock_init(>lock);
atomic64_set(>available, gtt_size >> PAGE_SHIFT);
-   man->priv = mgr;
 
ret = device_create_file(adev->dev, _attr_mem_info_gtt_total);
if (ret) {
@@ -121,6 +127,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
return ret;
}
 
+   ttm_set_driver_manager(>mman.bdev, TTM_PL_TT, >manager);
ttm_bo_use_mm(man);
return 0;
 }
@@ -136,7 +143,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
 void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
struct ttm_mem_type_manager *man = ttm_manager_type(>mman.bdev, 
TTM_PL_TT);
-   struct amdgpu_gtt_mgr *mgr = man->priv;
+   struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
int ret;
 
ttm_bo_disable_mm(man);
@@ -148,13 +155,13 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
spin_lock(>lock);
drm_mm_takedown(>mm);
spin_unlock(>lock);
-   kfree(mgr);
-   man->priv = NULL;
 
device_remove_file(adev->dev, _attr_mem_info_gtt_total);
device_remove_file(adev->dev, _attr_mem_info_gtt_used);
 
ttm_bo_man_cleanup(man);
+   ttm_set_driver_manager(>mman.bdev, TTM_PL_TT, NULL);
+   kfree(mgr);
 }
 
 /**
@@ -184,7 +191,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager 
*man,
  const struct ttm_place *place,
  struct ttm_mem_reg *mem)
 {
-   struct amdgpu_gtt_mgr *mgr = man->priv;
+   struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
struct amdgpu_gtt_node *node;
int r;
 
@@ -245,7 +252,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager 
*man,
 static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager *man,
   struct ttm_mem_reg *mem)
 {
-   struct amdgpu_gtt_mgr *mgr = man->priv;
+   struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
struct amdgpu_gtt_node *node = mem->mm_node;
 
if (node) {
@@ -267,7 +274,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager 
*man,
  */
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man)
 {
-   struct amdgpu_gtt_mgr *mgr = man->priv;
+   struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
s64 result = man->size - atomic64_read(>available);
 
return (result > 0 ? result : 0) * PAGE_SIZE;
@@ -275,7 +282,7 @@ uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager 
*man)
 
 int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
 {
-   struct amdgpu_gtt_mgr *mgr = man->priv;
+   struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
struct amdgpu_gtt_node *node;
struct drm_mm_node *mm_node;
int r = 0;
@@ -303,7 +310,7 @@ int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
 static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
 struct drm_printer 

[PATCH 34/49] drm/ttm: make manager debug function optional

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 92de8a6d7647..1e8fda1c9b3a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -88,7 +88,7 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, 
struct drm_printer *p
drm_printf(p, "size: %llu\n", man->size);
drm_printf(p, "available_caching: 0x%08X\n", 
man->available_caching);
drm_printf(p, "default_caching: 0x%08X\n", man->default_caching);
-   if (mem_type != TTM_PL_SYSTEM)
+   if (mem_type != TTM_PL_SYSTEM && man->func->debug)
(*man->func->debug)(man, p);
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 32/49] drm/vmwgfx/ttm: use wrapper to access memory manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   | 21 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c   |  4 ++--
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index b27f8b3699cf..dff6990ff9ed 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -634,7 +634,7 @@ static int vmw_init_vram_manager(struct vmw_private 
*dev_priv)
ret = ttm_bo_man_init(_priv->bdev, man,
  dev_priv->vram_size >> PAGE_SHIFT);
 #endif
-   dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+   ttm_manager_type(_priv->bdev, TTM_PL_VRAM)->use_type = false;
return ret;
 }
 
@@ -644,7 +644,7 @@ static void vmw_takedown_vram_manager(struct vmw_private 
*dev_priv)
vmw_thp_takedown(dev_priv);
 #else
ttm_bo_man_takedown(_priv->bdev,
-   _priv->bdev.man[TTM_PL_VRAM]);
+   ttm_manager_type(_priv->bdev, TTM_PL_VRAM));
 #endif
 }
 
@@ -1192,10 +1192,12 @@ static void vmw_master_drop(struct drm_device *dev,
  */
 static void __vmw_svga_enable(struct vmw_private *dev_priv)
 {
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
+
spin_lock(_priv->svga_lock);
-   if (!dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
+   if (!man->use_type) {
vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
-   dev_priv->bdev.man[TTM_PL_VRAM].use_type = true;
+   man->use_type = true;
}
spin_unlock(_priv->svga_lock);
 }
@@ -1221,9 +1223,11 @@ void vmw_svga_enable(struct vmw_private *dev_priv)
  */
 static void __vmw_svga_disable(struct vmw_private *dev_priv)
 {
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
+
spin_lock(_priv->svga_lock);
-   if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
-   dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+   if (man->use_type) {
+   man->use_type = false;
vmw_write(dev_priv, SVGA_REG_ENABLE,
  SVGA_REG_ENABLE_HIDE |
  SVGA_REG_ENABLE_ENABLE);
@@ -1240,6 +1244,7 @@ static void __vmw_svga_disable(struct vmw_private 
*dev_priv)
  */
 void vmw_svga_disable(struct vmw_private *dev_priv)
 {
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
/*
 * Disabling SVGA will turn off device modesetting capabilities, so
 * notify KMS about that so that it doesn't cache atomic state that
@@ -1255,8 +1260,8 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
vmw_kms_lost_device(dev_priv->dev);
ttm_write_lock(_priv->reservation_sem, false);
spin_lock(_priv->svga_lock);
-   if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
-   dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+   if (man->use_type) {
+   man->use_type = false;
spin_unlock(_priv->svga_lock);
if (ttm_bo_evict_mm(_priv->bdev, TTM_PL_VRAM))
DRM_ERROR("Failed evicting VRAM buffers.\n");
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 2522927b75da..3fa809b5e3bd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -98,7 +98,7 @@ static const struct ttm_mem_type_manager_func 
vmw_gmrid_manager_func;
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-   struct ttm_mem_type_manager *man = _priv->bdev.man[type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
type);
struct vmwgfx_gmrid_man *gman =
kzalloc(sizeof(*gman), GFP_KERNEL);
 
@@ -133,7 +133,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int 
type)
 
 void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
-   struct ttm_mem_type_manager *man = _priv->bdev.man[type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
type);
struct vmwgfx_gmrid_man *gman =
(struct vmwgfx_gmrid_man *)man->priv;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index 3591a93dad37..0dd619c9d207 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -117,7 +117,7 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager 
*man,
 
 int vmw_thp_init(struct vmw_private *dev_priv)
 {
-   struct ttm_mem_type_manager *man = _priv->bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(_priv->bdev, 
TTM_PL_VRAM);
struct vmw_thp_manager *rman;
man->available_caching = 

[PATCH 09/49] drm/nouveau: use new memory manager init paths

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 43 ---
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index b0012021ae12..e3c57c612765 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -31,12 +31,6 @@
 
 #include 
 
-static int
-nouveau_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
-{
-   return 0;
-}
-
 static int
 nouveau_manager_fini(struct ttm_mem_type_manager *man)
 {
@@ -82,7 +76,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
-   .init = nouveau_manager_init,
.takedown = nouveau_manager_fini,
.get_node = nouveau_vram_manager_new,
.put_node = nouveau_manager_del,
@@ -108,7 +101,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
-   .init = nouveau_manager_init,
.takedown = nouveau_manager_fini,
.get_node = nouveau_gart_manager_new,
.put_node = nouveau_manager_del,
@@ -143,7 +135,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
-   .init = nouveau_manager_init,
.takedown = nouveau_manager_fini,
.get_node = nv04_gart_manager_new,
.put_node = nouveau_manager_del,
@@ -200,27 +191,21 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 
man->func = _vram_manager;
man->use_io_reserve_lru = true;
+   ttm_bo_init_mm_base(>ttm.bdev, man,
+   drm->gem.vram_available >> PAGE_SHIFT);
+   ttm_bo_use_mm(man);
+   return 0;
} else {
-   man->func = _bo_manager_func;
+   return ttm_bo_man_init(>ttm.bdev, man,
+  drm->gem.vram_available >> PAGE_SHIFT);
}
-
-   return ttm_bo_init_mm(>ttm.bdev, TTM_PL_VRAM,
- drm->gem.vram_available >> PAGE_SHIFT);
 }
 
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_TT];
-
-   if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
-   man->func = _gart_manager;
-   else
-   if (!drm->agp.bridge)
-   man->func = _gart_manager;
-   else
-   man->func = _bo_manager_func;
-
+   unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
man->use_tt = true;
if (drm->agp.bridge) {
man->available_caching = TTM_PL_FLAG_UNCACHED |
@@ -231,8 +216,18 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
man->default_caching = TTM_PL_FLAG_CACHED;
}
 
-   return ttm_bo_init_mm(>ttm.bdev, TTM_PL_TT,
- drm->gem.gart_available >> PAGE_SHIFT);
+   if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
+   man->func = _gart_manager;
+   else if (!drm->agp.bridge)
+   man->func = _gart_manager;
+   else
+   return ttm_bo_man_init(>ttm.bdev, man,
+  size_pages);
+
+   ttm_bo_init_mm_base(>ttm.bdev, man,
+   size_pages);
+   ttm_bo_use_mm(man);
+   return 0;
 }
 
 int
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This will allow different abstractions later.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c  | 34 +++
 drivers/gpu/drm/ttm/ttm_bo_util.c | 20 +-
 drivers/gpu/drm/ttm/ttm_bo_vm.c   |  2 +-
 include/drm/ttm/ttm_bo_driver.h   |  6 ++
 4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 07c653374f15..7c6389ea067f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -80,7 +80,7 @@ static inline int ttm_mem_type_from_place(const struct 
ttm_place *place,
 static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer 
*p,
   int mem_type)
 {
-   struct ttm_mem_type_manager *man = >man[mem_type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
 
drm_printf(p, "has_type: %d\n", man->has_type);
drm_printf(p, "use_type: %d\n", man->use_type);
@@ -156,7 +156,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object 
*bo,
if (mem->placement & TTM_PL_FLAG_NO_EVICT)
return;
 
-   man = >man[mem->mem_type];
+   man = ttm_manager_type(bdev, mem->mem_type);
list_add_tail(>lru, >lru[bo->priority]);
 
if (man->use_tt && bo->ttm &&
@@ -231,7 +231,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move 
*bulk)
dma_resv_assert_held(pos->first->base.resv);
dma_resv_assert_held(pos->last->base.resv);
 
-   man = >first->bdev->man[TTM_PL_TT];
+   man = ttm_manager_type(pos->first->bdev, TTM_PL_TT);
list_bulk_move_tail(>lru[i], >first->lru,
>last->lru);
}
@@ -246,7 +246,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move 
*bulk)
dma_resv_assert_held(pos->first->base.resv);
dma_resv_assert_held(pos->last->base.resv);
 
-   man = >first->bdev->man[TTM_PL_VRAM];
+   man = ttm_manager_type(pos->first->bdev, TTM_PL_VRAM);
list_bulk_move_tail(>lru[i], >first->lru,
>last->lru);
}
@@ -272,8 +272,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object 
*bo,
  struct ttm_operation_ctx *ctx)
 {
struct ttm_bo_device *bdev = bo->bdev;
-   struct ttm_mem_type_manager *old_man = >man[bo->mem.mem_type];
-   struct ttm_mem_type_manager *new_man = >man[mem->mem_type];
+   struct ttm_mem_type_manager *old_man = ttm_manager_type(bdev, 
bo->mem.mem_type);
+   struct ttm_mem_type_manager *new_man = ttm_manager_type(bdev, 
mem->mem_type);
int ret;
 
ret = ttm_mem_io_lock(old_man, true);
@@ -338,7 +338,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object 
*bo,
return 0;
 
 out_err:
-   new_man = >man[bo->mem.mem_type];
+   new_man = ttm_manager_type(bdev, bo->mem.mem_type);
if (!new_man->use_tt) {
ttm_tt_destroy(bo->ttm);
bo->ttm = NULL;
@@ -550,7 +550,7 @@ static void ttm_bo_release(struct kref *kref)
struct ttm_buffer_object *bo =
container_of(kref, struct ttm_buffer_object, kref);
struct ttm_bo_device *bdev = bo->bdev;
-   struct ttm_mem_type_manager *man = >man[bo->mem.mem_type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(bdev, 
bo->mem.mem_type);
size_t acc_size = bo->acc_size;
int ret;
 
@@ -838,7 +838,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
  const struct ttm_place *place,
  struct ttm_mem_reg *mem)
 {
-   struct ttm_mem_type_manager *man = >bdev->man[mem->mem_type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, 
mem->mem_type);
 
mem->mm_node = NULL;
if (!man->func || !man->func->get_node)
@@ -849,7 +849,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
 
 void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
 {
-   struct ttm_mem_type_manager *man = >bdev->man[mem->mem_type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, 
mem->mem_type);
 
if (!man->func || !man->func->put_node)
return;
@@ -906,7 +906,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object 
*bo,
  struct ttm_operation_ctx *ctx)
 {
struct ttm_bo_device *bdev = bo->bdev;
-   struct ttm_mem_type_manager *man = >man[mem->mem_type];
+   struct ttm_mem_type_manager *man = ttm_manager_type(bdev, 
mem->mem_type);
struct ww_acquire_ctx *ticket;
int ret;
 
@@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object 
*bo,
if (ret)
return ret;
 
-   man = >man[mem_type];
+   man = 

[PATCH 29/49] drm/nouveau/ttm: use wrapper to access memory managers

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 2ccfdf203c52..ed651d7679fe 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -165,7 +165,7 @@ nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
 static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_VRAM);
struct nvif_mmu *mmu = >client.mmu;
 
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
@@ -195,7 +195,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 static void
 nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_VRAM];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_VRAM);
 
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
ttm_bo_disable_mm(man);
@@ -208,7 +208,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_TT];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_TT);
unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
man->use_tt = true;
if (drm->agp.bridge) {
@@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 static void
 nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 {
-   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_TT];
+   struct ttm_mem_type_manager *man = ttm_manager_type(>ttm.bdev, 
TTM_PL_TT);
 
if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
drm->agp.bridge)
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 33/49] drm/ttm: rename manager variable to make sure wrapper is used.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Other users of this should notice this change and switch to wrapper.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c| 2 +-
 include/drm/ttm/ttm_bo_driver.h | 7 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 7c6389ea067f..92de8a6d7647 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1610,7 +1610,7 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
bdev->driver = driver;
 
-   memset(bdev->man, 0, sizeof(bdev->man));
+   memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
 
ttm_bo_init_sysman(bdev);
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index ec25451b503f..419b088253cf 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -415,7 +415,10 @@ struct ttm_bo_device {
 */
struct list_head device_list;
struct ttm_bo_driver *driver;
-   struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES];
+   /*
+* access via ttm_manager_type.
+*/
+   struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
 
/*
 * Protected by internal locks.
@@ -447,7 +450,7 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct 
ttm_bo_device *bdev,
int mem_type)
 {
-   return >man[mem_type];
+   return >man_priv[mem_type];
 }
 
 /**
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index ed651d7679fe..1b9d9362132d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -37,12 +37,6 @@ nouveau_manager_del(struct ttm_mem_type_manager *man, struct 
ttm_mem_reg *reg)
nouveau_mem_del(reg);
 }
 
-static void
-nouveau_manager_debug(struct ttm_mem_type_manager *man,
- struct drm_printer *printer)
-{
-}
-
 static int
 nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 struct ttm_buffer_object *bo,
@@ -72,7 +66,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
.get_node = nouveau_vram_manager_new,
.put_node = nouveau_manager_del,
-   .debug = nouveau_manager_debug,
 };
 
 static int
@@ -96,7 +89,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
.get_node = nouveau_gart_manager_new,
.put_node = nouveau_manager_del,
-   .debug = nouveau_manager_debug
 };
 
 static int
@@ -129,7 +121,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
.get_node = nv04_gart_manager_new,
.put_node = nouveau_manager_del,
-   .debug = nouveau_manager_debug
 };
 
 int
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

drivers should all be cleaning up their memory managers
themselves now, so let the core just clean the system one up.

Remove the legacy cleaning interface.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c| 55 +++--
 include/drm/ttm/ttm_bo_api.h| 28 -
 include/drm/ttm/ttm_bo_driver.h | 10 --
 3 files changed, 4 insertions(+), 89 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f0f0f3101bd1..07c653374f15 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1446,43 +1446,6 @@ int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_force_list_clean);
 
-int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
-{
-   struct ttm_mem_type_manager *man;
-   int ret = -EINVAL;
-
-   if (mem_type >= TTM_NUM_MEM_TYPES) {
-   pr_err("Illegal memory type %d\n", mem_type);
-   return ret;
-   }
-   man = >man[mem_type];
-
-   if (!man->has_type) {
-   pr_err("Trying to take down uninitialized memory manager type 
%u\n",
-  mem_type);
-   return ret;
-   }
-
-   ttm_bo_disable_mm(man);
-
-   ret = 0;
-   if (mem_type > 0) {
-   ret = ttm_bo_force_list_clean(bdev, man);
-   if (ret) {
-   pr_err("Cleanup eviction failed\n");
-   return ret;
-   }
-
-   if (man->func->takedown)
-   ret = (*man->func->takedown)(man);
-   }
-
-   ttm_bo_man_cleanup(man);
-
-   return ret;
-}
-EXPORT_SYMBOL(ttm_bo_clean_mm);
-
 int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 {
struct ttm_mem_type_manager *man = >man[mem_type];
@@ -1585,21 +1548,11 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 {
struct ttm_bo_global *glob = _bo_glob;
int ret = 0;
-   unsigned i = TTM_NUM_MEM_TYPES;
+   unsigned i;
struct ttm_mem_type_manager *man;
 
-   while (i--) {
-   man = >man[i];
-   if (man->has_type) {
-   man->use_type = false;
-   if ((i != TTM_PL_SYSTEM) && ttm_bo_clean_mm(bdev, i)) {
-   ret = -EBUSY;
-   pr_err("DRM memory manager type %d is not 
clean\n",
-  i);
-   }
-   man->has_type = false;
-   }
-   }
+   man = >man[TTM_PL_SYSTEM];
+   ttm_bo_disable_mm(man);
 
mutex_lock(_global_mutex);
list_del(>device_list);
@@ -1612,7 +1565,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 
spin_lock(>lru_lock);
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
-   if (list_empty(>man[0].lru[0]))
+   if (list_empty(>lru[0]))
pr_debug("Swap list %d was clean\n", i);
spin_unlock(>lru_lock);
 
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 6562d1c5ac59..27dde1371376 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -551,34 +551,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 struct ttm_mem_type_manager *man,
 unsigned long p_size);
 
-/**
- * ttm_bo_clean_mm
- *
- * @bdev: Pointer to a ttm_bo_device struct.
- * @mem_type: The memory type.
- *
- * Take down a manager for a given memory type after first walking
- * the LRU list to evict any buffers left alive.
- *
- * Normally, this function is part of lastclose() or unload(), and at that
- * point there shouldn't be any buffers left created by user-space, since
- * there should've been removed by the file descriptor release() method.
- * However, before this function is run, make sure to signal all sync objects,
- * and verify that the delayed delete queue is empty. The driver must also
- * make sure that there are no NO_EVICT buffers present in this memory type
- * when the call is made.
- *
- * If this function is part of a VT switch, the caller must make sure that
- * there are no appications currently validating buffers before this
- * function is called. The caller can do that by first taking the
- * struct ttm_bo_device::ttm_lock in write mode.
- *
- * Returns:
- * -EINVAL: invalid or uninitialized memory type.
- * -EBUSY: There are still buffers left in this memory type.
- */
-int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
-
 /**
  * ttm_bo_evict_mm
  *
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 2ef33b407167..9d066529ca61 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -48,16 +48,6 @@
 struct ttm_mem_type_manager;
 
 struct ttm_mem_type_manager_func {
-   /**
-* struct 

[PATCH 17/49] drm/amdgpu/ttm: use new takedown path

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 15 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c  | 10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h  |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 15 +++
 4 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 5f58aa2eac4a..f4c870b2f348 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -133,10 +133,18 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, 
uint64_t gtt_size)
  * Destroy and free the GTT manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
-   struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_TT];
struct amdgpu_gtt_mgr *mgr = man->priv;
+   int ret;
+
+   ttm_bo_disable_mm(man);
+
+   ret = ttm_bo_force_list_clean(>mman.bdev, man);
+   if (ret)
+   return;
+
spin_lock(>lock);
drm_mm_takedown(>mm);
spin_unlock(>lock);
@@ -146,7 +154,7 @@ static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager 
*man)
device_remove_file(adev->dev, _attr_mem_info_gtt_total);
device_remove_file(adev->dev, _attr_mem_info_gtt_used);
 
-   return 0;
+   ttm_bo_man_cleanup(man);
 }
 
 /**
@@ -307,7 +315,6 @@ static void amdgpu_gtt_mgr_debug(struct 
ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
-   .takedown = amdgpu_gtt_mgr_fini,
.get_node = amdgpu_gtt_mgr_new,
.put_node = amdgpu_gtt_mgr_del,
.debug = amdgpu_gtt_mgr_debug
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index f1bf86b8de14..b1452df8fce9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2012,11 +2012,11 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
iounmap(adev->mman.aper_base_kaddr);
adev->mman.aper_base_kaddr = NULL;
 
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_VRAM);
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_TT);
-   ttm_bo_clean_mm(>mman.bdev, AMDGPU_PL_GDS);
-   ttm_bo_clean_mm(>mman.bdev, AMDGPU_PL_GWS);
-   ttm_bo_clean_mm(>mman.bdev, AMDGPU_PL_OA);
+   amdgpu_vram_mgr_fini(adev);
+   amdgpu_gtt_mgr_fini(adev);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[AMDGPU_PL_GDS]);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[AMDGPU_PL_GWS]);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[AMDGPU_PL_OA]);
ttm_bo_device_release(>mman.bdev);
adev->mman.initialized = false;
DRM_INFO("amdgpu: ttm finalized\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index fb45c0a323b0..c01fdb3f0458 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -68,7 +68,9 @@ struct amdgpu_copy_mem {
 };
 
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size);
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev);
 int amdgpu_vram_mgr_init(struct amdgpu_device *adev);
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
 
 bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 1bc04835c24f..cc45be8ccb0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -205,10 +205,17 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 {
-   struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_VRAM];
struct amdgpu_vram_mgr *mgr = man->priv;
+   int ret;
+
+   ttm_bo_disable_mm(man);
+
+   ret = ttm_bo_force_list_clean(>mman.bdev, man);
+   if (ret)
+   return;
 
spin_lock(>lock);
drm_mm_takedown(>mm);
@@ -216,7 +223,8 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager 
*man)
kfree(mgr);
man->priv = NULL;
sysfs_remove_files(>dev->kobj, amdgpu_vram_mgr_attributes);
-   return 0;
+
+   ttm_bo_man_cleanup(man);
 }
 
 /**
@@ -596,7 +604,6 @@ static void amdgpu_vram_mgr_debug(struct 
ttm_mem_type_manager *man,
 }
 
 static const struct 

[PATCH 24/49] drm/ttm: remove range manager legacy takedown path

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Now no drivers have been converted, drop the non-driver path.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 28 +---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 1127868274b3..f60a9a5d429d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -129,26 +129,11 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_man_init);
 
-static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
-{
-   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
-   struct drm_mm *mm = >mm;
-
-   spin_lock(>lock);
-   if (drm_mm_clean(mm)) {
-   drm_mm_takedown(mm);
-   spin_unlock(>lock);
-   kfree(rman);
-   man->priv = NULL;
-   return 0;
-   }
-   spin_unlock(>lock);
-   return -EBUSY;
-}
-
 int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
struct ttm_mem_type_manager *man)
 {
+   struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+   struct drm_mm *mm = >mm;
int ret;
 
ttm_bo_disable_mm(man);
@@ -157,7 +142,13 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
if (ret)
return ret;
 
-   ttm_bo_man_takedown_private(man);
+   spin_lock(>lock);
+   drm_mm_clean(mm);
+   drm_mm_takedown(mm);
+   spin_unlock(>lock);
+   kfree(rman);
+   man->priv = NULL;
+
ttm_bo_man_cleanup(man);
return 0;
 }
@@ -174,7 +165,6 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager 
*man,
 }
 
 static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-   .takedown = ttm_bo_man_takedown_private,
.get_node = ttm_bo_man_get_node,
.put_node = ttm_bo_man_put_node,
.debug = ttm_bo_man_debug
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 07/49] drm/qxl/ttm: use new init path for manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/qxl/qxl_ttm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 59478761efe8..ac22971cd20b 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -221,11 +221,10 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
 {
struct ttm_mem_type_manager *man = >mman.bdev.man[type];
 
-   man->func = _bo_manager_func;
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
 
-   return ttm_bo_init_mm(>mman.bdev, type, size);
+   return ttm_bo_man_init(>mman.bdev, man, size);
 }
 
 int qxl_ttm_init(struct qxl_device *qdev)
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 08/49] drm/vram_helper: use new ttm manager init function

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index b6f158ab0f5a..8a5d45a55ac7 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1116,10 +1116,9 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, 
struct drm_device *dev,
if (ret)
return ret;
 
-   man->func = _bo_manager_func;
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
man->default_caching = TTM_PL_FLAG_WC;
-   ret = ttm_bo_init_mm(>bdev, TTM_PL_VRAM, vram_size >> PAGE_SHIFT);
+   ret = ttm_bo_man_init(>bdev, man, vram_size >> PAGE_SHIFT);
if (ret)
return ret;
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 13/49] drm/ttm: purge old manager init path.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c | 19 ---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 27 +--
 include/drm/ttm/ttm_bo_api.h |  2 --
 include/drm/ttm/ttm_bo_driver.h  | 14 --
 4 files changed, 9 insertions(+), 53 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 476e768c5bd2..101a7910f9f7 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1523,25 +1523,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_init_mm_base);
 
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-   unsigned long p_size)
-{
-   int ret;
-   struct ttm_mem_type_manager *man;
-
-   BUG_ON(type >= TTM_NUM_MEM_TYPES);
-   ttm_bo_init_mm_base(bdev, >man[type], p_size);
-
-   if (type != TTM_PL_SYSTEM) {
-   ret = (*man->func->init)(man, p_size);
-   if (ret)
-   return ret;
-   }
-   ttm_bo_use_mm(man);
-   return 0;
-}
-EXPORT_SYMBOL(ttm_bo_init_mm);
-
 static void ttm_bo_global_kobj_release(struct kobject *kobj)
 {
struct ttm_bo_global *glob =
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 64234e5caee3..1877425abdf0 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -104,11 +104,18 @@ static void ttm_bo_man_put_node(struct 
ttm_mem_type_manager *man,
}
 }
 
-static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
+static const struct ttm_mem_type_manager_func ttm_bo_manager_func;
+
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man,
unsigned long p_size)
 {
struct ttm_range_manager *rman;
 
+   man->func = _bo_manager_func;
+
+   ttm_bo_init_mm_base(bdev, man, p_size);
+
rman = kzalloc(sizeof(*rman), GFP_KERNEL);
if (!rman)
return -ENOMEM;
@@ -116,21 +123,7 @@ static int ttm_bo_man_init_private(struct 
ttm_mem_type_manager *man,
drm_mm_init(>mm, 0, p_size);
spin_lock_init(>lock);
man->priv = rman;
-   return 0;
-}
 
-int ttm_bo_man_init(struct ttm_bo_device *bdev,
-   struct ttm_mem_type_manager *man,
-   unsigned long p_size)
-{
-   int ret;
-
-   man->func = _bo_manager_func;
-
-   ttm_bo_init_mm_base(bdev, man, p_size);
-   ret = ttm_bo_man_init_private(man, p_size);
-   if (ret)
-   return ret;
ttm_bo_use_mm(man);
return 0;
 }
@@ -163,11 +156,9 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager 
*man,
spin_unlock(>lock);
 }
 
-const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-   .init = ttm_bo_man_init_private,
+static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
.takedown = ttm_bo_man_takedown,
.get_node = ttm_bo_man_get_node,
.put_node = ttm_bo_man_put_node,
.debug = ttm_bo_man_debug
 };
-EXPORT_SYMBOL(ttm_bo_manager_func);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 0060925f507a..6562d1c5ac59 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -550,8 +550,6 @@ struct ttm_mem_type_manager;
 void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 struct ttm_mem_type_manager *man,
 unsigned long p_size);
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-  unsigned long p_size);
 
 /**
  * ttm_bo_clean_mm
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 5c4ccefd5393..d0f1a6cdfba7 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -48,19 +48,6 @@
 struct ttm_mem_type_manager;
 
 struct ttm_mem_type_manager_func {
-   /**
-* struct ttm_mem_type_manager member init
-*
-* @man: Pointer to a memory type manager.
-* @p_size: Implementation dependent, but typically the size of the
-* range to be managed in pages.
-*
-* Called to initialize a private range manager. The function is
-* expected to initialize the man::priv member.
-* Returns 0 on success, negative error code on failure.
-*/
-   int  (*init)(struct ttm_mem_type_manager *man, unsigned long p_size);
-
/**
 * struct ttm_mem_type_manager member takedown
 *
@@ -802,6 +789,5 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
struct ttm_mem_type_manager *man,
unsigned long p_size);
-extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 #endif
-- 
2.26.2

___

[PATCH 18/49] drm/vmwgfx: takedown vram manager

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Don't bother returning EBUSY, nobody cares enough,
if the driver has a problem, it should deal with it.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 13 -
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 23 +--
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 5ee5aa0aaa6a..7d65f9121cd7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -637,6 +637,17 @@ static int vmw_init_vram_manager(struct vmw_private 
*dev_priv)
dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
return ret;
 }
+
+static void vmw_takedown_vram_manager(struct vmw_private *dev_priv)
+{
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+   vmw_thp_takedown(dev_priv);
+#else
+   ttm_bo_man_takedown(_priv->bdev,
+   _priv->bdev.man[TTM_PL_VRAM]);
+#endif
+}
+
 static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 {
struct vmw_private *dev_priv;
@@ -986,7 +997,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned 
long chipset)
(void) ttm_bo_clean_mm(_priv->bdev, VMW_PL_MOB);
if (dev_priv->has_gmr)
(void) ttm_bo_clean_mm(_priv->bdev, VMW_PL_GMR);
-   (void)ttm_bo_clean_mm(_priv->bdev, TTM_PL_VRAM);
+   vmw_takedown_vram_manager(dev_priv);
 out_no_vram:
(void)ttm_bo_device_release(_priv->bdev);
 out_no_bdev:
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 8f319dd6cdb4..b20056fdd042 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1521,6 +1521,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
 /* Transparent hugepage support - vmwgfx_thp.c */
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 extern int vmw_thp_init(struct vmw_private *dev_priv);
+void vmw_thp_takedown(struct vmw_private *dev_priv);
 #endif
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index c4a9bee932c9..3591a93dad37 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -135,21 +135,25 @@ int vmw_thp_init(struct vmw_private *dev_priv)
return 0;
 }
 
-static int vmw_thp_takedown(struct ttm_mem_type_manager *man)
+void vmw_thp_takedown(struct vmw_private *dev_priv)
 {
+   struct ttm_mem_type_manager *man = _priv->bdev.man[TTM_PL_VRAM];
struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
struct drm_mm *mm = >mm;
+   int ret;
+
+   ttm_bo_disable_mm(man);
 
+   ret = ttm_bo_force_list_clean(_priv->bdev, man);
+   if (ret)
+   return;
spin_lock(>lock);
-   if (drm_mm_clean(mm)) {
-   drm_mm_takedown(mm);
-   spin_unlock(>lock);
-   kfree(rman);
-   man->priv = NULL;
-   return 0;
-   }
+   drm_mm_clean(mm);
+   drm_mm_takedown(mm);
spin_unlock(>lock);
-   return -EBUSY;
+   kfree(rman);
+   man->priv = NULL;
+   ttm_bo_man_cleanup(man);
 }
 
 static void vmw_thp_debug(struct ttm_mem_type_manager *man,
@@ -163,7 +167,6 @@ static void vmw_thp_debug(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func vmw_thp_func = {
-   .takedown = vmw_thp_takedown,
.get_node = vmw_thp_get_node,
.put_node = vmw_thp_put_node,
.debug = vmw_thp_debug
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This makes it easier to cleanup things

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 101a7910f9f7..84e399395e4f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -763,13 +763,12 @@ static int ttm_mem_evict_wait_busy(struct 
ttm_buffer_object *busy_bo,
 }
 
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
-  uint32_t mem_type,
+  struct ttm_mem_type_manager *man,
   const struct ttm_place *place,
   struct ttm_operation_ctx *ctx,
   struct ww_acquire_ctx *ticket)
 {
struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
-   struct ttm_mem_type_manager *man = >man[mem_type];
bool locked = false;
unsigned i;
int ret;
@@ -918,7 +917,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object 
*bo,
break;
if (unlikely(ret != -ENOSPC))
return ret;
-   ret = ttm_mem_evict_first(bdev, mem->mem_type, place, ctx,
+   ret = ttm_mem_evict_first(bdev, man, place, ctx,
  ticket);
if (unlikely(ret != 0))
return ret;
@@ -1403,14 +1402,13 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 EXPORT_SYMBOL(ttm_bo_create);
 
 static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-  unsigned mem_type)
+  struct ttm_mem_type_manager *man)
 {
struct ttm_operation_ctx ctx = {
.interruptible = false,
.no_wait_gpu = false,
.flags = TTM_OPT_FLAG_FORCE_ALLOC
};
-   struct ttm_mem_type_manager *man = >man[mem_type];
struct ttm_bo_global *glob = _bo_glob;
struct dma_fence *fence;
int ret;
@@ -1424,7 +1422,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device 
*bdev,
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
while (!list_empty(>lru[i])) {
spin_unlock(>lru_lock);
-   ret = ttm_mem_evict_first(bdev, mem_type, NULL, ,
+   ret = ttm_mem_evict_first(bdev, man, NULL, ,
  NULL);
if (ret)
return ret;
@@ -1469,7 +1467,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
 
ret = 0;
if (mem_type > 0) {
-   ret = ttm_bo_force_list_clean(bdev, mem_type);
+   ret = ttm_bo_force_list_clean(bdev, man);
if (ret) {
pr_err("Cleanup eviction failed\n");
return ret;
@@ -1499,7 +1497,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
return 0;
}
 
-   return ttm_bo_force_list_clean(bdev, mem_type);
+   return ttm_bo_force_list_clean(bdev, man);
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 12/49] drm/ttm: convert system manager init to new code.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Remove the exit path, since this can't fail now.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a658fd584c6d..476e768c5bd2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1644,6 +1644,22 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 }
 EXPORT_SYMBOL(ttm_bo_device_release);
 
+static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
+{
+   struct ttm_mem_type_manager *man = >man[TTM_PL_SYSTEM];
+
+   /*
+* Initialize the system memory buffer type.
+* Other types need to be driver / IOCTL initialized.
+*/
+   man->use_tt = true;
+   man->available_caching = TTM_PL_MASK_CACHING;
+   man->default_caching = TTM_PL_FLAG_CACHED;
+
+   ttm_bo_init_mm_base(bdev, man, 0);
+   ttm_bo_use_mm(man);
+}
+
 int ttm_bo_device_init(struct ttm_bo_device *bdev,
   struct ttm_bo_driver *driver,
   struct address_space *mapping,
@@ -1664,16 +1680,7 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
memset(bdev->man, 0, sizeof(bdev->man));
 
-   /*
-* Initialize the system memory buffer type.
-* Other types need to be driver / IOCTL initialized.
-*/
-   bdev->man[TTM_PL_SYSTEM].use_tt = true;
-   bdev->man[TTM_PL_SYSTEM].available_caching = TTM_PL_MASK_CACHING;
-   bdev->man[TTM_PL_SYSTEM].default_caching = TTM_PL_FLAG_CACHED;
-   ret = ttm_bo_init_mm(bdev, TTM_PL_SYSTEM, 0);
-   if (unlikely(ret != 0))
-   goto out_no_sys;
+   ttm_bo_init_sysman(bdev);
 
bdev->vma_manager = vma_manager;
INIT_DELAYED_WORK(>wq, ttm_bo_delayed_workqueue);
@@ -1685,9 +1692,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
mutex_unlock(_global_mutex);
 
return 0;
-out_no_sys:
-   ttm_bo_global_release();
-   return ret;
 }
 EXPORT_SYMBOL(ttm_bo_device_init);
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 22/49] drm/qxl/ttm: use new takedown path

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/qxl/qxl_ttm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index ac22971cd20b..acc4497887a6 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -266,8 +266,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
 
 void qxl_ttm_fini(struct qxl_device *qdev)
 {
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_VRAM);
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_PRIV);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_VRAM]);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_PRIV]);
ttm_bo_device_release(>mman.bdev);
DRM_INFO("qxl: ttm finalized\n");
 }
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 21/49] drm/radeon/ttm: use new takedown paths

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index a5043a5b7d89..e65297b4b678 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -826,8 +826,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
}
radeon_bo_unref(>stolen_vga_memory);
}
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_VRAM);
-   ttm_bo_clean_mm(>mman.bdev, TTM_PL_TT);
+   ttm_bo_man_takedown(>mman.bdev, 
>mman.bdev.man[TTM_PL_VRAM]);
+   ttm_bo_man_takedown(>mman.bdev, >mman.bdev.man[TTM_PL_TT]);
ttm_bo_device_release(>mman.bdev);
radeon_gart_fini(rdev);
rdev->mman.initialized = false;
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 19/49] drm/vram_helper: call explicit mm takedown

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index 8a5d45a55ac7..c6cc90d42f56 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1127,6 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, 
struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
+   ttm_bo_man_takedown(>bdev, >bdev.man[TTM_PL_VRAM]);
ttm_bo_device_release(>bdev);
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 20/49] drm/nouveau: use new cleanup paths

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 41 ---
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c 
b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index e3c57c612765..2ccfdf203c52 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -31,12 +31,6 @@
 
 #include 
 
-static int
-nouveau_manager_fini(struct ttm_mem_type_manager *man)
-{
-   return 0;
-}
-
 static void
 nouveau_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *reg)
 {
@@ -76,7 +70,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
-   .takedown = nouveau_manager_fini,
.get_node = nouveau_vram_manager_new,
.put_node = nouveau_manager_del,
.debug = nouveau_manager_debug,
@@ -101,7 +94,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
-   .takedown = nouveau_manager_fini,
.get_node = nouveau_gart_manager_new,
.put_node = nouveau_manager_del,
.debug = nouveau_manager_debug
@@ -135,7 +127,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
-   .takedown = nouveau_manager_fini,
.get_node = nv04_gart_manager_new,
.put_node = nouveau_manager_del,
.debug = nouveau_manager_debug
@@ -201,6 +192,19 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
}
 }
 
+static void
+nouveau_ttm_fini_vram(struct nouveau_drm *drm)
+{
+   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_VRAM];
+
+   if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+   ttm_bo_disable_mm(man);
+   ttm_bo_force_list_clean(>ttm.bdev, man);
+   ttm_bo_man_cleanup(man);
+   } else
+   ttm_bo_man_takedown(>ttm.bdev, man);
+}
+
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
@@ -230,6 +234,21 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
return 0;
 }
 
+static void
+nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
+{
+   struct ttm_mem_type_manager *man = >ttm.bdev.man[TTM_PL_TT];
+
+   if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
+   drm->agp.bridge)
+   ttm_bo_man_takedown(>ttm.bdev, man);
+   else {
+   ttm_bo_disable_mm(man);
+   ttm_bo_force_list_clean(>ttm.bdev, man);
+   ttm_bo_man_cleanup(man);
+   }
+}
+
 int
 nouveau_ttm_init(struct nouveau_drm *drm)
 {
@@ -319,8 +338,8 @@ nouveau_ttm_fini(struct nouveau_drm *drm)
 {
struct nvkm_device *device = nvxx_device(>client.device);
 
-   ttm_bo_clean_mm(>ttm.bdev, TTM_PL_VRAM);
-   ttm_bo_clean_mm(>ttm.bdev, TTM_PL_TT);
+   nouveau_ttm_fini_vram(drm);
+   nouveau_ttm_fini_gtt(drm);
 
ttm_bo_device_release(>ttm.bdev);
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c|  6 ++
 include/drm/ttm/ttm_bo_driver.h | 12 
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 84e399395e4f..f584e5e94383 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1462,8 +1462,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
return ret;
}
 
-   man->use_type = false;
-   man->has_type = false;
+   ttm_bo_disable_mm(man);
 
ret = 0;
if (mem_type > 0) {
@@ -1476,8 +1475,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned 
mem_type)
ret = (*man->func->takedown)(man);
}
 
-   dma_fence_put(man->move);
-   man->move = NULL;
+   ttm_bo_man_cleanup(man);
 
return ret;
 }
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index d0f1a6cdfba7..92bb54cce633 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -671,6 +671,18 @@ static inline void ttm_bo_use_mm(struct 
ttm_mem_type_manager *man)
man->use_type = true;
 }
 
+static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
+{
+   man->has_type = false;
+   man->use_type = false;
+}
+
+static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
+{
+   dma_fence_put(man->move);
+   man->move = NULL;
+}
+
 /*
  * ttm_bo_util.c
  */
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 11/49] drm/vmwgfx/ttm: switch gmrid allocator to new init paths.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   | 17 -
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 19 ---
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e11c20150ff6..5ee5aa0aaa6a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -894,14 +894,10 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
 *  slots as well as the bo size.
 */
dev_priv->has_gmr = true;
-   dev_priv->bdev.man[VMW_PL_GMR].func = _gmrid_manager_func;
-   dev_priv->bdev.man[VMW_PL_GMR].available_caching = TTM_PL_FLAG_CACHED;
-   dev_priv->bdev.man[VMW_PL_GMR].default_caching = TTM_PL_FLAG_CACHED;
/* TODO: This is most likely not correct */
-   dev_priv->bdev.man[VMW_PL_GMR].use_tt = true;
if (((dev_priv->capabilities & (SVGA_CAP_GMR | SVGA_CAP_GMR2)) == 0) ||
-   refuse_dma || ttm_bo_init_mm(_priv->bdev, VMW_PL_GMR,
-VMW_PL_GMR) != 0) {
+   refuse_dma ||
+   vmw_gmrid_man_init(dev_priv, VMW_PL_GMR) != 0) {
DRM_INFO("No GMR memory available. "
 "Graphics memory resources are very limited.\n");
dev_priv->has_gmr = false;
@@ -909,13 +905,8 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
 
if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS && !refuse_dma) {
dev_priv->has_mob = true;
-   dev_priv->bdev.man[VMW_PL_MOB].func = _gmrid_manager_func;
-   dev_priv->bdev.man[VMW_PL_MOB].available_caching = 
TTM_PL_FLAG_CACHED;
-   dev_priv->bdev.man[VMW_PL_MOB].default_caching = 
TTM_PL_FLAG_CACHED;
-   /* TODO: This is most likely not correct */
-   dev_priv->bdev.man[VMW_PL_MOB].use_tt = true;
-   if (ttm_bo_init_mm(_priv->bdev, VMW_PL_MOB,
-  VMW_PL_MOB) != 0) {
+
+   if (vmw_gmrid_man_init(dev_priv, VMW_PL_MOB) != 0) {
DRM_INFO("No MOB memory available. "
 "3D will be disabled.\n");
dev_priv->has_mob = false;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 10b681725a53..8f319dd6cdb4 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1221,7 +1221,7 @@ int vmw_overlay_num_free_overlays(struct vmw_private 
*dev_priv);
  * GMR Id manager
  */
 
-extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
 
 /**
  * Prime - vmwgfx_prime.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 4a76fc7114ad..e79d2c8abad2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -94,22 +94,28 @@ static void vmw_gmrid_man_put_node(struct 
ttm_mem_type_manager *man,
}
 }
 
-static int vmw_gmrid_man_init(struct ttm_mem_type_manager *man,
- unsigned long p_size)
+static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
+
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-   struct vmw_private *dev_priv =
-   container_of(man->bdev, struct vmw_private, bdev);
+   struct ttm_mem_type_manager *man = _priv->bdev.man[type];
struct vmwgfx_gmrid_man *gman =
kzalloc(sizeof(*gman), GFP_KERNEL);
 
if (unlikely(!gman))
return -ENOMEM;
 
+   man->func = _gmrid_manager_func;
+   man->available_caching = TTM_PL_FLAG_CACHED;
+   man->default_caching = TTM_PL_FLAG_CACHED;
+   /* TODO: This is most likely not correct */
+   man->use_tt = true;
+   ttm_bo_init_mm_base(_priv->bdev, man, 0);
spin_lock_init(>lock);
gman->used_gmr_pages = 0;
ida_init(>gmr_ida);
 
-   switch (p_size) {
+   switch (type) {
case VMW_PL_GMR:
gman->max_gmr_ids = dev_priv->max_gmr_ids;
gman->max_gmr_pages = dev_priv->max_gmr_pages;
@@ -143,8 +149,7 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager 
*man,
drm_printf(printer, "No debug info available for the GMR id manager\n");
 }
 
-const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-   .init = vmw_gmrid_man_init,
+static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
.takedown = vmw_gmrid_man_takedown,
.get_node = vmw_gmrid_man_get_node,
.put_node = vmw_gmrid_man_put_node,
-- 
2.26.2

___
dri-devel 

[PATCH 10/49] drm/vmwgfx/ttm: convert vram mm init to new code paths

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Split out the vram thp init path vs the range manager init.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 25 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  4 +---
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 12 
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e43f887cafb5..e11c20150ff6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -620,6 +620,23 @@ static int vmw_dma_masks(struct vmw_private *dev_priv)
return ret;
 }
 
+static int vmw_init_vram_manager(struct vmw_private *dev_priv)
+{
+   int ret;
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+   ret = vmw_thp_init(dev_priv);
+#else
+   struct ttm_mem_type_manager *man = _priv->bdev.man[TTM_PL_VRAM];
+
+   man->available_caching = TTM_PL_FLAG_CACHED;
+   man->default_caching = TTM_PL_FLAG_CACHED;
+
+   ret = ttm_bo_man_init(_priv->bdev, man,
+ dev_priv->vram_size >> PAGE_SHIFT);
+#endif
+   dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+   return ret;
+}
 static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 {
struct vmw_private *dev_priv;
@@ -864,16 +881,12 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
 * Enable VRAM, but initially don't use it until SVGA is enabled and
 * unhidden.
 */
-   dev_priv->bdev.man[TTM_PL_VRAM].func = _thp_func;
-   dev_priv->bdev.man[TTM_PL_VRAM].available_caching = TTM_PL_FLAG_CACHED;
-   dev_priv->bdev.man[TTM_PL_VRAM].default_caching = TTM_PL_FLAG_CACHED;
-   ret = ttm_bo_init_mm(_priv->bdev, TTM_PL_VRAM,
-(dev_priv->vram_size >> PAGE_SHIFT));
+
+   ret = vmw_init_vram_manager(dev_priv);
if (unlikely(ret != 0)) {
DRM_ERROR("Failed initializing memory manager for VRAM.\n");
goto out_no_vram;
}
-   dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
 
/*
 * "Guest Memory Regions" is an aperture like feature with
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 65c414f119c0..10b681725a53 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1520,9 +1520,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
 
 /* Transparent hugepage support - vmwgfx_thp.c */
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-extern const struct ttm_mem_type_manager_func vmw_thp_func;
-#else
-#define vmw_thp_func ttm_bo_manager_func
+extern int vmw_thp_init(struct vmw_private *dev_priv);
 #endif
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index b7c816ba7166..c4a9bee932c9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -115,18 +115,23 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager 
*man,
}
 }
 
-static int vmw_thp_init(struct ttm_mem_type_manager *man,
-   unsigned long p_size)
+int vmw_thp_init(struct vmw_private *dev_priv)
 {
+   struct ttm_mem_type_manager *man = _priv->bdev.man[TTM_PL_VRAM];
struct vmw_thp_manager *rman;
+   man->available_caching = TTM_PL_FLAG_CACHED;
+   man->default_caching = TTM_PL_FLAG_CACHED;
 
+   ttm_bo_init_mm_base(_priv->bdev, man,
+   dev_priv->vram_size >> PAGE_SHIFT);
rman = kzalloc(sizeof(*rman), GFP_KERNEL);
if (!rman)
return -ENOMEM;
 
-   drm_mm_init(>mm, 0, p_size);
+   drm_mm_init(>mm, 0, man->size);
spin_lock_init(>lock);
man->priv = rman;
+   ttm_bo_use_mm(man);
return 0;
 }
 
@@ -158,7 +163,6 @@ static void vmw_thp_debug(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func vmw_thp_func = {
-   .init = vmw_thp_init,
.takedown = vmw_thp_takedown,
.get_node = vmw_thp_get_node,
.put_node = vmw_thp_put_node,
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 02/49] drm/vram-helper: call the ttm manager debug function

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This code was assuming there was a drm_mm here, don't do
that call the correct API.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index a93a00966f3a..b6f158ab0f5a 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1075,12 +1075,10 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void 
*data)
 {
struct drm_info_node *node = (struct drm_info_node *) m->private;
struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
-   struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv;
+   struct ttm_mem_type_manager *man = >bdev.man[TTM_PL_VRAM];
struct drm_printer p = drm_seq_file_printer(m);
 
-   spin_lock(_bo_glob.lru_lock);
-   drm_mm_print(mm, );
-   spin_unlock(_bo_glob.lru_lock);
+   man->func->debug(man, );
return 0;
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 03/49] drm/ttm: split the mm manager init code

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This will allow the driver to control the ordering here better.

Eventually the old path will be removed.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo.c| 34 +++--
 include/drm/ttm/ttm_bo_api.h|  4 
 include/drm/ttm/ttm_bo_driver.h |  6 ++
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 041a0e73cd1b..a658fd584c6d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, 
unsigned mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-   unsigned long p_size)
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+struct ttm_mem_type_manager *man,
+unsigned long p_size)
 {
-   int ret;
-   struct ttm_mem_type_manager *man;
unsigned i;
 
-   BUG_ON(type >= TTM_NUM_MEM_TYPES);
-   man = >man[type];
BUG_ON(man->has_type);
man->use_io_reserve_lru = false;
mutex_init(>io_reserve_mutex);
spin_lock_init(>move_lock);
INIT_LIST_HEAD(>io_reserve_lru);
man->bdev = bdev;
-
-   if (type != TTM_PL_SYSTEM) {
-   ret = (*man->func->init)(man, p_size);
-   if (ret)
-   return ret;
-   }
-   man->has_type = true;
-   man->use_type = true;
man->size = p_size;
 
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
INIT_LIST_HEAD(>lru[i]);
man->move = NULL;
+}
+EXPORT_SYMBOL(ttm_bo_init_mm_base);
 
+int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
+   unsigned long p_size)
+{
+   int ret;
+   struct ttm_mem_type_manager *man;
+
+   BUG_ON(type >= TTM_NUM_MEM_TYPES);
+   ttm_bo_init_mm_base(bdev, >man[type], p_size);
+
+   if (type != TTM_PL_SYSTEM) {
+   ret = (*man->func->init)(man, p_size);
+   if (ret)
+   return ret;
+   }
+   ttm_bo_use_mm(man);
return 0;
 }
 EXPORT_SYMBOL(ttm_bo_init_mm);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index a9e13b252820..0060925f507a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned 
long size,
  * -ENOMEM: Not enough memory.
  * May also return driver-specified errors.
  */
+struct ttm_mem_type_manager;
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+struct ttm_mem_type_manager *man,
+unsigned long p_size);
 int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
   unsigned long p_size);
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 7958e411269a..68e75c3b8c7a 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct 
ttm_buffer_object *bo)
dma_resv_unlock(bo->base.resv);
 }
 
+static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
+{
+   man->has_type = true;
+   man->use_type = true;
+}
+
 /*
  * ttm_bo_util.c
  */
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 06/49] drm/radeon: use new ttm man init path

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Use the new common manager init path.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index dbd1d2766279..a5043a5b7d89 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -70,19 +70,17 @@ static int radeon_ttm_init_vram(struct radeon_device *rdev)
 {
struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_VRAM];
 
-   man->func = _bo_manager_func;
man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
man->default_caching = TTM_PL_FLAG_WC;
 
-   return ttm_bo_init_mm(>mman.bdev, TTM_PL_VRAM,
- rdev->mc.real_vram_size >> PAGE_SHIFT);
+   return ttm_bo_man_init(>mman.bdev, man,
+  rdev->mc.real_vram_size >> PAGE_SHIFT);
 }
 
 static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 {
struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_TT];
 
-   man->func = _bo_manager_func;
man->available_caching = TTM_PL_MASK_CACHING;
man->default_caching = TTM_PL_FLAG_CACHED;
man->use_tt = true;
@@ -98,7 +96,7 @@ static int radeon_ttm_init_gtt(struct radeon_device *rdev)
}
 #endif
 
-   return ttm_bo_init_mm(>mman.bdev, TTM_PL_TT,
+   return ttm_bo_man_init(>mman.bdev, man,
  rdev->mc.gtt_size >> PAGE_SHIFT);
 }
 
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This lets the generic mm manager be initialised by the driver.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 23 ---
 include/drm/ttm/ttm_bo_driver.h  |  3 +++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c 
b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index facd3049c3aa..64234e5caee3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager 
*man,
}
 }
 
-static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
-  unsigned long p_size)
+static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
+   unsigned long p_size)
 {
struct ttm_range_manager *rman;
 
@@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager 
*man,
return 0;
 }
 
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man,
+   unsigned long p_size)
+{
+   int ret;
+
+   man->func = _bo_manager_func;
+
+   ttm_bo_init_mm_base(bdev, man, p_size);
+   ret = ttm_bo_man_init_private(man, p_size);
+   if (ret)
+   return ret;
+   ttm_bo_use_mm(man);
+   return 0;
+}
+EXPORT_SYMBOL(ttm_bo_man_init);
+
 static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
 {
struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
@@ -147,7 +164,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager 
*man,
 }
 
 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-   .init = ttm_bo_man_init,
+   .init = ttm_bo_man_init_private,
.takedown = ttm_bo_man_takedown,
.get_node = ttm_bo_man_get_node,
.put_node = ttm_bo_man_put_node,
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 68e75c3b8c7a..5c4ccefd5393 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -799,6 +799,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
  */
 pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+   struct ttm_mem_type_manager *man,
+   unsigned long p_size);
 extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 #endif
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 01/49] drm/qxl/ttm: call ttm manager debug

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

This code was poking inside a struct and assuming it was a drm_mm
at the start. Call the proper API.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/qxl/qxl_ttm.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 759c9d601072..59478761efe8 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -279,12 +279,10 @@ void qxl_ttm_fini(struct qxl_device *qdev)
 static int qxl_mm_dump_table(struct seq_file *m, void *data)
 {
struct drm_info_node *node = (struct drm_info_node *)m->private;
-   struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
+   struct ttm_mem_type_manager *man = (struct ttm_mem_type_manager 
*)node->info_ent->data;
struct drm_printer p = drm_seq_file_printer(m);
 
-   spin_lock(_bo_glob.lru_lock);
-   drm_mm_print(mm, );
-   spin_unlock(_bo_glob.lru_lock);
+   man->func->debug(man, );
return 0;
 }
 #endif
@@ -305,9 +303,9 @@ void qxl_ttm_debugfs_init(struct qxl_device *qdev)
qxl_mem_types_list[i].show = _mm_dump_table;
qxl_mem_types_list[i].driver_features = 0;
if (i == 0)
-   qxl_mem_types_list[i].data = 
qdev->mman.bdev.man[TTM_PL_VRAM].priv;
+   qxl_mem_types_list[i].data = 
>mman.bdev.man[TTM_PL_VRAM];
else
-   qxl_mem_types_list[i].data = 
qdev->mman.bdev.man[TTM_PL_PRIV].priv;
+   qxl_mem_types_list[i].data = 
>mman.bdev.man[TTM_PL_PRIV];
 
}
qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
-- 
2.26.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 05/49] drm/amdgpu/ttm: init managers from the driver side.

2020-07-30 Thread Dave Airlie
From: Dave Airlie 

Use new init calls to unwrap manager init

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 19 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c  | 37 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h  |  4 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 19 ++
 4 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 77fae40197ab..5f58aa2eac4a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -76,6 +76,7 @@ static DEVICE_ATTR(mem_info_gtt_total, S_IRUGO,
 static DEVICE_ATTR(mem_info_gtt_used, S_IRUGO,
   amdgpu_mem_info_gtt_used_show, NULL);
 
+static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 /**
  * amdgpu_gtt_mgr_init - init GTT manager and DRM MM
  *
@@ -84,14 +85,20 @@ static DEVICE_ATTR(mem_info_gtt_used, S_IRUGO,
  *
  * Allocate and initialize the GTT manager.
  */
-static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
-  unsigned long p_size)
+int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 {
-   struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_TT];
struct amdgpu_gtt_mgr *mgr;
uint64_t start, size;
int ret;
 
+   man->use_tt = true;
+   man->func = _gtt_mgr_func;
+   man->available_caching = TTM_PL_MASK_CACHING;
+   man->default_caching = TTM_PL_FLAG_CACHED;
+
+   ttm_bo_init_mm_base(>mman.bdev, man, gtt_size >> PAGE_SHIFT);
+
mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
if (!mgr)
return -ENOMEM;
@@ -100,7 +107,7 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager 
*man,
size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
drm_mm_init(>mm, start, size);
spin_lock_init(>lock);
-   atomic64_set(>available, p_size);
+   atomic64_set(>available, gtt_size >> PAGE_SHIFT);
man->priv = mgr;
 
ret = device_create_file(adev->dev, _attr_mem_info_gtt_total);
@@ -114,6 +121,7 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager 
*man,
return ret;
}
 
+   ttm_bo_use_mm(man);
return 0;
 }
 
@@ -298,8 +306,7 @@ static void amdgpu_gtt_mgr_debug(struct 
ttm_mem_type_manager *man,
   amdgpu_gtt_mgr_usage(man) >> 20);
 }
 
-const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
-   .init = amdgpu_gtt_mgr_init,
+static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
.takedown = amdgpu_gtt_mgr_fini,
.get_node = amdgpu_gtt_mgr_new,
.put_node = amdgpu_gtt_mgr_del,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d3e3cad4d0cb..f1bf86b8de14 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -63,43 +63,16 @@
 
 #define AMDGPU_TTM_VRAM_MAX_DW_READ(size_t)128
 
-static int amdgpu_ttm_init_vram(struct amdgpu_device *adev)
-{
-
-   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_VRAM];
-
-   man->func = _vram_mgr_func;
-   man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-   man->default_caching = TTM_PL_FLAG_WC;
-
-   return ttm_bo_init_mm(>mman.bdev, TTM_PL_VRAM,
- adev->gmc.real_vram_size >> PAGE_SHIFT);
-}
-
-static int amdgpu_ttm_init_gtt(struct amdgpu_device *adev, uint64_t gtt_size)
-{
-   struct ttm_mem_type_manager *man = >mman.bdev.man[TTM_PL_TT];
-
-   man->use_tt = true;
-   man->func = _gtt_mgr_func;
-   man->available_caching = TTM_PL_MASK_CACHING;
-   man->default_caching = TTM_PL_FLAG_CACHED;
-
-   return ttm_bo_init_mm(>mman.bdev, TTM_PL_TT,
- gtt_size >> PAGE_SHIFT);
-}
-
 static int amdgpu_ttm_init_on_chip(struct amdgpu_device *adev,
-  unsigned int type,
-  uint64_t size)
+   unsigned int type,
+   uint64_t size)
 {
struct ttm_mem_type_manager *man = >mman.bdev.man[type];
 
-   man->func = _bo_manager_func;
man->available_caching = TTM_PL_FLAG_UNCACHED;
man->default_caching = TTM_PL_FLAG_UNCACHED;
 
-   return ttm_bo_init_mm(>mman.bdev, type, size);
+   return ttm_bo_man_init(>mman.bdev, man, size >> PAGE_SHIFT);
 }
 
 /**
@@ -1915,7 +1888,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
adev->mman.bdev.no_retry = true;
 
/* Initialize VRAM pool with all of VRAM divided into pages */
-   r = amdgpu_ttm_init_vram(adev);
+   r = amdgpu_vram_mgr_init(adev);
if (r) {
DRM_ERROR("Failed initializing VRAM heap.\n");
   

[PATCH 00/49] ttm mem manager refactoring.

2020-07-30 Thread Dave Airlie
I started pulling on a thread, and it led me down a hole.

This series refactors the ttm ttm_mem_type_manager object into
a driver owned, allocated, subclassaed object.

It starts with two minor fixes for some bad assumptions in two drivers.

Enables a new init path, ports all the drivers to the new init
path, and cleans up the old init path.
Enables a new takedown path, ports all the drivers to the new takedown
path, and cleans up the old takedown path
Wraps all access to the memory managers in the bo_device in a wrapper
across all drivers.
Make debug callback optional
Enables driver to provide their own mem manager objects
Subclasses the objects in all drivers and makes them into driver owned object
Drops the bo_device arrays of pointers, and some unneeded links and
struct members
Cleans up one api.

I think I'd probably want to merge all this via drm-misc, so if I can collect
acks/r-b from driver maintainers that would be good.

This is also based on Chrisitan's work to remove init_mem_type, so it won't
apply until he's finished getting all of that into drm-misc.

https://cgit.freedesktop.org/~airlied/linux/log/?h=ttm-refactor-mem-manager
is the tree I've built this on top off, so it's probably going to get rebased
but the code should stay mostly the same.

I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
amdgpu soon.

Dave.


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[git pull] drm fixes for 5.8-rc8 (part 2)

2020-07-30 Thread Dave Airlie
Hi Linus,

As mentioned previously this contains the nouveau regression fix,
amdgpu had 3 fixes outstanding as well, one revert, an info leak and
use after free. The use after free is a bit trickier than I'd like,
and I've personally gone over it to confirm I'm happy that it is doing
what it says.

Let me know if any issues with any, happy to respin if necessary.
Dave.

drm-fixes-2020-07-31:
drm fixes for 5.8-rc8 (part 2)

nouveau:
- final modifiers regression fix

amdgpu:
- Revert a fix which caused other regressions
- Fix potential kernel info leak
- Fix a use-after-free bug that was uncovered by another change in 5.7
The following changes since commit a4a2739beb8933a19281bca077fdb852598803ed:

  Merge tag 'drm-misc-fixes-2020-07-28' of
git://anongit.freedesktop.org/drm/drm-misc into drm-fixes (2020-07-29
12:46:58 +1000)

are available in the Git repository at:

  git://anongit.freedesktop.org/drm/drm tags/drm-fixes-2020-07-31

for you to fetch changes up to 887c909dd5d557c203a233ebbe238c18438a680a:

  Merge tag 'amd-drm-fixes-5.8-2020-07-30' of
git://people.freedesktop.org/~agd5f/linux into drm-fixes (2020-07-31
13:04:00 +1000)


drm fixes for 5.8-rc8 (part 2)

nouveau:
- final modifiers regression fix

amdgpu:
- Revert a fix which caused other regressions
- Fix potential kernel info leak
- Fix a use-after-free bug that was uncovered by another change in 5.7


Alex Deucher (1):
  Revert "drm/amdgpu: Fix NULL dereference in dpm sysfs handlers"

Dave Airlie (1):
  Merge tag 'amd-drm-fixes-5.8-2020-07-30' of
git://people.freedesktop.org/~agd5f/linux into drm-fixes

James Jones (1):
  drm/nouveau: Accept 'legacy' format modifiers

Mazin Rezk (1):
  drm/amd/display: Clear dm_state for fast updates

Peilin Ye (1):
  drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()

 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c|  9 --
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 +--
 drivers/gpu/drm/nouveau/nouveau_display.c | 27 +++--
 4 files changed, 60 insertions(+), 15 deletions(-)
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2 1/1] drm: xlnx: zynqmp: Use switch - case for link rate downshift

2020-07-30 Thread Hyun Kwon
Hi Laurent,

Thanks for the comment.

On Thu, Jul 30, 2020 at 04:12:46PM -0700, Laurent Pinchart wrote:
> Hi Hyun,
> 
> Thank you for the patch.
> 
> On Wed, Jul 29, 2020 at 04:30:45PM -0700, Hyun Kwon wrote:
> > Use switch - case to downshift from the current link rate. It's a small
> > loop now, so fine to be replaced with switch - case. With a loop, it is
> > confusing and hard to follow as reported below.
> > 
> > The patch d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP
> > DisplayPort Subsystem" from Jul 7, 2018, leads to the following
> > static checker warning:
> > 
> > drivers/gpu/drm/xlnx/zynqmp_dp.c:594 zynqmp_dp_mode_configure()
> > error: iterator underflow 'bws' (-1)-2
> > 
> > Reported-by: Dan Carpenter 
> > Signed-off-by: Hyun Kwon 
> > ---
> > v2
> > - Convert the for loop into switch - case
> > ---
> > ---
> >  drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 -
> >  1 file changed, 16 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c 
> > b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > index b735072..5d6adeaa 100644
> > --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> > @@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp 
> > *dp, int pclock,
> > u8 current_bw)
> >  {
> > int max_rate = dp->link_config.max_rate;
> > -   u8 bws[3] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
> > +   u8 bw_code;
> > u8 max_lanes = dp->link_config.max_lanes;
> > u8 max_link_rate_code = drm_dp_link_rate_to_bw_code(max_rate);
> > u8 bpp = dp->config.bpp;
> > u8 lane_cnt;
> > -   s8 i;
> >  
> > -   if (current_bw == DP_LINK_BW_1_62) {
> > +   /* Downshift from current one */
> 
> Maybe "Downshift from the current bandwidth" ?
> 
> Reviewed-by: Laurent Pinchart 
> 

I agree. I'll fix and add the tag.

Thanks!

-hyun

> > +   switch (current_bw) {
> > +   case DP_LINK_BW_5_4:
> > +   bw_code = DP_LINK_BW_2_7;
> > +   break;
> > +   case DP_LINK_BW_2_7:
> > +   bw_code = DP_LINK_BW_1_62;
> > +   break;
> > +   case DP_LINK_BW_1_62:
> > dev_err(dp->dev, "can't downshift. already lowest link rate\n");
> > return -EINVAL;
> > -   }
> > -
> > -   for (i = ARRAY_SIZE(bws) - 1; i >= 0; i--) {
> > -   if (current_bw && bws[i] >= current_bw)
> > -   continue;
> > -
> > -   if (bws[i] <= max_link_rate_code)
> > -   break;
> > +   default:
> > +   /* If not given, start with max supported */
> > +   bw_code = max_link_rate_code;
> > +   break;
> > }
> >  
> > for (lane_cnt = 1; lane_cnt <= max_lanes; lane_cnt <<= 1) {
> > int bw;
> > u32 rate;
> >  
> > -   bw = drm_dp_bw_code_to_link_rate(bws[i]);
> > +   bw = drm_dp_bw_code_to_link_rate(bw_code);
> > rate = zynqmp_dp_max_rate(bw, lane_cnt, bpp);
> > if (pclock <= rate) {
> > -   dp->mode.bw_code = bws[i];
> > +   dp->mode.bw_code = bw_code;
> > dp->mode.lane_cnt = lane_cnt;
> > dp->mode.pclock = pclock;
> > return dp->mode.bw_code;
> 
> -- 
> Regards,
> 
> Laurent Pinchart
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v4] drm/nouveau: Accept 'legacy' format modifiers

2020-07-30 Thread James Jones
Accept the DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()
family of modifiers to handle broken userspace
Xorg modesetting and Mesa drivers. Existing Mesa
drivers are still aware of only these older
format modifiers which do not differentiate
between different variations of the block linear
layout. When the format modifier support flag was
flipped in the nouveau kernel driver, the X.org
modesetting driver began attempting to use its
format modifier-enabled framebuffer path. Because
the set of format modifiers advertised by the
kernel prior to this change do not intersect with
the set of format modifiers advertised by Mesa,
allocating GBM buffers using format modifiers
fails and the modesetting driver falls back to
non-modifier allocation. However, it still later
queries the modifier of the GBM buffer when
creating its DRM-KMS framebuffer object, receives
the old-format modifier from Mesa, and attempts
to create a framebuffer with it. Since the kernel
is still not aware of these formats, this fails.

Userspace should not be attempting to query format
modifiers of GBM buffers allocated with a non-
format-modifier-aware allocation path, but to
avoid breaking existing userspace behavior, this
change accepts the old-style format modifiers when
creating framebuffers and applying them to planes
by translating them to the equivalent new-style
modifier. To accomplish this, some layout
parameters must be assumed to match properties of
the device targeted by the relevant ioctls. To
avoid perpetuating misuse of the old-style
modifiers, this change does not advertise support
for them. Doing so would imply compatibility
between devices with incompatible memory layouts.

Tested with Xorg 1.20 modesetting driver,
weston@c46c70dac84a4b3030cd05b380f9f410536690fc,
gnome & KDE wayland desktops from Ubuntu 18.04,
and sway 1.5

Reported-by: Kirill A. Shutemov 
Fixes: fa4f4c213f5f ("drm/nouveau/kms: Support NVIDIA format modifiers")
Link: https://lkml.org/lkml/2020/6/30/1251
Signed-off-by: James Jones 
---
 drivers/gpu/drm/nouveau/nouveau_display.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 496c4621cc78..07373bbc2acf 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -191,6 +191,7 @@ nouveau_decode_mod(struct nouveau_drm *drm,
   uint32_t *tile_mode,
   uint8_t *kind)
 {
+   struct nouveau_display *disp = nouveau_display(drm->dev);
BUG_ON(!tile_mode || !kind);
 
if (modifier == DRM_FORMAT_MOD_LINEAR) {
@@ -202,6 +203,12 @@ nouveau_decode_mod(struct nouveau_drm *drm,
 * Extract the block height and kind from the corresponding
 * modifier fields.  See drm_fourcc.h for details.
 */
+
+   if ((modifier & (0xffull << 12)) == 0ull) {
+   /* Legacy modifier.  Translate to this dev's 'kind.' */
+   modifier |= disp->format_modifiers[0] & (0xffull << 12);
+   }
+
*tile_mode = (uint32_t)(modifier & 0xF);
*kind = (uint8_t)((modifier >> 12) & 0xFF);
 
@@ -227,6 +234,16 @@ nouveau_framebuffer_get_layout(struct drm_framebuffer *fb,
}
 }
 
+static const u64 legacy_modifiers[] = {
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5),
+   DRM_FORMAT_MOD_INVALID
+};
+
 static int
 nouveau_validate_decode_mod(struct nouveau_drm *drm,
uint64_t modifier,
@@ -247,8 +264,14 @@ nouveau_validate_decode_mod(struct nouveau_drm *drm,
 (disp->format_modifiers[mod] != modifier);
 mod++);
 
-   if (disp->format_modifiers[mod] == DRM_FORMAT_MOD_INVALID)
-   return -EINVAL;
+   if (disp->format_modifiers[mod] == DRM_FORMAT_MOD_INVALID) {
+   for (mod = 0;
+(legacy_modifiers[mod] != DRM_FORMAT_MOD_INVALID) &&
+(legacy_modifiers[mod] != modifier);
+mod++);
+   if (legacy_modifiers[mod] == DRM_FORMAT_MOD_INVALID)
+   return -EINVAL;
+   }
 
nouveau_decode_mod(drm, modifier, tile_mode, kind);
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v3] drm/nouveau: Accept 'legacy' format modifiers

2020-07-30 Thread James Jones

On 7/30/20 3:19 PM, Kirill A. Shutemov wrote:

On Thu, Jul 30, 2020 at 10:26:17AM -0700, James Jones wrote:

Accept the DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()
family of modifiers to handle broken userspace
Xorg modesetting and Mesa drivers. Existing Mesa
drivers are still aware of only these older
format modifiers which do not differentiate
between different variations of the block linear
layout. When the format modifier support flag was
flipped in the nouveau kernel driver, the X.org
modesetting driver began attempting to use its
format modifier-enabled framebuffer path. Because
the set of format modifiers advertised by the
kernel prior to this change do not intersect with
the set of format modifiers advertised by Mesa,
allocating GBM buffers using format modifiers
fails and the modesetting driver falls back to
non-modifier allocation. However, it still later
queries the modifier of the GBM buffer when
creating its DRM-KMS framebuffer object, receives
the old-format modifier from Mesa, and attempts
to create a framebuffer with it. Since the kernel
is still not aware of these formats, this fails.

Userspace should not be attempting to query format
modifiers of GBM buffers allocated with a non-
format-modifier-aware allocation path, but to
avoid breaking existing userspace behavior, this
change accepts the old-style format modifiers when
creating framebuffers and applying them to planes
by translating them to the equivalent new-style
modifier. To accomplish this, some layout
parameters must be assumed to match properties of
the device targeted by the relevant ioctls. To
avoid perpetuating misuse of the old-style
modifiers, this change does not advertise support
for them. Doing so would imply compatibility
between devices with incompatible memory layouts.

Tested with Xorg 1.20 modesetting driver,
weston@c46c70dac84a4b3030cd05b380f9f410536690fc,
gnome & KDE wayland desktops from Ubuntu 18.04,
kmscube hacked to use linear mod, and sway 1.5

Reported-by: Kirill A. Shutemov 
Fixes: fa4f4c213f5f ("drm/nouveau/kms: Support NVIDIA format modifiers")
Link: https://lkml.org/lkml/2020/6/30/1251
Signed-off-by: James Jones 
---
  drivers/gpu/drm/nouveau/nouveau_display.c | 26 +--
  1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 496c4621cc78..31543086254b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -191,8 +191,14 @@ nouveau_decode_mod(struct nouveau_drm *drm,
   uint32_t *tile_mode,
   uint8_t *kind)
  {
+   struct nouveau_display *disp = nouveau_display(drm->dev);
BUG_ON(!tile_mode || !kind);
  
+	if ((modifier & (0xffull << 12)) == 0ull) {

+   /* Legacy modifier.  Translate to this device's 'kind.' */
+   modifier |= disp->format_modifiers[0] & (0xffull << 12);
+   }
+
if (modifier == DRM_FORMAT_MOD_LINEAR) {
/* tile_mode will not be used in this case */
*tile_mode = 0;


Em. I thought Ben's suggestion was to move it under != MOD_LINEAR. I don't
see it here.


Yes, it looks like I forgot to commit before generating the patch.  v4 sent.

Thanks,
-James

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2 1/1] drm: xlnx: zynqmp: Use switch - case for link rate downshift

2020-07-30 Thread Laurent Pinchart
Hi Hyun,

Thank you for the patch.

On Wed, Jul 29, 2020 at 04:30:45PM -0700, Hyun Kwon wrote:
> Use switch - case to downshift from the current link rate. It's a small
> loop now, so fine to be replaced with switch - case. With a loop, it is
> confusing and hard to follow as reported below.
> 
> The patch d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP
> DisplayPort Subsystem" from Jul 7, 2018, leads to the following
> static checker warning:
> 
>   drivers/gpu/drm/xlnx/zynqmp_dp.c:594 zynqmp_dp_mode_configure()
>   error: iterator underflow 'bws' (-1)-2
> 
> Reported-by: Dan Carpenter 
> Signed-off-by: Hyun Kwon 
> ---
> v2
> - Convert the for loop into switch - case
> ---
> ---
>  drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 -
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c 
> b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> index b735072..5d6adeaa 100644
> --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
> +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> @@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp 
> *dp, int pclock,
>   u8 current_bw)
>  {
>   int max_rate = dp->link_config.max_rate;
> - u8 bws[3] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
> + u8 bw_code;
>   u8 max_lanes = dp->link_config.max_lanes;
>   u8 max_link_rate_code = drm_dp_link_rate_to_bw_code(max_rate);
>   u8 bpp = dp->config.bpp;
>   u8 lane_cnt;
> - s8 i;
>  
> - if (current_bw == DP_LINK_BW_1_62) {
> + /* Downshift from current one */

Maybe "Downshift from the current bandwidth" ?

Reviewed-by: Laurent Pinchart 

> + switch (current_bw) {
> + case DP_LINK_BW_5_4:
> + bw_code = DP_LINK_BW_2_7;
> + break;
> + case DP_LINK_BW_2_7:
> + bw_code = DP_LINK_BW_1_62;
> + break;
> + case DP_LINK_BW_1_62:
>   dev_err(dp->dev, "can't downshift. already lowest link rate\n");
>   return -EINVAL;
> - }
> -
> - for (i = ARRAY_SIZE(bws) - 1; i >= 0; i--) {
> - if (current_bw && bws[i] >= current_bw)
> - continue;
> -
> - if (bws[i] <= max_link_rate_code)
> - break;
> + default:
> + /* If not given, start with max supported */
> + bw_code = max_link_rate_code;
> + break;
>   }
>  
>   for (lane_cnt = 1; lane_cnt <= max_lanes; lane_cnt <<= 1) {
>   int bw;
>   u32 rate;
>  
> - bw = drm_dp_bw_code_to_link_rate(bws[i]);
> + bw = drm_dp_bw_code_to_link_rate(bw_code);
>   rate = zynqmp_dp_max_rate(bw, lane_cnt, bpp);
>   if (pclock <= rate) {
> - dp->mode.bw_code = bws[i];
> + dp->mode.bw_code = bw_code;
>   dp->mode.lane_cnt = lane_cnt;
>   dp->mode.pclock = pclock;
>   return dp->mode.bw_code;

-- 
Regards,

Laurent Pinchart
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v3] drm/nouveau: Accept 'legacy' format modifiers

2020-07-30 Thread Kirill A. Shutemov
On Thu, Jul 30, 2020 at 10:26:17AM -0700, James Jones wrote:
> Accept the DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()
> family of modifiers to handle broken userspace
> Xorg modesetting and Mesa drivers. Existing Mesa
> drivers are still aware of only these older
> format modifiers which do not differentiate
> between different variations of the block linear
> layout. When the format modifier support flag was
> flipped in the nouveau kernel driver, the X.org
> modesetting driver began attempting to use its
> format modifier-enabled framebuffer path. Because
> the set of format modifiers advertised by the
> kernel prior to this change do not intersect with
> the set of format modifiers advertised by Mesa,
> allocating GBM buffers using format modifiers
> fails and the modesetting driver falls back to
> non-modifier allocation. However, it still later
> queries the modifier of the GBM buffer when
> creating its DRM-KMS framebuffer object, receives
> the old-format modifier from Mesa, and attempts
> to create a framebuffer with it. Since the kernel
> is still not aware of these formats, this fails.
> 
> Userspace should not be attempting to query format
> modifiers of GBM buffers allocated with a non-
> format-modifier-aware allocation path, but to
> avoid breaking existing userspace behavior, this
> change accepts the old-style format modifiers when
> creating framebuffers and applying them to planes
> by translating them to the equivalent new-style
> modifier. To accomplish this, some layout
> parameters must be assumed to match properties of
> the device targeted by the relevant ioctls. To
> avoid perpetuating misuse of the old-style
> modifiers, this change does not advertise support
> for them. Doing so would imply compatibility
> between devices with incompatible memory layouts.
> 
> Tested with Xorg 1.20 modesetting driver,
> weston@c46c70dac84a4b3030cd05b380f9f410536690fc,
> gnome & KDE wayland desktops from Ubuntu 18.04,
> kmscube hacked to use linear mod, and sway 1.5
> 
> Reported-by: Kirill A. Shutemov 
> Fixes: fa4f4c213f5f ("drm/nouveau/kms: Support NVIDIA format modifiers")
> Link: https://lkml.org/lkml/2020/6/30/1251
> Signed-off-by: James Jones 
> ---
>  drivers/gpu/drm/nouveau/nouveau_display.c | 26 +--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
> b/drivers/gpu/drm/nouveau/nouveau_display.c
> index 496c4621cc78..31543086254b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_display.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_display.c
> @@ -191,8 +191,14 @@ nouveau_decode_mod(struct nouveau_drm *drm,
>  uint32_t *tile_mode,
>  uint8_t *kind)
>  {
> + struct nouveau_display *disp = nouveau_display(drm->dev);
>   BUG_ON(!tile_mode || !kind);
>  
> + if ((modifier & (0xffull << 12)) == 0ull) {
> + /* Legacy modifier.  Translate to this device's 'kind.' */
> + modifier |= disp->format_modifiers[0] & (0xffull << 12);
> + }
> +
>   if (modifier == DRM_FORMAT_MOD_LINEAR) {
>   /* tile_mode will not be used in this case */
>   *tile_mode = 0;

Em. I thought Ben's suggestion was to move it under != MOD_LINEAR. I don't
see it here.


-- 
 Kirill A. Shutemov
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v5 0/6] Add support for GPU DDR BW scaling

2020-07-30 Thread Rob Clark
On Thu, Jul 30, 2020 at 8:37 AM Viresh Kumar  wrote:
>
> On 30-07-20, 08:27, Rob Clark wrote:
> > Hmm, I've already sent my pull request to Dave, dropping the patch
> > would require force-push and sending a new PR.  Which I can do if Dave
> > prefers.  OTOH I guess it isn't the end of the world if the patch is
> > merged via two different trees.
>
> I don't think a patch can go via two trees, as that would have two sha
> keys for the same code.
>
> Though it is fine for a patch to go via two different trees if we make
> sure the same sha key is used for both.
>
> Will it be possible for you to provide a branch/tag of your branch
> that I can base stuff of ?
>

Ok, I sent a v2 pull req that dropped the OPP patch.  Both are tagged
so Dave can use either version, so I guess you two can coordinate this

BR,
-R
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[pull v2] drm/msm: msm-next for 5.9

2020-07-30 Thread Rob Clark
Hi Dave,

Take 2 of msm-next pull, this version drops the OPP patch due to [1],
so I'll send the gpu opp/bw scaling patch after the OPP patch lands.
Since I had to force-push I took the opportunity to rebase on
drm-next, and since you already merged in 5.8-rc6 a few fixes from the
last cycle dropped out.

This time around:

* A bunch more a650/a640 (sm8150/sm8250) display and GPU enablement
  and fixes
* Enable dpu dither block for 6bpc panels
* dpu suspend fixes
* dpu fix for cursor on 2nd display
* dsi/mdp5 enablement for sdm630/sdm636/sdm660

I also regenerated the register headers, which accounts for a good
bit of the size this time, because we hadn't re-synced the register
headers since the early days of a6xx bringup.

[1] https://lkml.org/lkml/2020/7/30/23

The following changes since commit 5de5b6ecf97a021f29403aa272cb4e03318ef586:

  drm/ttm/nouveau: don't call tt destroy callback on alloc failure.
(2020-07-29 10:06:38 +1000)

are available in the Git repository at:

  https://gitlab.freedesktop.org/drm/msm.git drm-msm-next-2020-07-30

for you to fetch changes up to aa6800856f3aba864f8174dd1ac2c325e37be428:

  drm/msm: use kthread_create_worker instead of kthread_run
(2020-07-30 13:46:11 -0700)


Akhil P Oommen (2):
  drm/msm: Fix a null pointer access in msm_gem_shrinker_count()
  drm: msm: a6xx: fix gpu failure after system resume

Bernard (1):
  drm/msm: use kthread_create_worker instead of kthread_run

Eric Anholt (2):
  drm/msm: Garbage collect unused resource _len fields.
  drm/msm: Quiet error during failure in optional resource mappings.

Jonathan Marek (16):
  drm/msm: fix unbalanced pm_runtime_enable in adreno_gpu_{init, cleanup}
  drm/msm: reset devfreq freq_table/max_state before devfreq_add_device
  drm/msm: handle for EPROBE_DEFER for of_icc_get
  drm/msm/a6xx: fix crashstate capture for A650
  drm/msm/a6xx: add build_bw_table for A640/A650
  drm/msm/a6xx: set ubwc config for A640 and A650
  drm/msm/dpu: use right setup_blend_config for sm8150 and sm8250
  drm/msm/dpu: update UBWC config for sm8150 and sm8250
  drm/msm/dpu: move some sspp caps to dpu_caps
  drm/msm/dpu: don't use INTF_INPUT_CTRL feature on sdm845
  drm/msm/dpu: set missing flush bits for INTF_2 and INTF_3
  drm/msm/dpu: intf timing path for displayport
  drm/msm/dpu: add SM8150 to hw catalog
  drm/msm/dpu: add SM8250 to hw catalog
  drm/msm/a6xx: hwcg tables in gpulist
  drm/msm/a6xx: add A640/A650 hwcg

Kalyan Thota (3):
  drm/msm/dpu: ensure device suspend happens during PM sleep
  drm/msm/dpu: enumerate second cursor pipe for external interface
  drm/msm/dpu: add support for dither block in display

Konrad Dybcio (4):
  drm/msm/dsi: Add phy configuration for SDM630/636/660
  drm/msm/mdp5: Add MDP5 configuration for SDM630
  drm/msm/dsi: Add DSI configuration for SDM660
  drm/msm/mdp5: Add MDP5 configuration for SDM636/660

Rajendra Nayak (2):
  drm/msm/dpu: Use OPP API to set clk/perf state
  drm/msm: dsi: Use OPP API to set clk/perf state

Rob Clark (5):
  drm/msm/adreno: fix gpu probe if no interconnect-names
  drm/msm: ratelimit crtc event overflow error
  drm/msm/dpu: fix/enable 6bpc dither with split-lm
  drm/msm: sync generated headers
  drm/msm/adreno: un-open-code some packets

Sharat Masetty (2):
  dt-bindings: drm/msm/gpu: Document gpu opp table
  drm: msm: a6xx: send opp instead of a frequency

 .../devicetree/bindings/display/msm/dsi.txt|1 +
 .../devicetree/bindings/display/msm/gpu.txt|   28 +
 drivers/gpu/drm/msm/adreno/a2xx.xml.h  | 1102 +-
 drivers/gpu/drm/msm/adreno/a3xx.xml.h  |  102 +-
 drivers/gpu/drm/msm/adreno/a4xx.xml.h  |  125 +-
 drivers/gpu/drm/msm/adreno/a5xx.xml.h  |  403 ++-
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c  |5 +-
 drivers/gpu/drm/msm/adreno/a6xx.xml.h  | 3624 
 drivers/gpu/drm/msm/adreno/a6xx_gmu.c  |  107 +-
 drivers/gpu/drm/msm/adreno/a6xx_gmu.h  |5 +
 drivers/gpu/drm/msm/adreno/a6xx_gmu.xml.h  |  147 +-
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c  |  191 +-
 drivers/gpu/drm/msm/adreno/a6xx_gpu.h  |2 +-
 drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c|   25 +-
 drivers/gpu/drm/msm/adreno/a6xx_gpu_state.h|   12 +-
 drivers/gpu/drm/msm/adreno/a6xx_hfi.c  |   74 +
 drivers/gpu/drm/msm/adreno/adreno_common.xml.h |  230 +-
 drivers/gpu/drm/msm/adreno/adreno_device.c |3 +
 drivers/gpu/drm/msm/adreno/adreno_gpu.c|   70 +-
 drivers/gpu/drm/msm/adreno/adreno_gpu.h|8 +
 drivers/gpu/drm/msm/adreno/adreno_pm4.xml.h|  933 -
 drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c  |3 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c

Re: [Linux-kernel-mentees] [PATCH] drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()

2020-07-30 Thread Luben Tuikov
On 2020-07-29 9:49 a.m., Alex Deucher wrote:
> On Wed, Jul 29, 2020 at 4:11 AM Christian König
>  wrote:
>>
>> Am 28.07.20 um 21:29 schrieb Peilin Ye:
>>> Compiler leaves a 4-byte hole near the end of `dev_info`, causing
>>> amdgpu_info_ioctl() to copy uninitialized kernel stack memory to userspace
>>> when `size` is greater than 356.
>>>
>>> In 2015 we tried to fix this issue by doing `= {};` on `dev_info`, which
>>> unfortunately does not initialize that 4-byte hole. Fix it by using
>>> memset() instead.
>>>
>>> Cc: sta...@vger.kernel.org
>>> Fixes: c193fa91b918 ("drm/amdgpu: information leak in amdgpu_info_ioctl()")
>>> Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
>>> Suggested-by: Dan Carpenter 
>>> Signed-off-by: Peilin Ye 
>>
>> Reviewed-by: Christian König 
>>
>> I can't count how many of those we have fixed over the years.
>>
>> At some point we should probably document that using "= {}" or "= { 0 }"
>> in the kernel is a really bad idea and should be avoided.
> 
> Moreover, it seems like different compilers seem to behave relatively
> differently with these and we often get reports of warnings with these
> on clang.  When in doubt, memset.

There are quite a few of those under drivers/gpu/drm, for "amd/", "scheduler/"
drm*.c files,

$find . \( -regex "./drm.*\.c" -or -regex "./amd/.*\.c" -or -regex 
"./scheduler/.*\.c" \) -exec egrep -n -- " *= *{ *(|NULL|0) *}" \{\} \+ | wc -l
374
$_

Out of which only 16 are of the non-ISO C variety, "= {}",

$find . \( -regex "./drm.*\.c" -or -regex "./amd/.*\.c" -or -regex 
"./scheduler/.*\.c" \) -exec egrep -n -- " *= *{ *}" \{\} \+ | wc -l
16
$_

Perhaps the latter are the more pressing ones, since it is a C++ initializer 
and not a ISO C one.

Regards,
Luben



> 
> Alex
> 
>>
>> Thanks,
>> Christian.
>>
>>> ---
>>> $ pahole -C "drm_amdgpu_info_device" drivers/gpu/drm/amd/amdgpu/amdgpu_kms.o
>>> struct drm_amdgpu_info_device {
>>>   __u32  device_id;/* 0 4 */
>>>   __u32  chip_rev; /* 4 4 */
>>>   __u32  external_rev; /* 8 4 */
>>>   __u32  pci_rev;  /*12 4 */
>>>   __u32  family;   /*16 4 */
>>>   __u32  num_shader_engines;   /*20 4 */
>>>   __u32  num_shader_arrays_per_engine; /*24 
>>> 4 */
>>>   __u32  gpu_counter_freq; /*28 4 */
>>>   __u64  max_engine_clock; /*32 8 */
>>>   __u64  max_memory_clock; /*40 8 */
>>>   __u32  cu_active_number; /*48 4 */
>>>   __u32  cu_ao_mask;   /*52 4 */
>>>   __u32  cu_bitmap[4][4];  /*5664 */
>>>   /* --- cacheline 1 boundary (64 bytes) was 56 bytes ago --- */
>>>   __u32  enabled_rb_pipes_mask; /*   120 4 */
>>>   __u32  num_rb_pipes; /*   124 4 */
>>>   /* --- cacheline 2 boundary (128 bytes) --- */
>>>   __u32  num_hw_gfx_contexts;  /*   128 4 */
>>>   __u32  _pad; /*   132 4 */
>>>   __u64  ids_flags;/*   136 8 */
>>>   __u64  virtual_address_offset; /*   144 8 */
>>>   __u64  virtual_address_max;  /*   152 8 */
>>>   __u32  virtual_address_alignment; /*   160 4 
>>> */
>>>   __u32  pte_fragment_size;/*   164 4 */
>>>   __u32  gart_page_size;   /*   168 4 */
>>>   __u32  ce_ram_size;  /*   172 4 */
>>>   __u32  vram_type;/*   176 4 */
>>>   __u32  vram_bit_width;   /*   180 4 */
>>>   __u32  vce_harvest_config;   /*   184 4 */
>>>   __u32  gc_double_offchip_lds_buf; /*   188 4 
>>> */
>>>   /* --- cacheline 3 boundary (192 bytes) --- */
>>>   __u64  prim_buf_gpu_addr;/*   192 8 */
>>>   __u64  pos_buf_gpu_addr; /*   200 8 */
>>>   __u64  cntl_sb_buf_gpu_addr; /*   208 8 */
>>>   __u64  param_buf_gpu_addr;   /*   216 8 */
>>>   __u32  prim_buf_size;/*   224 4 */
>>>   __u32  pos_buf_size; /*   228 4 */
>>>   __u32  cntl_sb_buf_size; /*   232 4 */
>>>   __u32  param_buf_size;   /*   236 4 */
>>>   __u32  wave_front_size;  /*   240 4 */
>>>   

Re: [Nouveau] [PATCH v2] drm/nouveau: Accept 'legacy' format modifiers

2020-07-30 Thread James Jones

On 7/29/20 7:47 AM, Kirill A. Shutemov wrote:

On Wed, Jul 29, 2020 at 01:40:13PM +1000, Ben Skeggs wrote:

On Wed, 29 Jul 2020 at 12:48, Dave Airlie  wrote:


On Tue, 28 Jul 2020 at 04:51, James Jones  wrote:


On 7/23/20 9:06 PM, Ben Skeggs wrote:

On Sat, 18 Jul 2020 at 13:34, James Jones  wrote:


Accept the DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()
family of modifiers to handle broken userspace
Xorg modesetting and Mesa drivers. Existing Mesa
drivers are still aware of only these older
format modifiers which do not differentiate
between different variations of the block linear
layout. When the format modifier support flag was
flipped in the nouveau kernel driver, the X.org
modesetting driver began attempting to use its
format modifier-enabled framebuffer path. Because
the set of format modifiers advertised by the
kernel prior to this change do not intersect with
the set of format modifiers advertised by Mesa,
allocating GBM buffers using format modifiers
fails and the modesetting driver falls back to
non-modifier allocation. However, it still later
queries the modifier of the GBM buffer when
creating its DRM-KMS framebuffer object, receives
the old-format modifier from Mesa, and attempts
to create a framebuffer with it. Since the kernel
is still not aware of these formats, this fails.

Userspace should not be attempting to query format
modifiers of GBM buffers allocated with a non-
format-modifier-aware allocation path, but to
avoid breaking existing userspace behavior, this
change accepts the old-style format modifiers when
creating framebuffers and applying them to planes
by translating them to the equivalent new-style
modifier. To accomplish this, some layout
parameters must be assumed to match properties of
the device targeted by the relevant ioctls. To
avoid perpetuating misuse of the old-style
modifiers, this change does not advertise support
for them. Doing so would imply compatibility
between devices with incompatible memory layouts.

Tested with Xorg 1.20 modesetting driver,
weston@c46c70dac84a4b3030cd05b380f9f410536690fc,
gnome & KDE wayland desktops from Ubuntu 18.04,
and sway 1.5

Reported-by: Kirill A. Shutemov 
Fixes: fa4f4c213f5f ("drm/nouveau/kms: Support NVIDIA format modifiers")
Link: https://lkml.org/lkml/2020/6/30/1251
Signed-off-by: James Jones 
---
   drivers/gpu/drm/nouveau/nouveau_display.c | 26 +--
   1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 496c4621cc78..31543086254b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -191,8 +191,14 @@ nouveau_decode_mod(struct nouveau_drm *drm,
 uint32_t *tile_mode,
 uint8_t *kind)
   {
+   struct nouveau_display *disp = nouveau_display(drm->dev);
  BUG_ON(!tile_mode || !kind);

+   if ((modifier & (0xffull << 12)) == 0ull) {
+   /* Legacy modifier.  Translate to this device's 'kind.' */
+   modifier |= disp->format_modifiers[0] & (0xffull << 12);
+   }

I believe this should be moved into the != MOD_LINEAR case.


Yes, of course, thanks.  I need to re-evaluate my testing yet again to
make sure I hit that case too.  Preparing a v3...


Going to need something here in the next day, two max.

Linus may wait for another week, but it's not guaranteed.

I tested a whole bunch of GPUs before sending nouveau's -next tree,
and with the change I suggested to this patch + the other stuff I sent
through -fixes already, things seemed to be in OK shape.


JFYI, the adjusted (moved into != MOD_LINEAR case) patch works fine for me
on top of drm-fixes-2020-07-29.


Sorry again for the delays (life is terrible lately), but the signed-off 
version with Ben's suggestion went out this morning, and I specifically 
tested linear modifiers in addition to retesting all the other test 
cases mentioned in the patch.


Thanks,
-James
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


RE: [PATCH 5/7] drm/amd/display: Reset plane for anything that's not a FAST update

2020-07-30 Thread Wu, Hersen
[AMD Official Use Only - Internal Distribution Only]

Reviewed-by: Hersen Wu 

-Original Message-
From: Nicholas Kazlauskas  
Sent: Thursday, July 30, 2020 4:37 PM
To: amd-...@lists.freedesktop.org; dri-devel@lists.freedesktop.org
Cc: Kazlauskas, Nicholas ; Lakha, Bhawanpreet 
; Wu, Hersen 
Subject: [PATCH 5/7] drm/amd/display: Reset plane for anything that's not a 
FAST update

[Why]
MEDIUM or FULL updates can require global validation or affect bandwidth. By 
treating these all simply as surface updates we aren't actually passing this 
through DC global validation.

[How]
There's currently no way to pass surface updates through DC global validation, 
nor do I think it's a good idea to change the interface to accept these.

DC global validation itself is currently stateless, and we can move our update 
type checking to be stateless as well by duplicating DC surface checks in DM 
based on DRM properties.

We wanted to rely on DC automatically determining this since DC knows best, but 
DM is ultimately what fills in everything into DC plane state so it does need 
to know as well.

There are basically only three paths that we exercise in DM today:

1) Cursor (async update)
2) Pageflip (fast update)
3) Full pipe programming (medium/full updates)

Which means that anything that's more than a pageflip really needs to go down 
path #3.

So this change duplicates all the surface update checks based on DRM state 
instead inside of should_reset_plane().

Next step is dropping dm_determine_update_type_for_commit and we no longer 
require the old DC state at all for global validation.

Optimization can come later so we don't reset DC planes at all for MEDIUM 
udpates and avoid validation, but we might require some extra checks in DM to 
achieve this.

Cc: Bhawanpreet Lakha 
Cc: Hersen Wu 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 25 +++
 1 file changed, 25 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 0d5f45742bb5..2cbb29199e61 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8336,6 +8336,31 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
if (old_other_state->crtc != new_other_state->crtc)
return true;
 
+   /* Src/dst size and scaling updates. */
+   if (old_other_state->src_w != new_other_state->src_w ||
+   old_other_state->src_h != new_other_state->src_h ||
+   old_other_state->crtc_w != new_other_state->crtc_w ||
+   old_other_state->crtc_h != new_other_state->crtc_h)
+   return true;
+
+   /* Rotation / mirroring updates. */
+   if (old_other_state->rotation != new_other_state->rotation)
+   return true;
+
+   /* Blending updates. */
+   if (old_other_state->pixel_blend_mode !=
+   new_other_state->pixel_blend_mode)
+   return true;
+
+   /* Alpha updates. */
+   if (old_other_state->alpha != new_other_state->alpha)
+   return true;
+
+   /* Colorspace changes. */
+   if (old_other_state->color_range != 
new_other_state->color_range ||
+   old_other_state->color_encoding != 
new_other_state->color_encoding)
+   return true;
+
/* Framebuffer checks fall at the end. */
if (!old_other_state->fb || !new_other_state->fb)
continue;
--
2.25.1
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


RE: [PATCH 2/7] drm/amd/display: Reset plane when tiling flags change

2020-07-30 Thread Wu, Hersen
[AMD Official Use Only - Internal Distribution Only]

Reviewed-by: Hersen Wu 

-Original Message-
From: Nicholas Kazlauskas  
Sent: Thursday, July 30, 2020 4:37 PM
To: amd-...@lists.freedesktop.org; dri-devel@lists.freedesktop.org
Cc: Kazlauskas, Nicholas ; Lakha, Bhawanpreet 
; Siqueira, Rodrigo ; Wu, 
Hersen 
Subject: [PATCH 2/7] drm/amd/display: Reset plane when tiling flags change

[Why]
Enabling or disable DCC or switching between tiled and linear formats can 
require bandwidth updates.

They're currently skipping all DC validation by being treated as purely surface 
updates.

[How]
Treat tiling_flag changes (which encode DCC state) as a condition for resetting 
the plane.

Cc: Bhawanpreet Lakha 
Cc: Rodrigo Siqueira 
Cc: Hersen Wu 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 7cc5ab90ce13..bf1881bd492c 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8332,6 +8332,8 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
 * TODO: Come up with a more elegant solution for this.
 */
for_each_oldnew_plane_in_state(state, other, old_other_state, 
new_other_state, i) {
+   struct dm_plane_state *old_dm_plane_state, *new_dm_plane_state;
+
if (other->type == DRM_PLANE_TYPE_CURSOR)
continue;
 
@@ -8342,9 +8344,20 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
if (old_other_state->crtc != new_other_state->crtc)
return true;
 
-   /* TODO: Remove this once we can handle fast format changes. */
-   if (old_other_state->fb && new_other_state->fb &&
-   old_other_state->fb->format != new_other_state->fb->format)
+   /* Framebuffer checks fall at the end. */
+   if (!old_other_state->fb || !new_other_state->fb)
+   continue;
+
+   /* Pixel format changes can require bandwidth updates. */
+   if (old_other_state->fb->format != new_other_state->fb->format)
+   return true;
+
+   old_dm_plane_state = to_dm_plane_state(old_other_state);
+   new_dm_plane_state = to_dm_plane_state(new_other_state);
+
+   /* Tiling and DCC changes also require bandwidth updates. */
+   if (old_dm_plane_state->tiling_flags !=
+   new_dm_plane_state->tiling_flags)
return true;
}
 
--
2.25.1
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v4] Add support for KeemBay DRM driver

2020-07-30 Thread Anitha Chrisanthus
This is a new DRM driver for Intel's KeemBay SOC.
The SoC couples an ARM Cortex A53 CPU with an Intel
Movidius VPU.

This driver is tested with the KMB EVM board which is the refernce baord
for Keem Bay SOC. The SOC's display pipeline is as follows

+--++-++---+
|LCD controller| -> |Mipi DSI | -> |Mipi to HDMI Converter |
+--++-++---+

LCD controller and Mipi DSI transmitter are part of the SOC and
mipi to HDMI converter is ADV7535 for KMB EVM board.

The DRM driver is a basic KMS atomic modesetting display driver and
has no 2D or 3D graphics.It calls into the ADV bridge driver at
the connector level.

Only 1080p resolution and single plane is supported at this time.
The usecase is for debugging video and camera outputs.

Device tree patches are under review here
https://lore.kernel.org/linux-arm-kernel/20200708175020.194436-1-daniele.alessandre...@linux.intel.com/T/

Changes since v1:
- Removed redundant license text, updated license
- Rearranged include blocks
- renamed global vars and removed extern in c
- Used upclassing for dev_private
- Used drm_dev_init in drm device create
- minor cleanups

Changes since v2:
- squashed all commits to a single commit
- logging changed to drm_info, drm_dbg etc.
- used devm_drm_dev_alloc()
- removed commented out sections and general cleanup

Changes since v3:
- renamed dev_p to kmb
- moved clocks under kmb_clock, consolidated clk initializations
- use drmm functions
- use DRM_GEM_CMA_DRIVER_OPS_VMAP
- more cleanups

Anitha Chrisanthus (1):
  drm/kmb: Add support for KeemBay Display

 drivers/gpu/drm/Kconfig |2 +
 drivers/gpu/drm/Makefile|1 +
 drivers/gpu/drm/kmb/Kconfig |   13 +
 drivers/gpu/drm/kmb/Makefile|2 +
 drivers/gpu/drm/kmb/kmb_crtc.c  |  217 +
 drivers/gpu/drm/kmb/kmb_crtc.h  |   36 +
 drivers/gpu/drm/kmb/kmb_drv.c   |  733 
 drivers/gpu/drm/kmb/kmb_drv.h   |  172 
 drivers/gpu/drm/kmb/kmb_dsi.c   | 1834 +++
 drivers/gpu/drm/kmb/kmb_dsi.h   |  370 
 drivers/gpu/drm/kmb/kmb_plane.c |  518 +++
 drivers/gpu/drm/kmb/kmb_plane.h |  124 +++
 drivers/gpu/drm/kmb/kmb_regs.h  |  738 
 13 files changed, 4760 insertions(+)
 create mode 100644 drivers/gpu/drm/kmb/Kconfig
 create mode 100644 drivers/gpu/drm/kmb/Makefile
 create mode 100644 drivers/gpu/drm/kmb/kmb_crtc.c
 create mode 100644 drivers/gpu/drm/kmb/kmb_crtc.h
 create mode 100644 drivers/gpu/drm/kmb/kmb_drv.c
 create mode 100644 drivers/gpu/drm/kmb/kmb_drv.h
 create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.c
 create mode 100644 drivers/gpu/drm/kmb/kmb_dsi.h
 create mode 100644 drivers/gpu/drm/kmb/kmb_plane.c
 create mode 100644 drivers/gpu/drm/kmb/kmb_plane.h
 create mode 100644 drivers/gpu/drm/kmb/kmb_regs.h

-- 
2.7.4

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 0/7] drm/amd/display: Drop DRM private objects from amdgpu_dm

2020-07-30 Thread Nicholas Kazlauskas
Based on the analysis of the bug from [1] the best course of action seems
to be swapping off of DRM private objects back to subclassing DRM atomic
state instead.

This patch series implements this change, but not yet the other changes
suggested in the threads from that bug - these will come later.

CCing dri-devel per Daniel's suggestion since this issue brought
some interesting misuse of private objects.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=207383

Nicholas Kazlauskas (7):
  drm/amd/display: Store tiling_flags and tmz_surface on dm_plane_state
  drm/amd/display: Reset plane when tiling flags change
  drm/amd/display: Avoid using unvalidated tiling_flags and tmz_surface
in prepare_planes
  drm/amd/display: Use validated tiling_flags and tmz_surface in
commit_tail
  drm/amd/display: Reset plane for anything that's not a FAST update
  drm/amd/display: Drop dm_determine_update_type_for_commit
  drm/amd/display: Replace DRM private objects with subclassed DRM
atomic state

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 967 ++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  13 +-
 2 files changed, 343 insertions(+), 637 deletions(-)

-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 6/7] drm/amd/display: Drop dm_determine_update_type_for_commit

2020-07-30 Thread Nicholas Kazlauskas
[Why]
This was added in the past to solve the issue of not knowing when
to stall for medium and full updates in DM.

Since DC is ultimately decides what requires bandwidth changes we
wanted to make use of it directly to determine this.

The problem is that we can't actually pass any of the stream or surface
updates into DC global validation, so we don't actually check if the new
configuration is valid - we just validate the old existing config
instead and stall for outstanding commits to finish.

There's also the problem of grabbing the DRM private object for
pageflips which can lead to page faults in the case where commits
execute out of order and free a DRM private object state that was
still required for commit tail.

[How]
Now that we reset the plane in DM with the same conditions DC checks
we can have planes go through DC validation and we know when we need
to check and stall based on whether the stream or planes changed.

We mark lock_and_validation_needed whenever we've done this, so just
go back to using that instead of dm_determine_update_type_for_commit.

Since we'll skip resetting the plane for a pageflip we will no longer
grab the DRM private object for pageflips as well, avoiding the
page fault issued caused by pageflipping under load with commits
executing out of order.

Cc: Harry Wentland 
Cc: Bhawanpreet Lakha 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 199 ++
 1 file changed, 17 insertions(+), 182 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 2cbb29199e61..59829ec81694 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8542,161 +8542,6 @@ static int dm_update_plane_state(struct dc *dc,
return ret;
 }
 
-static int
-dm_determine_update_type_for_commit(struct amdgpu_display_manager *dm,
-   struct drm_atomic_state *state,
-   enum surface_update_type *out_type)
-{
-   struct dc *dc = dm->dc;
-   struct dm_atomic_state *dm_state = NULL, *old_dm_state = NULL;
-   int i, j, num_plane, ret = 0;
-   struct drm_plane_state *old_plane_state, *new_plane_state;
-   struct dm_plane_state *new_dm_plane_state, *old_dm_plane_state;
-   struct drm_crtc *new_plane_crtc;
-   struct drm_plane *plane;
-
-   struct drm_crtc *crtc;
-   struct drm_crtc_state *new_crtc_state, *old_crtc_state;
-   struct dm_crtc_state *new_dm_crtc_state, *old_dm_crtc_state;
-   struct dc_stream_status *status = NULL;
-   enum surface_update_type update_type = UPDATE_TYPE_FAST;
-   struct surface_info_bundle {
-   struct dc_surface_update surface_updates[MAX_SURFACES];
-   struct dc_plane_info plane_infos[MAX_SURFACES];
-   struct dc_scaling_info scaling_infos[MAX_SURFACES];
-   struct dc_flip_addrs flip_addrs[MAX_SURFACES];
-   struct dc_stream_update stream_update;
-   } *bundle;
-
-   bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
-
-   if (!bundle) {
-   DRM_ERROR("Failed to allocate update bundle\n");
-   /* Set type to FULL to avoid crashing in DC*/
-   update_type = UPDATE_TYPE_FULL;
-   goto cleanup;
-   }
-
-   for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, 
new_crtc_state, i) {
-
-   memset(bundle, 0, sizeof(struct surface_info_bundle));
-
-   new_dm_crtc_state = to_dm_crtc_state(new_crtc_state);
-   old_dm_crtc_state = to_dm_crtc_state(old_crtc_state);
-   num_plane = 0;
-
-   if (new_dm_crtc_state->stream != old_dm_crtc_state->stream) {
-   update_type = UPDATE_TYPE_FULL;
-   goto cleanup;
-   }
-
-   if (!new_dm_crtc_state->stream)
-   continue;
-
-   for_each_oldnew_plane_in_state(state, plane, old_plane_state, 
new_plane_state, j) {
-   struct dc_plane_info *plane_info = 
>plane_infos[num_plane];
-   struct dc_flip_addrs *flip_addr = 
>flip_addrs[num_plane];
-   struct dc_scaling_info *scaling_info = 
>scaling_infos[num_plane];
-
-   new_plane_crtc = new_plane_state->crtc;
-   new_dm_plane_state = to_dm_plane_state(new_plane_state);
-   old_dm_plane_state = to_dm_plane_state(old_plane_state);
-
-   if (plane->type == DRM_PLANE_TYPE_CURSOR)
-   continue;
-
-   if (new_dm_plane_state->dc_state != 
old_dm_plane_state->dc_state) {
-   update_type = UPDATE_TYPE_FULL;
-   goto cleanup;
-   }
-
-   if (crtc != 

[PATCH 5/7] drm/amd/display: Reset plane for anything that's not a FAST update

2020-07-30 Thread Nicholas Kazlauskas
[Why]
MEDIUM or FULL updates can require global validation or affect
bandwidth. By treating these all simply as surface updates we aren't
actually passing this through DC global validation.

[How]
There's currently no way to pass surface updates through DC global
validation, nor do I think it's a good idea to change the interface
to accept these.

DC global validation itself is currently stateless, and we can move
our update type checking to be stateless as well by duplicating DC
surface checks in DM based on DRM properties.

We wanted to rely on DC automatically determining this since DC knows
best, but DM is ultimately what fills in everything into DC plane
state so it does need to know as well.

There are basically only three paths that we exercise in DM today:

1) Cursor (async update)
2) Pageflip (fast update)
3) Full pipe programming (medium/full updates)

Which means that anything that's more than a pageflip really needs to
go down path #3.

So this change duplicates all the surface update checks based on DRM
state instead inside of should_reset_plane().

Next step is dropping dm_determine_update_type_for_commit and we no
longer require the old DC state at all for global validation.

Optimization can come later so we don't reset DC planes at all for
MEDIUM udpates and avoid validation, but we might require some extra
checks in DM to achieve this.

Cc: Bhawanpreet Lakha 
Cc: Hersen Wu 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 25 +++
 1 file changed, 25 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 0d5f45742bb5..2cbb29199e61 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8336,6 +8336,31 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
if (old_other_state->crtc != new_other_state->crtc)
return true;
 
+   /* Src/dst size and scaling updates. */
+   if (old_other_state->src_w != new_other_state->src_w ||
+   old_other_state->src_h != new_other_state->src_h ||
+   old_other_state->crtc_w != new_other_state->crtc_w ||
+   old_other_state->crtc_h != new_other_state->crtc_h)
+   return true;
+
+   /* Rotation / mirroring updates. */
+   if (old_other_state->rotation != new_other_state->rotation)
+   return true;
+
+   /* Blending updates. */
+   if (old_other_state->pixel_blend_mode !=
+   new_other_state->pixel_blend_mode)
+   return true;
+
+   /* Alpha updates. */
+   if (old_other_state->alpha != new_other_state->alpha)
+   return true;
+
+   /* Colorspace changes. */
+   if (old_other_state->color_range != 
new_other_state->color_range ||
+   old_other_state->color_encoding != 
new_other_state->color_encoding)
+   return true;
+
/* Framebuffer checks fall at the end. */
if (!old_other_state->fb || !new_other_state->fb)
continue;
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 7/7] drm/amd/display: Replace DRM private objects with subclassed DRM atomic state

2020-07-30 Thread Nicholas Kazlauskas
[Why]
DM atomic check was structured in a way that we required old DC state
in order to dynamically add and remove planes and streams from the
context to build the DC state context for validation.

DRM private objects were used to carry over the last DC state and
were added to the context on nearly every commit - regardless of fast
or full so we could check whether or not the new state could affect
bandwidth.

The problem with this model is that DRM private objects do not
implicitly stall out other commits.

So if you have two commits touching separate DRM objects they could
run concurrently and potentially execute out of order - leading to a
use-after-free.

If we want this to be safe we have two options:
1. Stall out concurrent commits since they touch the same private object
2. Refactor DM to not require old DC state and drop private object usage

[How]
This implements approach #2 since it still allows for judder free
updates in multi-display scenarios.

I'll list the big changes in order at a high level:

1. Subclass DRM atomic state instead of using DRM private objects.

DC relied on the old state to determine which changes cause bandwidth
updates but now we have DM perform similar checks based on DRM state
instead - dropping the requirement for old state to exist at all.

This means that we can now build a new DC context from scratch whenever
we have something that DM thinks could affect bandwidth.

Whenever we need to rebuild bandwidth we now add all CRTCs and planes
to the DRM state in order to get the absolute set of DC streams and
DC planes.

This introduces a stall on other commits, but this stall already
exists because of the lock_and_validation logic and it's necessary
since updates may move around pipes and require full reprogramming.

2. Drop workarounds to add planes to maintain z-order early in atomic
check. This is no longer needed because of the changes for (1).

This also involves fixing up should_plane_reset checks since we can just
avoid resetting streams and planes when they haven't actually changed.

3. Rework dm_update_crtc_state and dm_update_plane_state to be single
pass instead of two pass.

This is necessary since we no longer have the dc_state to add and
remove planes to the context in and we want to defer creation to the
end of commit_check.

It also makes the logic a lot simpler to follow since as an added bonus.

Cc: Bhawanpreet Lakha 
Cc: Harry Wentland 
Cc: Leo Li 
Cc: Daniel Vetter 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 720 +++---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  11 +-
 2 files changed, 280 insertions(+), 451 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 59829ec81694..97a7dfc620e8 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -1839,7 +1839,6 @@ static int dm_resume(void *handle)
struct drm_plane *plane;
struct drm_plane_state *new_plane_state;
struct dm_plane_state *dm_new_plane_state;
-   struct dm_atomic_state *dm_state = 
to_dm_atomic_state(dm->atomic_obj.state);
enum dc_connection_type new_connection_type = dc_connection_none;
struct dc_state *dc_state;
int i, r, j;
@@ -1879,11 +1878,6 @@ static int dm_resume(void *handle)
 
return 0;
}
-   /* Recreate dc_state - DC invalidates it when setting power state to 
S3. */
-   dc_release_state(dm_state->context);
-   dm_state->context = dc_create_state(dm->dc);
-   /* TODO: Remove dc_state->dccg, use dc->dccg directly. */
-   dc_resource_state_construct(dm->dc, dm_state->context);
 
/* Before powering on DC we need to re-initialize DMUB. */
r = dm_dmub_hw_init(adev);
@@ -2019,11 +2013,51 @@ const struct amdgpu_ip_block_version dm_ip_block =
  * *WIP*
  */
 
+struct drm_atomic_state *dm_atomic_state_alloc(struct drm_device *dev)
+{
+   struct dm_atomic_state *dm_state;
+
+   dm_state = kzalloc(sizeof(*dm_state), GFP_KERNEL);
+
+   if (!dm_state)
+   return NULL;
+
+   if (drm_atomic_state_init(dev, _state->base) < 0) {
+   kfree(dm_state);
+   return NULL;
+   }
+
+   return _state->base;
+}
+
+void dm_atomic_state_free(struct drm_atomic_state *state)
+{
+   struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
+
+   if (dm_state->context) {
+   dc_release_state(dm_state->context);
+   dm_state->context = NULL;
+   }
+
+   drm_atomic_state_default_release(state);
+   kfree(state);
+}
+
+void dm_atomic_state_clear(struct drm_atomic_state *state)
+{
+   struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
+
+   drm_atomic_state_default_clear(_state->base);
+}
+
 static const struct drm_mode_config_funcs amdgpu_dm_mode_funcs = {
.fb_create = 

[PATCH 2/7] drm/amd/display: Reset plane when tiling flags change

2020-07-30 Thread Nicholas Kazlauskas
[Why]
Enabling or disable DCC or switching between tiled and linear formats
can require bandwidth updates.

They're currently skipping all DC validation by being treated as purely
surface updates.

[How]
Treat tiling_flag changes (which encode DCC state) as a condition for
resetting the plane.

Cc: Bhawanpreet Lakha 
Cc: Rodrigo Siqueira 
Cc: Hersen Wu 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 7cc5ab90ce13..bf1881bd492c 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -8332,6 +8332,8 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
 * TODO: Come up with a more elegant solution for this.
 */
for_each_oldnew_plane_in_state(state, other, old_other_state, 
new_other_state, i) {
+   struct dm_plane_state *old_dm_plane_state, *new_dm_plane_state;
+
if (other->type == DRM_PLANE_TYPE_CURSOR)
continue;
 
@@ -8342,9 +8344,20 @@ static bool should_reset_plane(struct drm_atomic_state 
*state,
if (old_other_state->crtc != new_other_state->crtc)
return true;
 
-   /* TODO: Remove this once we can handle fast format changes. */
-   if (old_other_state->fb && new_other_state->fb &&
-   old_other_state->fb->format != new_other_state->fb->format)
+   /* Framebuffer checks fall at the end. */
+   if (!old_other_state->fb || !new_other_state->fb)
+   continue;
+
+   /* Pixel format changes can require bandwidth updates. */
+   if (old_other_state->fb->format != new_other_state->fb->format)
+   return true;
+
+   old_dm_plane_state = to_dm_plane_state(old_other_state);
+   new_dm_plane_state = to_dm_plane_state(new_other_state);
+
+   /* Tiling and DCC changes also require bandwidth updates. */
+   if (old_dm_plane_state->tiling_flags !=
+   new_dm_plane_state->tiling_flags)
return true;
}
 
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 3/7] drm/amd/display: Avoid using unvalidated tiling_flags and tmz_surface in prepare_planes

2020-07-30 Thread Nicholas Kazlauskas
[Why]
We're racing with userspace as the flags could potentially change
from when we acquired and validated them in commit_check.

[How]
We unfortunately can't drop this function in its entirety from
prepare_planes since we don't know the afb->address at commit_check
time yet.

So instead of querying new tiling_flags and tmz_surface use the ones
from the plane_state directly.

While we're at it, also update the force_disable_dcc option based
on the state from atomic check.

Cc: Bhawanpreet Lakha 
Cc: Rodrigo Siqueira 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++-
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index bf1881bd492c..f78c09c9585e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -5794,14 +5794,8 @@ static int dm_plane_helper_prepare_fb(struct drm_plane 
*plane,
struct list_head list;
struct ttm_validate_buffer tv;
struct ww_acquire_ctx ticket;
-   uint64_t tiling_flags;
uint32_t domain;
int r;
-   bool tmz_surface = false;
-   bool force_disable_dcc = false;
-
-   dm_plane_state_old = to_dm_plane_state(plane->state);
-   dm_plane_state_new = to_dm_plane_state(new_state);
 
if (!new_state->fb) {
DRM_DEBUG_DRIVER("No FB bound\n");
@@ -5845,27 +5839,35 @@ static int dm_plane_helper_prepare_fb(struct drm_plane 
*plane,
return r;
}
 
-   amdgpu_bo_get_tiling_flags(rbo, _flags);
-
-   tmz_surface = amdgpu_bo_encrypted(rbo);
-
ttm_eu_backoff_reservation(, );
 
afb->address = amdgpu_bo_gpu_offset(rbo);
 
amdgpu_bo_ref(rbo);
 
+   /**
+* We don't do surface updates on planes that have been newly created,
+* but we also don't have the afb->address during atomic check.
+*
+* Fill in buffer attributes depending on the address here, but only on
+* newly created planes since they're not being used by DC yet and this
+* won't modify global state.
+*/
+   dm_plane_state_old = to_dm_plane_state(plane->state);
+   dm_plane_state_new = to_dm_plane_state(new_state);
+
if (dm_plane_state_new->dc_state &&
-   dm_plane_state_old->dc_state != 
dm_plane_state_new->dc_state) {
-   struct dc_plane_state *plane_state = 
dm_plane_state_new->dc_state;
+   dm_plane_state_old->dc_state != dm_plane_state_new->dc_state) {
+   struct dc_plane_state *plane_state =
+   dm_plane_state_new->dc_state;
+   bool force_disable_dcc = !plane_state->dcc.enable;
 
-   force_disable_dcc = adev->asic_type == CHIP_RAVEN && 
adev->in_suspend;
fill_plane_buffer_attributes(
adev, afb, plane_state->format, plane_state->rotation,
-   tiling_flags, _state->tiling_info,
-   _state->plane_size, _state->dcc,
-   _state->address, tmz_surface,
-   force_disable_dcc);
+   dm_plane_state_new->tiling_flags,
+   _state->tiling_info, _state->plane_size,
+   _state->dcc, _state->address,
+   dm_plane_state_new->tmz_surface, force_disable_dcc);
}
 
return 0;
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 4/7] drm/amd/display: Use validated tiling_flags and tmz_surface in commit_tail

2020-07-30 Thread Nicholas Kazlauskas
[Why]
So we're not racing with userspace or deadlocking DM.

[How]
These flags are now stored on dm_plane_state itself and acquried and
validated during commit_check, so just use those instead.

Cc: Daniel Vetter 
Cc: Bhawanpreet Lakha 
Cc: Rodrigo Siqueira 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index f78c09c9585e..0d5f45742bb5 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -7094,8 +7094,6 @@ static void amdgpu_dm_commit_planes(struct 
drm_atomic_state *state,
long r;
unsigned long flags;
struct amdgpu_bo *abo;
-   uint64_t tiling_flags;
-   bool tmz_surface = false;
uint32_t target_vblank, last_flip_vblank;
bool vrr_active = amdgpu_dm_vrr_active(acrtc_state);
bool pflip_present = false;
@@ -7179,20 +7177,12 @@ static void amdgpu_dm_commit_planes(struct 
drm_atomic_state *state,
if (unlikely(r <= 0))
DRM_ERROR("Waiting for fences timed out!");
 
-   /*
-* We cannot reserve buffers here, which means the normal flag
-* access functions don't work. Paper over this with READ_ONCE,
-* but maybe the flags are invariant enough that not even that
-* would be needed.
-*/
-   tiling_flags = READ_ONCE(abo->tiling_flags);
-   tmz_surface = READ_ONCE(abo->flags) & 
AMDGPU_GEM_CREATE_ENCRYPTED;
-
fill_dc_plane_info_and_addr(
-   dm->adev, new_plane_state, tiling_flags,
+   dm->adev, new_plane_state,
+   dm_new_plane_state->tiling_flags,
>plane_infos[planes_count],
-   >flip_addrs[planes_count].address, tmz_surface,
-   false);
+   >flip_addrs[planes_count].address,
+   dm_new_plane_state->tmz_surface, false);
 
DRM_DEBUG_DRIVER("plane: id=%d dcc_en=%d\n",
 new_plane_state->plane->index,
-- 
2.25.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 1/7] drm/amd/display: Store tiling_flags and tmz_surface on dm_plane_state

2020-07-30 Thread Nicholas Kazlauskas
[Why]
Store these in advance so we can reuse them later in commit_tail without
having to reserve the fbo again.

These will also be used for checking for tiling changes when deciding
to reset the plane or not.

[How]
This change should mostly be a refactor. Only commit check is affected
for now and I'll drop the get_fb_info calls in prepare_planes and
commit_tail after.

This runs a prepass loop once we think that all planes have been added
to the context and replaces the get_fb_info calls with accessing the
dm_plane_state instead.

Cc: Bhawanpreet Lakha 
Cc: Rodrigo Siqueira 
Signed-off-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 60 +++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  2 +
 2 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 8d64f5fde7e2..7cc5ab90ce13 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3700,8 +3700,17 @@ static int fill_dc_scaling_info(const struct 
drm_plane_state *state,
 static int get_fb_info(const struct amdgpu_framebuffer *amdgpu_fb,
   uint64_t *tiling_flags, bool *tmz_surface)
 {
-   struct amdgpu_bo *rbo = gem_to_amdgpu_bo(amdgpu_fb->base.obj[0]);
-   int r = amdgpu_bo_reserve(rbo, false);
+   struct amdgpu_bo *rbo;
+   int r;
+
+   if (!amdgpu_fb) {
+   *tiling_flags = 0;
+   *tmz_surface = false;
+   return 0;
+   }
+
+   rbo = gem_to_amdgpu_bo(amdgpu_fb->base.obj[0]);
+   r = amdgpu_bo_reserve(rbo, false);
 
if (unlikely(r)) {
/* Don't show error message when returning -ERESTARTSYS */
@@ -4124,13 +4133,10 @@ static int fill_dc_plane_attributes(struct 
amdgpu_device *adev,
struct drm_crtc_state *crtc_state)
 {
struct dm_crtc_state *dm_crtc_state = to_dm_crtc_state(crtc_state);
-   const struct amdgpu_framebuffer *amdgpu_fb =
-   to_amdgpu_framebuffer(plane_state->fb);
+   struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane_state);
struct dc_scaling_info scaling_info;
struct dc_plane_info plane_info;
-   uint64_t tiling_flags;
int ret;
-   bool tmz_surface = false;
bool force_disable_dcc = false;
 
ret = fill_dc_scaling_info(plane_state, _info);
@@ -4142,15 +4148,12 @@ static int fill_dc_plane_attributes(struct 
amdgpu_device *adev,
dc_plane_state->clip_rect = scaling_info.clip_rect;
dc_plane_state->scaling_quality = scaling_info.scaling_quality;
 
-   ret = get_fb_info(amdgpu_fb, _flags, _surface);
-   if (ret)
-   return ret;
-
force_disable_dcc = adev->asic_type == CHIP_RAVEN && adev->in_suspend;
-   ret = fill_dc_plane_info_and_addr(adev, plane_state, tiling_flags,
+   ret = fill_dc_plane_info_and_addr(adev, plane_state,
+ dm_plane_state->tiling_flags,
  _info,
  _plane_state->address,
- tmz_surface,
+ dm_plane_state->tmz_surface,
  force_disable_dcc);
if (ret)
return ret;
@@ -5753,6 +5756,10 @@ dm_drm_plane_duplicate_state(struct drm_plane *plane)
dc_plane_state_retain(dm_plane_state->dc_state);
}
 
+   /* Framebuffer hasn't been updated yet, so retain old flags. */
+   dm_plane_state->tiling_flags = old_dm_plane_state->tiling_flags;
+   dm_plane_state->tmz_surface = old_dm_plane_state->tmz_surface;
+
return _plane_state->base;
 }
 
@@ -8557,13 +8564,9 @@ dm_determine_update_type_for_commit(struct 
amdgpu_display_manager *dm,
continue;
 
for_each_oldnew_plane_in_state(state, plane, old_plane_state, 
new_plane_state, j) {
-   const struct amdgpu_framebuffer *amdgpu_fb =
-   to_amdgpu_framebuffer(new_plane_state->fb);
struct dc_plane_info *plane_info = 
>plane_infos[num_plane];
struct dc_flip_addrs *flip_addr = 
>flip_addrs[num_plane];
struct dc_scaling_info *scaling_info = 
>scaling_infos[num_plane];
-   uint64_t tiling_flags;
-   bool tmz_surface = false;
 
new_plane_crtc = new_plane_state->crtc;
new_dm_plane_state = to_dm_plane_state(new_plane_state);
@@ -8610,16 +8613,12 @@ dm_determine_update_type_for_commit(struct 
amdgpu_display_manager *dm,
 
bundle->surface_updates[num_plane].scaling_info = 
scaling_info;
 
-   if (amdgpu_fb) {
-

[PATCH] drm/vkms: fix xrgb on compute crc

2020-07-30 Thread Melissa Wen
The previous memset operation was not correctly zeroing the alpha
channel to compute the crc, and as a result, the IGT subtest
kms_cursor_crc/pipe-A-cursor-alpha-transparent fails.

Fixes: db7f419c06d7c ("drm/vkms: Compute CRC with Cursor Plane")

Signed-off-by: Melissa Wen 
---
 drivers/gpu/drm/vkms/vkms_composer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 4af2f19480f4..b8b060354667 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -33,7 +33,7 @@ static uint32_t compute_crc(void *vaddr_out, struct 
vkms_composer *composer)
 + (i * composer->pitch)
 + (j * composer->cpp);
/* XRGB format ignores Alpha channel */
-   memset(vaddr_out + src_offset + 24, 0,  8);
+   bitmap_clear(vaddr_out + src_offset, 24, 8);
crc = crc32_le(crc, vaddr_out + src_offset,
   sizeof(u32));
}
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 4/6] drm/panel: Add panel driver for NewVision NV3052C based LCDs

2020-07-30 Thread Sam Ravnborg
Hi Paul.

While I continue to try to wrap my head around how I think we should
support DBI here are some panel specific comments.

Sam

On Mon, Jul 27, 2020 at 06:46:11PM +0200, Paul Cercueil wrote:
> This driver supports the NewVision NV3052C based LCDs. Right now, it
> only supports the LeadTek LTK035C5444T 2.4" 640x480 TFT LCD panel, which
> can be found in the Anbernic RG-350M handheld console.
> 
> Signed-off-by: Paul Cercueil 
> ---
>  drivers/gpu/drm/panel/Kconfig |   9 +
>  drivers/gpu/drm/panel/Makefile|   1 +
>  .../gpu/drm/panel/panel-newvision-nv3052c.c   | 523 ++
>  3 files changed, 533 insertions(+)
>  create mode 100644 drivers/gpu/drm/panel/panel-newvision-nv3052c.c
> 
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> index de2f2a452be5..6a8a51a702d8 100644
> --- a/drivers/gpu/drm/panel/Kconfig
> +++ b/drivers/gpu/drm/panel/Kconfig
> @@ -198,6 +198,15 @@ config DRM_PANEL_NEC_NL8048HL11
> panel (found on the Zoom2/3/3630 SDP boards). To compile this driver
> as a module, choose M here.
>  
> +config DRM_PANEL_NEWVISION_NV3052C
> + tristate "NewVision NV3052C DSI/SPI RGB panel"
> + depends on OF
> + depends on DRM_MIPI_DSI
> + depends on BACKLIGHT_CLASS_DEVICE
> + help
> +   Say Y here if you want to enable support for the panels built
> +   around the NewVision NV3052C display controller.
> +
>  config DRM_PANEL_NOVATEK_NT35510
>   tristate "Novatek NT35510 RGB panel driver"
>   depends on OF
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
> index e45ceac6286f..a0516ced87db 100644
> --- a/drivers/gpu/drm/panel/Makefile
> +++ b/drivers/gpu/drm/panel/Makefile
> @@ -18,6 +18,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += 
> panel-leadtek-ltk500hd1829.o
>  obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
>  obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
>  obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
> +obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3052C) += panel-newvision-nv3052c.o
>  obj-$(CONFIG_DRM_PANEL_NOVATEK_NT35510) += panel-novatek-nt35510.o
>  obj-$(CONFIG_DRM_PANEL_NOVATEK_NT39016) += panel-novatek-nt39016.o
>  obj-$(CONFIG_DRM_PANEL_OLIMEX_LCD_OLINUXINO) += panel-olimex-lcd-olinuxino.o
> diff --git a/drivers/gpu/drm/panel/panel-newvision-nv3052c.c 
> b/drivers/gpu/drm/panel/panel-newvision-nv3052c.c
> new file mode 100644
> index ..2feabef6dc3c
> --- /dev/null
> +++ b/drivers/gpu/drm/panel/panel-newvision-nv3052c.c
> @@ -0,0 +1,523 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * NevVision NV3052C IPS LCD panel driver
> + *
> + * Copyright (C) 2020, Paul Cercueil 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +struct nv3052c_panel_info {
> + const struct drm_display_mode *display_modes;
> + unsigned int num_modes;
> + unsigned int bus_type;
> + u16 width_mm, height_mm;
> + u32 bus_format, bus_flags;
> +};
> +
> +struct nv3052c_reg {
> + u8 cmd;
> + u8 value;
> +};
> +
> +struct nv3052c {
> + struct drm_panel drm_panel;
> + struct mipi_dsi_device *dsi;
> + struct device *dev;
> +
> + struct regulator *supply;
> + const struct nv3052c_panel_info *panel_info;
> +
> + struct gpio_desc *reset_gpio;
> +
> + struct backlight_device *backlight;

drm_panel has backlight support.

Just calling drm_panel_of_backlight() after init should do the trick.
All other references to backlight can be dropped, including this
variable in struct nv3052c.

There is one delay loop you may need to keep.
Will comment on it below.



> +};
> +
> +static const struct nv3052c_reg nv3052c_regs[] = {
...
> + { 0x36, 0x0a },
> +};
> +
> +static inline struct nv3052c *to_nv3052c(struct drm_panel *panel)
> +{
> + return container_of(panel, struct nv3052c, drm_panel);
> +}
> +
> +static int nv3052c_prepare(struct drm_panel *drm_panel)
> +{
> + struct nv3052c *priv = to_nv3052c(drm_panel);
> + unsigned int i;
> + int err;
> +
> + err = regulator_enable(priv->supply);
> + if (err) {
> + dev_err(priv->dev, "Failed to enable power supply: %d\n", err);
> + return err;
> + }
> +
> + /* Reset the chip */
> + gpiod_set_value_cansleep(priv->reset_gpio, 1);
> + usleep_range(10, 1000);
> + gpiod_set_value_cansleep(priv->reset_gpio, 0);
> + usleep_range(5000, 2);
> +
> + for (i = 0; i < ARRAY_SIZE(nv3052c_regs); i++) {
> + err = mipi_dsi_dcs_write(priv->dsi, nv3052c_regs[i].cmd,
> +  _regs[i].value, 1);
> + if (err) {
> + dev_err(priv->dev, "Unable to set register: %d\n", err);
> + goto err_disable_regulator;
> + }
> + }
> +
> +

Re: [RFC][PATCH] regulator: rpi-panel: Add regulator/backlight driver for RPi panel

2020-07-30 Thread Mark Brown
On Thu, Jul 30, 2020 at 06:28:07PM +0200, Marek Vasut wrote:
> On 7/30/20 5:59 PM, Sam Ravnborg wrote:
> > On Wed, Jul 29, 2020 at 11:46:45PM +0200, Marek Vasut wrote:

> >> This regulator/backlight driver handles the ATTINY88 present on the
> >> RPi 7" touchscreen panel and exposes the power/backlight interfaces.

> > It looks strange that the regulator and the backligth are defined in the
> > same module like this.

> It's one chip, attiny with custom firmware, what do you want me to do
> about it ? I can over-complicate this and split it into multiple
> drivers, but I don't think it's worth the complexity, considering that
> this is likely a one-off device which will never be re-used elsewhere,
> except on this one particular display module for RPi.

Now you've written that you've pretty much guaranteed someone's going to
use the same component elsewhere :)

I think my main question would be that if this is going to be written
like this shouldn't it be a backlight driver rather than a regulator
driver?  I don't 100% follow how this would actually get used in a
system (perhaps the binding would help) but for these things if there's
only one tightly coupled user that's possible it's sometimes simpler to
just skip APIs and do things directly.


signature.asc
Description: PGP signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v9 0/4] driver core: add probe error check helper

2020-07-30 Thread Mark Brown
On Thu, Jul 30, 2020 at 11:45:25AM -0700, Dmitry Torokhov wrote:
> On Thu, Jul 30, 2020 at 11:16 AM Mark Brown  wrote:

> > You can sometimes do a better job of explaining what the resource you
> > were looking for was,

> I think it is true for very esoteric cases. I.e. your driver uses 2
> interrupt lines, or something like that. For GPIO, regulators, and
> clocks we normally have a name/connection ID that provides enough of

*Normally* but not always - some of the older bindings do love their
arrays of phandles (or mixes of numbers and phandles!) unfortunately.

> context. We need to remember, the error messages really only make
> total sense to a person familiar with the driver to begin with, not
> for a random person looking at the log.

Not really, one of the big targets is people doing system integration
who are writing a DT or possibly producing a highly tuned kernel config.
They needn't have a strong familiarity with the driver, they're often
just picking it up off the shelf.

> > and of course you still need diagnostics in the
> > non-deferral case.  Whatever happens we'll need a lot of per-driver
> > churn, either removing existing diagnostics that get factored into cores
> > or updating to use this new API.

> The point is if you push it into core you'll get the benefit of
> notifying about the deferral (and can "attach" deferral reason to a
> device) without changing drivers at all. You can clean them up later
> if you want, or decide that additional logging in error paths does not
> hurt. This new API does not do you any good unless you convert
> drivers, and you need to convert the majority of them to be able to
> rely on the deferral diagnostic that is being added.

The push for this is that there's already people going around modifying
drivers whatever happens but at present they're mainly trying to delete
diagnostics which isn't wonderful.  Besides, even if we push things into
the subsystems they'd want to use this interface or something quite like
it anyway - it's more a question of if we go quickly add some users to
subsystems isn't it?  I'm not against that.


signature.asc
Description: PGP signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v9 0/4] driver core: add probe error check helper

2020-07-30 Thread Mark Brown
On Thu, Jul 30, 2020 at 10:46:31AM -0700, Dmitry Torokhov wrote:
> On Thu, Jul 30, 2020 at 9:49 AM Mark Brown  wrote:

> > The error messages are frequently in the caller rather than the
> > frameworks, it's often helpful for the comprehensibility of the error
> > messages especially in cases where things may be legitimately absent.

> Not for deferral. All you need to know in this case is:

> "device A is attempting to request resource B which is not ready yet"

> There is nothing to handle on the caller part except to float the error up.

You can sometimes do a better job of explaining what the resource you
were looking for was, and of course you still need diagnostics in the
non-deferral case.  Whatever happens we'll need a lot of per-driver
churn, either removing existing diagnostics that get factored into cores
or updating to use this new API.


signature.asc
Description: PGP signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: linux-next: manual merge of the hmm tree with the drm tree

2020-07-30 Thread Ralph Campbell



On 7/30/20 5:03 AM, Jason Gunthorpe wrote:

On Thu, Jul 30, 2020 at 07:21:10PM +1000, Stephen Rothwell wrote:

Hi all,

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

   drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c

between commit:

   7763d24f3ba0 ("drm/nouveau/vmm/gp100-: fix mapping 2MB sysmem pages")

from the drm tree and commits:

   4725c6b82a48 ("nouveau: fix mapping 2MB sysmem pages")
   1a77decd0cae ("nouveau: fix storing invalid ptes")

from the hmm tree.

7763d24f3ba0 and 4725c6b82a48 are exactly the same patch.


Oh? Ralph? What happened here?


Ben did email me saying he was planning to take this patch into
his nouveau tree and I did reply to him saying you had also taken it
into your tree and that I had more nouveau/SVM patches for you on the way.
So, I'm not sure what happened.


Ben can you drop 7763d24f3ba0 ?

Jason


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v3] drm/nouveau: Accept 'legacy' format modifiers

2020-07-30 Thread James Jones
Accept the DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK()
family of modifiers to handle broken userspace
Xorg modesetting and Mesa drivers. Existing Mesa
drivers are still aware of only these older
format modifiers which do not differentiate
between different variations of the block linear
layout. When the format modifier support flag was
flipped in the nouveau kernel driver, the X.org
modesetting driver began attempting to use its
format modifier-enabled framebuffer path. Because
the set of format modifiers advertised by the
kernel prior to this change do not intersect with
the set of format modifiers advertised by Mesa,
allocating GBM buffers using format modifiers
fails and the modesetting driver falls back to
non-modifier allocation. However, it still later
queries the modifier of the GBM buffer when
creating its DRM-KMS framebuffer object, receives
the old-format modifier from Mesa, and attempts
to create a framebuffer with it. Since the kernel
is still not aware of these formats, this fails.

Userspace should not be attempting to query format
modifiers of GBM buffers allocated with a non-
format-modifier-aware allocation path, but to
avoid breaking existing userspace behavior, this
change accepts the old-style format modifiers when
creating framebuffers and applying them to planes
by translating them to the equivalent new-style
modifier. To accomplish this, some layout
parameters must be assumed to match properties of
the device targeted by the relevant ioctls. To
avoid perpetuating misuse of the old-style
modifiers, this change does not advertise support
for them. Doing so would imply compatibility
between devices with incompatible memory layouts.

Tested with Xorg 1.20 modesetting driver,
weston@c46c70dac84a4b3030cd05b380f9f410536690fc,
gnome & KDE wayland desktops from Ubuntu 18.04,
kmscube hacked to use linear mod, and sway 1.5

Reported-by: Kirill A. Shutemov 
Fixes: fa4f4c213f5f ("drm/nouveau/kms: Support NVIDIA format modifiers")
Link: https://lkml.org/lkml/2020/6/30/1251
Signed-off-by: James Jones 
---
 drivers/gpu/drm/nouveau/nouveau_display.c | 26 +--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 496c4621cc78..31543086254b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -191,8 +191,14 @@ nouveau_decode_mod(struct nouveau_drm *drm,
   uint32_t *tile_mode,
   uint8_t *kind)
 {
+   struct nouveau_display *disp = nouveau_display(drm->dev);
BUG_ON(!tile_mode || !kind);
 
+   if ((modifier & (0xffull << 12)) == 0ull) {
+   /* Legacy modifier.  Translate to this device's 'kind.' */
+   modifier |= disp->format_modifiers[0] & (0xffull << 12);
+   }
+
if (modifier == DRM_FORMAT_MOD_LINEAR) {
/* tile_mode will not be used in this case */
*tile_mode = 0;
@@ -227,6 +233,16 @@ nouveau_framebuffer_get_layout(struct drm_framebuffer *fb,
}
 }
 
+static const u64 legacy_modifiers[] = {
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4),
+   DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5),
+   DRM_FORMAT_MOD_INVALID
+};
+
 static int
 nouveau_validate_decode_mod(struct nouveau_drm *drm,
uint64_t modifier,
@@ -247,8 +263,14 @@ nouveau_validate_decode_mod(struct nouveau_drm *drm,
 (disp->format_modifiers[mod] != modifier);
 mod++);
 
-   if (disp->format_modifiers[mod] == DRM_FORMAT_MOD_INVALID)
-   return -EINVAL;
+   if (disp->format_modifiers[mod] == DRM_FORMAT_MOD_INVALID) {
+   for (mod = 0;
+(legacy_modifiers[mod] != DRM_FORMAT_MOD_INVALID) &&
+(legacy_modifiers[mod] != modifier);
+mod++);
+   if (legacy_modifiers[mod] == DRM_FORMAT_MOD_INVALID)
+   return -EINVAL;
+   }
 
nouveau_decode_mod(drm, modifier, tile_mode, kind);
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v9 0/4] driver core: add probe error check helper

2020-07-30 Thread Mark Brown
On Thu, Jul 30, 2020 at 09:18:30AM -0700, Dmitry Torokhov wrote:

> I believe it still has not been answered why this can't be pushed into
> resource providers (clock, regulators, gpio, interrupts, etc),
> especially for devm APIs where we know exactly what device we are
> requesting a resource for, so that individual drivers do not need to
> change anything.

The error messages are frequently in the caller rather than the
frameworks, it's often helpful for the comprehensibility of the error
messages especially in cases where things may be legitimately absent.

>  We can mark the device as being probed so that probe
> deferral is only handled when we actually execute probe() (and for the
> bonus points scream loudly if someone tries to return -EPROBE_DEFER
> outside of probe path).

Is this a big issue?


signature.asc
Description: PGP signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] dma-resv: lockdep-prime address_space->i_mmap_rwsem for dma-resv

2020-07-30 Thread Intel


On 7/30/20 3:17 PM, Daniel Vetter wrote:

On Thu, Jul 30, 2020 at 2:17 PM Thomas Hellström (Intel)
 wrote:


On 7/28/20 3:58 PM, Daniel Vetter wrote:

GPU drivers need this in their shrinkers, to be able to throw out
mmap'ed buffers. Note that we also need dma_resv_lock in shrinkers,
but that loop is resolved by trylocking in shrinkers.

So full hierarchy is now (ignore some of the other branches we already
have primed):

mmap_read_lock -> dma_resv -> shrinkers -> i_mmap_lock_write

I hope that's not inconsistent with anything mm or fs does, adding
relevant people.


Looks OK to me. The mapping_dirty_helpers run under the i_mmap_lock, but
don't allocate any memory AFAICT.

Since huge page-table-entry splitting may happen under the i_mmap_lock
from unmap_mapping_range() it might be worth figuring out how new page
directory pages are allocated, though.

ofc I'm not an mm expert at all, but I did try to scroll through all
i_mmap_lock_write/read callers. Found the following:

- kernel/events/uprobes.c in build_map_info:

 /*
  * Needs GFP_NOWAIT to avoid i_mmap_rwsem recursion through
  * reclaim. This is optimistic, no harm done if it fails.
  */

- I got lost in the hugetlb.c code and couldn't convince myself it's
not allocating page directories at various levels with something else
than GFP_KERNEL.

So looks like the recursion is clearly there and known, but the
hugepage code is too complex and flying over my head.
-Daniel


OK, so I inverted your annotation and ran a memory hog, and got the 
below splat. So clearly your proposed reclaim->i_mmap_lock locking order 
is an already established one.


So

Reviewed-by: Thomas Hellström 

8<-

[  308.324654] WARNING: possible circular locking dependency detected
[  308.324655] 5.8.0-rc2+ #16 Not tainted
[  308.324656] --
[  308.324657] kswapd0/98 is trying to acquire lock:
[  308.324658] 92a16f758428 (>i_mmap_rwsem){}-{3:3}, 
at: rmap_walk_file+0x1c0/0x2f0

[  308.324663]
   but task is already holding lock:
[  308.324664] b0960240 (fs_reclaim){+.+.}-{0:0}, at: 
__fs_reclaim_acquire+0x5/0x30

[  308.324666]
   which lock already depends on the new lock.

[  308.324667]
   the existing dependency chain (in reverse order) is:
[  308.324667]
   -> #1 (fs_reclaim){+.+.}-{0:0}:
[  308.324670]    fs_reclaim_acquire+0x34/0x40
[  308.324672]    dma_resv_lockdep+0x186/0x224
[  308.324675]    do_one_initcall+0x5d/0x2c0
[  308.324676]    kernel_init_freeable+0x222/0x288
[  308.324678]    kernel_init+0xa/0x107
[  308.324679]    ret_from_fork+0x1f/0x30
[  308.324680]
   -> #0 (>i_mmap_rwsem){}-{3:3}:
[  308.324682]    __lock_acquire+0x119f/0x1fc0
[  308.324683]    lock_acquire+0xa4/0x3b0
[  308.324685]    down_read+0x2d/0x110
[  308.324686]    rmap_walk_file+0x1c0/0x2f0
[  308.324687]    page_referenced+0x133/0x150
[  308.324689]    shrink_active_list+0x142/0x610
[  308.324690]    balance_pgdat+0x229/0x620
[  308.324691]    kswapd+0x200/0x470
[  308.324693]    kthread+0x11f/0x140
[  308.324694]    ret_from_fork+0x1f/0x30
[  308.324694]
   other info that might help us debug this:

[  308.324695]  Possible unsafe locking scenario:

[  308.324695]    CPU0    CPU1
[  308.324696]        
[  308.324696]   lock(fs_reclaim);
[  308.324697] lock(>i_mmap_rwsem);
[  308.324698]    lock(fs_reclaim);
[  308.324699]   lock(>i_mmap_rwsem);
[  308.324699]
    *** DEADLOCK ***

[  308.324700] 1 lock held by kswapd0/98:
[  308.324701]  #0: b0960240 (fs_reclaim){+.+.}-{0:0}, at: 
__fs_reclaim_acquire+0x5/0x30

[  308.324702]
   stack backtrace:
[  308.324704] CPU: 1 PID: 98 Comm: kswapd0 Not tainted 5.8.0-rc2+ #16
[  308.324705] Hardware name: VMware, Inc. VMware Virtual Platform/440BX 
Desktop Reference Platform, BIOS 6.00 07/29/2019

[  308.324706] Call Trace:
[  308.324710]  dump_stack+0x92/0xc8
[  308.324711]  check_noncircular+0x12d/0x150
[  308.324713]  __lock_acquire+0x119f/0x1fc0
[  308.324715]  lock_acquire+0xa4/0x3b0
[  308.324716]  ? rmap_walk_file+0x1c0/0x2f0
[  308.324717]  ? __lock_acquire+0x394/0x1fc0
[  308.324719]  down_read+0x2d/0x110
[  308.324720]  ? rmap_walk_file+0x1c0/0x2f0
[  308.324721]  rmap_walk_file+0x1c0/0x2f0
[  308.324722]  page_referenced+0x133/0x150
[  308.324724]  ? __page_set_anon_rmap+0x70/0x70
[  308.324725]  ? page_get_anon_vma+0x190/0x190
[  308.324726]  shrink_active_list+0x142/0x610
[  308.324728]  balance_pgdat+0x229/0x620
[  308.324730]  kswapd+0x200/0x470
[  308.324731]  ? lockdep_hardirqs_on_prepare+0xf5/0x170
[  308.324733]  ? finish_wait+0x80/0x80
[  308.324734]  ? balance_pgdat+0x620/0x620
[  

[PULL] drm-intel-next-fixes

2020-07-30 Thread Joonas Lahtinen
Hi Dave & Daniel,

(Covering for Jani here for drm-intel-next-fixes)

5 new commits over drm-intel-next here.

Fix for KASAN detected race condition and linux-next scheduler
WARNs. Patch to avoid IRQ spinlock and Cc: stable PMU refcount
update.

CI machinery needed some kicking, so results didn't appear
at first. BAT now passed, shards should shortly be availabl

CI_DINF_202 at 
https://intel-gfx-ci.01.org/tree/drm-intel-next-fixes/combined-alt.html?

Regards, Joonas

***

drm-intel-next-fixes-2020-07-30-1:

- Fixes for linux-next introduced scheduler races
- Fix for KASAN race in active execlists
- Fix for previous breadcrumb breadcrumb code to avoid IRQ spinlock
- Cc: stable patch for PMU refcount

The following changes since commit d524b87f77364db096855d7eb714ffacec974ddf:

  drm/i915: Update DRIVER_DATE to 20200702 (2020-07-02 21:25:28 +0300)

are available in the Git repository at:

  git://anongit.freedesktop.org/drm/drm-intel 
tags/drm-intel-next-fixes-2020-07-30-1

for you to fetch changes up to 6bd0b413618ffb50f900ec770283d8c2217d069f:

  drm/i915: Filter wake_flags passed to default_wake_function (2020-07-30 
15:33:37 +0300)


- Fixes for linux-next introduced scheduler races
- Fix for KASAN race in active execlists
- Fix for previous breadcrumb breadcrumb code to avoid IRQ spinlock
- Cc: stable patch for PMU refcount


Abdiel Janulgue (2):
  drm/i915/dg1: add initial DG-1 definitions
  drm/i915/dg1: Add DG1 PCI IDs

Anshuman Gupta (1):
  drm/i915/hdcp: Update CP as per the kernel internal state

Anusha Srivatsa (1):
  drm/i915/dg1: Remove SHPD_FILTER_CNT register programming

Chris Wilson (27):
  drm/i915/gem: Only revoke the GGTT mmappings on aperture detiling changes
  drm/i915/gem: Only revoke mmap handlers if active
  drm/i915/gem: Drop forced struct_mutex from shrinker_taints_mutex
  drm/i915: Also drop vm.ref along error paths for vma construction
  drm/i915/gem: Split the context's obj:vma lut into its own mutex
  drm/i915: Export ppgtt_bind_vma
  drm/i915/gt: Pin the rings before marking active
  drm/i915: Update dma-attributes for our sg DMA
  drm/i915/gem: Unpin idle contexts from kswapd reclaim
  drm/i915/gt: Replace opencoded i915_gem_object_pin_map()
  drm/i915: Release shortlived maps of longlived objects
  drm/i915: Remove i915_gem_object_get_dirty_page()
  drm/i915/gt: Optimise aliasing-ppgtt allocations
  drm/i915/selftest: Check that GPR are restored across noa_wait
  drm/i915/gt: Be defensive in the face of false CS events
  drm/i915: Pull printing GT capabilities on error to err_print_gt
  drm/i915/gt: Always reset the engine, even if inactive, on execlists 
failure
  drm/i915/gt: Ignore irq enabling on the virtual engines
  drm/i915/gt: Only swap to a random sibling once upon creation
  drm/i915: Skip signaling a signaled request
  drm/i915/gt: Trace placement of timeline HWSP
  drm/i915/gt: Assert the kernel context is using the HWSP
  drm/i915: Provide the perf pmu.module
  drm/i915: Be wary of data races when reading the active execlists
  drm/i915: Remove i915_request.lock requirement for execution callbacks
  drm/i915: Copy default modparams to mock i915_device
  drm/i915: Filter wake_flags passed to default_wake_function

Colin Ian King (1):
  drm/i915/selftest: fix an error return path where err is not being set

Dan Carpenter (1):
  drm/i915/selftest: Fix an error code in live_noa_gpr()

Daniele Ceraolo Spurio (8):
  drm/i915: Convert device_info to uncore/de_read
  drm/i915: Use the gt in HAS_ENGINE
  drm/i915: Move engine-related mmio init to engines_init_mmio
  drm/i915: Move the engine mask to intel_gt_info
  drm/i915: Introduce gt_init_mmio
  drm/i915/sseu: Move sseu detection and dump to intel_sseu
  drm/i915: gt-fy sseu debugfs
  drm/i915: Move sseu debugfs under gt/

Flavio Suligoi (1):
  drm/i915: Fix spelling mistake in i915_reg.h

Jani Nikula (1):
  drm/i915: Update DRIVER_DATE to 20200715

José Roberto de Souza (6):
  drm/i915/display: Implement new combo phy initialization step
  drm/i915/ehl: Add new PCI ids
  drm/i915/tgl: Implement WAs 18011464164 and 22010931296
  drm/i915/display: Replace drm_i915_private in voltage swing functions by 
intel_encoder
  drm/i915/display: Remove port and phy from voltage swing functions
  drm/i915/bios: Parse HOBL parameter

Lee Shawn C (1):
  drm/i915/mst: filter out the display mode exceed sink's capability

Lucas De Marchi (4):
  drm/i915/display: prefer dig_port to reference intel_digital_port
  drm/i915: do not read swizzle info if unavailable
  drm/i915/dg1: add support for the master unit interrupt
  drm/i915/dg1: Add fake PCH

Lyude Paul (1):
  drm/probe_helper: Add 

Re: [RFC][PATCH] regulator: rpi-panel: Add regulator/backlight driver for RPi panel

2020-07-30 Thread Sam Ravnborg
Hi Marek

On Wed, Jul 29, 2020 at 11:46:45PM +0200, Marek Vasut wrote:
> This regulator/backlight driver handles the ATTINY88 present on the
> RPi 7" touchscreen panel and exposes the power/backlight interfaces.
> 
> Signed-off-by: Marek Vasut 
> To: dri-devel@lists.freedesktop.org
> Cc: Eric Anholt 
> Cc: Mark Brown 
> Cc: Sam Ravnborg 

It looks strange that the regulator and the backligth are defined in the
same module like this.

The usual approach is to have an independent regulator and an
independent backlight. Each are represented by their own node in the DT.

Also the compatible "raspberrypi,7inch-touchscreen-panel-regulator",
is unknown. We need a binding for the compatible.

For backlight drivers, and modules that includes backlight support it
would be good to include the backlight gang in cc:
Jingoo, Lee, Daniel.

One detail below - but I otherwise did not look at the code.

Sam



> ---
>  drivers/regulator/Kconfig |  10 +
>  drivers/regulator/Makefile|   1 +
>  .../regulator/rpi-panel-attiny-regulator.c| 214 ++
>  3 files changed, 225 insertions(+)
>  create mode 100644 drivers/regulator/rpi-panel-attiny-regulator.c
> 
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index de17ef7e18f0..439cc5226bae 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -864,6 +864,16 @@ config REGULATOR_QCOM_USB_VBUS
> Say M here if you want to include support for enabling the VBUS output
> as a module. The module will be named "qcom_usb_vbus_regulator".
>  
> +config REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY
> + tristate "Raspberry Pi 7-inch touchscreen panel ATTINY regulator"
> + depends on BACKLIGHT_CLASS_DEVICE
> + depends on I2C
> + select REGMAP_I2C
> + help
> +   This driver supports ATTINY regulator on the Raspberry Pi 7-inch
> +   touchscreen unit. The regulator is used to enable power to the
> +   TC358762, display and to control backlight.
> +
>  config REGULATOR_RC5T583
>   tristate "RICOH RC5T583 Power regulators"
>   depends on MFD_RC5T583
> diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
> index d8d3ecf526a8..6e39ea87901e 100644
> --- a/drivers/regulator/Makefile
> +++ b/drivers/regulator/Makefile
> @@ -107,6 +107,7 @@ obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
>  obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o
>  obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
>  obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
> +obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY)  += 
> rpi-panel-attiny-regulator.o
>  obj-$(CONFIG_REGULATOR_RC5T583)  += rc5t583-regulator.o
>  obj-$(CONFIG_REGULATOR_RK808)   += rk808-regulator.o
>  obj-$(CONFIG_REGULATOR_RN5T618) += rn5t618-regulator.o
> diff --git a/drivers/regulator/rpi-panel-attiny-regulator.c 
> b/drivers/regulator/rpi-panel-attiny-regulator.c
> new file mode 100644
> index ..ee46bfbf5eee
> --- /dev/null
> +++ b/drivers/regulator/rpi-panel-attiny-regulator.c
> @@ -0,0 +1,214 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2020 Marek Vasut 
> + *
> + * Based on rpi_touchscreen.c by Eric Anholt 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* I2C registers of the Atmel microcontroller. */
> +#define REG_ID   0x80
> +#define REG_PORTA0x81
> +#define REG_PORTA_HF BIT(2)
> +#define REG_PORTA_VF BIT(3)
> +#define REG_PORTB0x82
> +#define REG_POWERON  0x85
> +#define REG_PWM  0x86
> +
> +static const struct regmap_config attiny_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = REG_PWM,
> + .cache_type = REGCACHE_NONE,
> +};
> +
> +static int attiny_lcd_power_enable(struct regulator_dev *rdev)
> +{
> + unsigned int data;
> +
> + regmap_write(rdev->regmap, REG_POWERON, 1);
> + /* Wait for nPWRDWN to go low to indicate poweron is done. */
> + regmap_read_poll_timeout(rdev->regmap, REG_PORTB, data,
> + data & BIT(0), 10, 100);
> +
> + /* Default to the same orientation as the closed source
> +  * firmware used for the panel.  Runtime rotation
> +  * configuration will be supported using VC4's plane
> +  * orientation bits.
> +  */
> + regmap_write(rdev->regmap, REG_PORTA, BIT(2));
> +
> + return 0;
> +}
> +
> +static int attiny_lcd_power_disable(struct regulator_dev *rdev)
> +{
> + regmap_write(rdev->regmap, REG_PWM, 0);
> + regmap_write(rdev->regmap, REG_POWERON, 0);
> + udelay(1);
> + return 0;
> +}
> +
> +static int attiny_lcd_power_is_enabled(struct regulator_dev *rdev)
> +{
> + unsigned int data;
> + int ret;
> +
> + ret = regmap_read(rdev->regmap, REG_POWERON, );
> + if (ret < 0)
> + 

Re: [PATCH v5 0/6] Add support for GPU DDR BW scaling

2020-07-30 Thread Rob Clark
On Thu, Jul 30, 2020 at 8:37 AM Viresh Kumar  wrote:
>
> On 30-07-20, 08:27, Rob Clark wrote:
> > Hmm, I've already sent my pull request to Dave, dropping the patch
> > would require force-push and sending a new PR.  Which I can do if Dave
> > prefers.  OTOH I guess it isn't the end of the world if the patch is
> > merged via two different trees.
>
> I don't think a patch can go via two trees, as that would have two sha
> keys for the same code.

it looks weird in the history, but other than that I think it is
fine.. at least I see it happen somewhat regularly with fixes in drm

> Though it is fine for a patch to go via two different trees if we make
> sure the same sha key is used for both.
>
> Will it be possible for you to provide a branch/tag of your branch
> that I can base stuff of ?

You could use https://gitlab.freedesktop.org/drm/msm/-/commits/msm-next/
(or the tag drm-msm-next-2020-07-29), which already has the OPP patch.
I've been trying to avoid force-pushing that because downstream trees
are already pulling from that.

BR,
-R
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] ttm: ttm_bo_swapout_all doesn't use it's argument.

2020-07-30 Thread Roland Scheidegger
Patch looks good to me too.
Reviewed-by: Roland Scheidegger 

Seems indeed like we should do some cleanup.

Roland

Am 28.07.20 um 09:37 schrieb Christian König:
> Am 28.07.20 um 05:42 schrieb Dave Airlie:
>> From: Dave Airlie 
>>
>> Just drop the argument from this.
>>
>> This does ask the question if this is the function vmwgfx
>> should be using or should it be doing an evict all like
>> the other drivers.
>>
>> Signed-off-by: Dave Airlie 
> 
> Reviewed-by: Christian König 
> 
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c    | 2 +-
>>   drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 +-
>>   include/drm/ttm/ttm_bo_api.h    | 2 +-
>>   3 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index b03747717ec7..f297fd5e02d4 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -1838,7 +1838,7 @@ int ttm_bo_swapout(struct ttm_bo_global *glob,
>> struct ttm_operation_ctx *ctx)
>>   }
>>   EXPORT_SYMBOL(ttm_bo_swapout);
>>   -void ttm_bo_swapout_all(struct ttm_bo_device *bdev)
>> +void ttm_bo_swapout_all(void)
>>   {
>>   struct ttm_operation_ctx ctx = {
>>   .interruptible = false,
>> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
>> b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
>> index 470428387878..fb39826f72c1 100644
>> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
>> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
>> @@ -1352,7 +1352,7 @@ static int vmw_pm_freeze(struct device *kdev)
>>   vmw_execbuf_release_pinned_bo(dev_priv);
>>   vmw_resource_evict_all(dev_priv);
>>   vmw_release_device_early(dev_priv);
>> -    ttm_bo_swapout_all(_priv->bdev);
>> +    ttm_bo_swapout_all();
>>   if (dev_priv->enable_fb)
>>   vmw_fifo_resource_dec(dev_priv);
>>   if (atomic_read(_priv->num_fifo_resources) != 0) {
>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>> index b1c705a93517..a9e13b252820 100644
>> --- a/include/drm/ttm/ttm_bo_api.h
>> +++ b/include/drm/ttm/ttm_bo_api.h
>> @@ -692,7 +692,7 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev,
>> struct file *filp,
>>     int ttm_bo_swapout(struct ttm_bo_global *glob,
>>   struct ttm_operation_ctx *ctx);
>> -void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>> +void ttm_bo_swapout_all(void);
>>     /**
>>    * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
> 

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[pull] amdgpu drm-fixes-5.8 (take 2)

2020-07-30 Thread Alex Deucher
Hi Dave, Daniel,

A few fixes for 5.8.  It would be nice to get these in for 5.8 final.  Take
2 just reverts the original fix because the fix for the fix seems to cause
other problems.

The following changes since commit a4a2739beb8933a19281bca077fdb852598803ed:

  Merge tag 'drm-misc-fixes-2020-07-28' of 
git://anongit.freedesktop.org/drm/drm-misc into drm-fixes (2020-07-29 12:46:58 
+1000)

are available in the Git repository at:

  git://people.freedesktop.org/~agd5f/linux tags/amd-drm-fixes-5.8-2020-07-30

for you to fetch changes up to 87004abfbc27261edd15716515d89ab42198b405:

  Revert "drm/amdgpu: Fix NULL dereference in dpm sysfs handlers" (2020-07-30 
11:03:28 -0400)


amd-drm-fixes-5.8-2020-07-30:

amdgpu:
- Revert a fix which caused other regressions
- Fix potential kernel info leak
- Fix a use-after-free bug that was uncovered by another change in 5.7


Alex Deucher (1):
  Revert "drm/amdgpu: Fix NULL dereference in dpm sysfs handlers"

Mazin Rezk (1):
  drm/amd/display: Clear dm_state for fast updates

Peilin Ye (1):
  drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()

 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c|  9 --
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 +--
 3 files changed, 35 insertions(+), 13 deletions(-)
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2 2/3] drm/ingenic: ipu: Remove YUV422 from supported formats on JZ4725B

2020-07-30 Thread Sam Ravnborg
Hi Paul

On Thu, Jul 30, 2020 at 04:48:29PM +0200, Paul Cercueil wrote:
> When configuring the IPU for packed YUV 4:2:2, depending on the scaling
> ratios given by the source and destination resolutions, it is possible
> to crash the IPU block, to the point where a software reset of the IP
> does not fix it. This can happen anytime, in the first few frames, or
> after dozens of minutes. The same crash also happens when the IPU is
> fully controlled by the LCD controller (in that case no HW register is
> written at any moment after startup), which points towards a hardware
> bug.
> 
> Thanksfully multiplanar YUV is not affected.
> 
> Until this bug is fixed or worked around, address this issue by removing
> support for YUV 4:2:2 on the IPU of the JZ4725B.
> 
> v2: Update commit message (remove the "crash beyond repair" bit)
> 
> Signed-off-by: Paul Cercueil 
Reviewed-by: Sam Ravnborg 
> ---
>  drivers/gpu/drm/ingenic/ingenic-ipu.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c 
> b/drivers/gpu/drm/ingenic/ingenic-ipu.c
> index 7eae56fa92ea..7dd2a6ae4994 100644
> --- a/drivers/gpu/drm/ingenic/ingenic-ipu.c
> +++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c
> @@ -795,10 +795,16 @@ static int ingenic_ipu_remove(struct platform_device 
> *pdev)
>  }
>  
>  static const u32 jz4725b_ipu_formats[] = {
> + /*
> +  * While officially supported, packed YUV 4:2:2 formats can cause
> +  * random hardware crashes on JZ4725B under certain circumstances.
> +  * It seems to happen with some specific resize ratios.
> +  * Until a proper workaround or fix is found, disable these formats.
>   DRM_FORMAT_YUYV,
>   DRM_FORMAT_YVYU,
>   DRM_FORMAT_UYVY,
>   DRM_FORMAT_VYUY,
> + */
>   DRM_FORMAT_YUV411,
>   DRM_FORMAT_YUV420,
>   DRM_FORMAT_YUV422,
> -- 
> 2.27.0
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2 3/3] drm/ingenic: ipu: Only enable clock when needed

2020-07-30 Thread Sam Ravnborg
On Thu, Jul 30, 2020 at 04:48:30PM +0200, Paul Cercueil wrote:
> Instead of keeping the IPU clock enabled constantly, enable and disable
> it on demand, when the IPU plane is used. That way, we won't use any
> extra power when the IPU is not used.
> 
> v2: Explain the reason of this patch
> 
> Signed-off-by: Paul Cercueil 
Reviewed-by: Sam Ravnborg 

And thanks for the quick update!

Sam

> ---
>  drivers/gpu/drm/ingenic/ingenic-ipu.c | 23 ---
>  1 file changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c 
> b/drivers/gpu/drm/ingenic/ingenic-ipu.c
> index 7dd2a6ae4994..fc8c6e970ee3 100644
> --- a/drivers/gpu/drm/ingenic/ingenic-ipu.c
> +++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c
> @@ -49,6 +49,7 @@ struct ingenic_ipu {
>   struct regmap *map;
>   struct clk *clk;
>   const struct soc_info *soc_info;
> + bool clk_enabled;
>  
>   unsigned int num_w, num_h, denom_w, denom_h;
>  
> @@ -288,12 +289,23 @@ static void ingenic_ipu_plane_atomic_update(struct 
> drm_plane *plane,
>   const struct drm_format_info *finfo;
>   u32 ctrl, stride = 0, coef_index = 0, format = 0;
>   bool needs_modeset, upscaling_w, upscaling_h;
> + int err;
>  
>   if (!state || !state->fb)
>   return;
>  
>   finfo = drm_format_info(state->fb->format->format);
>  
> + if (!ipu->clk_enabled) {
> + err = clk_enable(ipu->clk);
> + if (err) {
> + dev_err(ipu->dev, "Unable to enable clock: %d\n", err);
> + return;
> + }
> +
> + ipu->clk_enabled = true;
> + }
> +
>   /* Reset all the registers if needed */
>   needs_modeset = drm_atomic_crtc_needs_modeset(state->crtc->state);
>   if (needs_modeset) {
> @@ -578,6 +590,11 @@ static void ingenic_ipu_plane_atomic_disable(struct 
> drm_plane *plane,
>   regmap_clear_bits(ipu->map, JZ_REG_IPU_CTRL, JZ_IPU_CTRL_CHIP_EN);
>  
>   ingenic_drm_plane_disable(ipu->master, plane);
> +
> + if (ipu->clk_enabled) {
> + clk_disable(ipu->clk);
> + ipu->clk_enabled = false;
> + }
>  }
>  
>  static const struct drm_plane_helper_funcs ingenic_ipu_plane_helper_funcs = {
> @@ -761,9 +778,9 @@ static int ingenic_ipu_bind(struct device *dev, struct 
> device *master, void *d)
>   drm_object_attach_property(>base, ipu->sharpness_prop,
>  ipu->sharpness);
>  
> - err = clk_prepare_enable(ipu->clk);
> + err = clk_prepare(ipu->clk);
>   if (err) {
> - dev_err(dev, "Unable to enable clock\n");
> + dev_err(dev, "Unable to prepare clock\n");
>   return err;
>   }
>  
> @@ -775,7 +792,7 @@ static void ingenic_ipu_unbind(struct device *dev,
>  {
>   struct ingenic_ipu *ipu = dev_get_drvdata(dev);
>  
> - clk_disable_unprepare(ipu->clk);
> + clk_unprepare(ipu->clk);
>  }
>  
>  static const struct component_ops ingenic_ipu_ops = {
> -- 
> 2.27.0
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v5 0/6] Add support for GPU DDR BW scaling

2020-07-30 Thread Rob Clark
On Wed, Jul 29, 2020 at 10:10 PM Viresh Kumar  wrote:
>
> On 22-07-20, 11:00, Viresh Kumar wrote:
> > On 21-07-20, 07:28, Rob Clark wrote:
> > > With your ack, I can add the patch the dev_pm_opp_set_bw patch to my
> > > tree and merge it via msm-next -> drm-next -> linus
> >
> > I wanted to send it via my tree, but its okay. Pick this patch from
> > linux-next and add my Ack, I will drop it after that.
> >
> > a8351c12c6c7 OPP: Add and export helper to set bandwidth
>
> Oops, sorry for the trouble but this needs to go via my tree only :(
>
> I maintain two different branches, one for OPP and another one for
> cpufreq. There was no dependency within the OPP branch and so I
> dropped it that day and asked you to take it.
>
> But when I tried to send a pull request today I realised that one of
> the qcom patches in the cpufreq branch is dependent on it and I need
> to keep this patch in my tree.

Hmm, I've already sent my pull request to Dave, dropping the patch
would require force-push and sending a new PR.  Which I can do if Dave
prefers.  OTOH I guess it isn't the end of the world if the patch is
merged via two different trees.

BR,
-R
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [pull] amdgpu drm-fixes-5.8

2020-07-30 Thread Alex Deucher
On Wed, Jul 29, 2020 at 11:36 PM Alex Deucher  wrote:
>
> Hi Dave, Daniel,
>
> A few fixes for 5.8.  It would be nice to get these in for 5.8 final, but if
> it's too late, they can go back via stable from 5.9.

Ignore this one.  The NULL pointer regression fix didn't fully fix the
issue, so I'm going to send a new PR with a revert of the original
patch.

Sorry for the confusion.

Alex

>
> The following changes since commit a4a2739beb8933a19281bca077fdb852598803ed:
>
>   Merge tag 'drm-misc-fixes-2020-07-28' of 
> git://anongit.freedesktop.org/drm/drm-misc into drm-fixes (2020-07-29 
> 12:46:58 +1000)
>
> are available in the Git repository at:
>
>   git://people.freedesktop.org/~agd5f/linux tags/amd-drm-fixes-5.8-2020-07-29
>
> for you to fetch changes up to a4f8b953a42ef6f3655dcf83d560528b9f4162dc:
>
>   drm/amd/display: Clear dm_state for fast updates (2020-07-29 23:17:23 -0400)
>
> 
> amd-drm-fixes-5.8-2020-07-29:
>
> amdgpu:
> - Fix a regression caused by a NULL pointer fix
> - Fix potential kernel info leak
> - Fix a use-after-free bug that was uncovered by another change in 5.7
>
> 
> Mazin Rezk (1):
>   drm/amd/display: Clear dm_state for fast updates
>
> Paweł Gronowski (1):
>   drm/amdgpu: Fix regression in adjusting power table/profile
>
> Peilin Ye (1):
>   drm/amdgpu: Prevent kernel-infoleak in amdgpu_info_ioctl()
>
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  3 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c|  9 --
>  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 
> +--
>  3 files changed, 36 insertions(+), 12 deletions(-)
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 7/9] drm/ast: Managed release of ast firmware

2020-07-30 Thread Thomas Zimmermann
The ast driver loads firmware for the DP501 display encoder. The
patch replaces the removal code with a managed release function.

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
Acked-by: Sam Ravnborg 
---
 drivers/gpu/drm/ast/ast_dp501.c | 23 ++-
 drivers/gpu/drm/ast/ast_drv.h   |  1 -
 drivers/gpu/drm/ast/ast_main.c  |  3 ---
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_dp501.c b/drivers/gpu/drm/ast/ast_dp501.c
index 4b85a504825a..88121c0e0d05 100644
--- a/drivers/gpu/drm/ast/ast_dp501.c
+++ b/drivers/gpu/drm/ast/ast_dp501.c
@@ -8,11 +8,24 @@
 
 MODULE_FIRMWARE("ast_dp501_fw.bin");
 
+static void ast_release_firmware(void *data)
+{
+   struct ast_private *ast = data;
+
+   release_firmware(ast->dp501_fw);
+   ast->dp501_fw = NULL;
+}
+
 static int ast_load_dp501_microcode(struct drm_device *dev)
 {
struct ast_private *ast = to_ast_private(dev);
+   int ret;
+
+   ret = request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
+   if (ret)
+   return ret;
 
-   return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
+   return devm_add_action_or_reset(dev->dev, ast_release_firmware, ast);
 }
 
 static void send_ack(struct ast_private *ast)
@@ -435,11 +448,3 @@ void ast_init_3rdtx(struct drm_device *dev)
}
}
 }
-
-void ast_release_firmware(struct drm_device *dev)
-{
-   struct ast_private *ast = to_ast_private(dev);
-
-   release_firmware(ast->dp501_fw);
-   ast->dp501_fw = NULL;
-}
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index acd9bbfec98e..af26483106bd 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -312,7 +312,6 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
size);
 bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata);
 u8 ast_get_dp501_max_clk(struct drm_device *dev);
 void ast_init_3rdtx(struct drm_device *dev);
-void ast_release_firmware(struct drm_device *dev);
 
 /* ast_cursor.c */
 int ast_cursor_init(struct ast_private *ast);
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 792fb7f616ec..e3b7748335a3 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -442,11 +442,8 @@ struct ast_private *ast_device_create(struct drm_driver 
*drv,
 
 void ast_device_destroy(struct ast_private *ast)
 {
-   struct drm_device *dev = >base;
-
/* enable standard VGA decode */
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
 
-   ast_release_firmware(dev);
kfree(ast->dp501_fw_addr);
 }
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 9/9] drm/ast: Managed device release

2020-07-30 Thread Thomas Zimmermann
This turns the ast's device cleanup code into a managed release helper
function. Note that the code uses devres helpers. The release function
switches the device back to VGA mode and therefore runs during HW device
cleanup; not at DRM device cleanup.

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
---
 drivers/gpu/drm/ast/ast_drv.c  | 17 +++--
 drivers/gpu/drm/ast/ast_drv.h  |  1 -
 drivers/gpu/drm/ast/ast_main.c | 22 --
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index c394383a7979..f0b4af1c390a 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -120,35 +120,24 @@ static int ast_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
return ret;
 
ast = ast_device_create(_driver, pdev, ent->driver_data);
-   if (IS_ERR(ast)) {
-   ret = PTR_ERR(ast);
-   goto err_drm_dev_put;
-   }
+   if (IS_ERR(ast))
+   return PTR_ERR(ast);
dev = >base;
 
ret = drm_dev_register(dev, ent->driver_data);
if (ret)
-   goto err_ast_device_destroy;
+   return ret;
 
drm_fbdev_generic_setup(dev, 32);
 
return 0;
-
-err_ast_device_destroy:
-   ast_device_destroy(ast);
-err_drm_dev_put:
-   drm_dev_put(dev);
-   return ret;
 }
 
 static void ast_pci_remove(struct pci_dev *pdev)
 {
struct drm_device *dev = pci_get_drvdata(pdev);
-   struct ast_private *ast = to_ast_private(dev);
 
drm_dev_unregister(dev);
-   ast_device_destroy(ast);
-   drm_dev_put(dev);
 }
 
 static int ast_drm_freeze(struct drm_device *dev)
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index af26483106bd..c1af6b725933 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -162,7 +162,6 @@ static inline struct ast_private *to_ast_private(struct 
drm_device *dev)
 struct ast_private *ast_device_create(struct drm_driver *drv,
  struct pci_dev *pdev,
  unsigned long flags);
-void ast_device_destroy(struct ast_private *ast);
 
 #define AST_IO_AR_PORT_WRITE   (0x40)
 #define AST_IO_MISC_PORT_WRITE (0x42)
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 67e20727d82d..d62749a10cdd 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -380,6 +380,18 @@ static int ast_get_dram_info(struct drm_device *dev)
return 0;
 }
 
+/*
+ * Run this function as part of the HW device cleanup; not
+ * when the DRM device gets released.
+ */
+static void ast_device_release(void *data)
+{
+   struct ast_private *ast = data;
+
+   /* enable standard VGA decode */
+   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
+}
+
 struct ast_private *ast_device_create(struct drm_driver *drv,
  struct pci_dev *pdev,
  unsigned long flags)
@@ -438,11 +450,9 @@ struct ast_private *ast_device_create(struct drm_driver 
*drv,
if (ret)
return ERR_PTR(ret);
 
-   return ast;
-}
+   ret = devm_add_action_or_reset(dev->dev, ast_device_release, ast);
+   if (ret)
+   return ERR_PTR(ret);
 
-void ast_device_destroy(struct ast_private *ast)
-{
-   /* enable standard VGA decode */
-   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
+   return ast;
 }
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 3/9] drm/ast: Replace driver load/unload functions with device create/destroy

2020-07-30 Thread Thomas Zimmermann
The ast driver's load and unload functions are left-overs from when
struct drm_driver.load/unload was still in use. The PCI probe helper
allocated the DRM device and ran load to initialize it.

This patch replaces this code with device create and destroy. The
main difference is that the device's create function allocates the
DRM device and ast structures in the same place. This will be required
for switching ast to managed allocations.

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
Acked-by: Sam Ravnborg 
---
 drivers/gpu/drm/ast/ast_drv.c  | 24 +++-
 drivers/gpu/drm/ast/ast_drv.h  |  6 --
 drivers/gpu/drm/ast/ast_main.c | 24 ++--
 3 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index 9d04f2b5225c..ad93c35b4cf7 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -109,6 +109,7 @@ static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
 
 static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
+   struct ast_private *ast;
struct drm_device *dev;
int ret;
 
@@ -118,27 +119,23 @@ static int ast_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
if (ret)
return ret;
 
-   dev = drm_dev_alloc(_driver, >dev);
-   if (IS_ERR(dev))
-   return  PTR_ERR(dev);
-
-   dev->pdev = pdev;
-   pci_set_drvdata(pdev, dev);
-
-   ret = ast_driver_load(dev, ent->driver_data);
-   if (ret)
+   ast = ast_device_create(_driver, pdev, ent->driver_data);
+   if (IS_ERR(ast)) {
+   ret = PTR_ERR(ast);
goto err_drm_dev_put;
+   }
+   dev = ast->dev;
 
ret = drm_dev_register(dev, ent->driver_data);
if (ret)
-   goto err_ast_driver_unload;
+   goto err_ast_device_destroy;
 
drm_fbdev_generic_setup(dev, 32);
 
return 0;
 
-err_ast_driver_unload:
-   ast_driver_unload(dev);
+err_ast_device_destroy:
+   ast_device_destroy(ast);
 err_drm_dev_put:
drm_dev_put(dev);
return ret;
@@ -147,9 +144,10 @@ static int ast_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
 static void ast_pci_remove(struct pci_dev *pdev)
 {
struct drm_device *dev = pci_get_drvdata(pdev);
+   struct ast_private *ast = to_ast_private(dev);
 
drm_dev_unregister(dev);
-   ast_driver_unload(dev);
+   ast_device_destroy(ast);
drm_dev_put(dev);
 }
 
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index e7564055fa70..210d62f69fb9 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -159,8 +159,10 @@ static inline struct ast_private *to_ast_private(struct 
drm_device *dev)
return dev->dev_private;
 }
 
-int ast_driver_load(struct drm_device *dev, unsigned long flags);
-void ast_driver_unload(struct drm_device *dev);
+struct ast_private *ast_device_create(struct drm_driver *drv,
+ struct pci_dev *pdev,
+ unsigned long flags);
+void ast_device_destroy(struct ast_private *ast);
 
 #define AST_IO_AR_PORT_WRITE   (0x40)
 #define AST_IO_MISC_PORT_WRITE (0x42)
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index dd12b55d57a2..8d46166f8462 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -30,6 +30,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -378,15 +379,25 @@ static int ast_get_dram_info(struct drm_device *dev)
return 0;
 }
 
-int ast_driver_load(struct drm_device *dev, unsigned long flags)
+struct ast_private *ast_device_create(struct drm_driver *drv,
+ struct pci_dev *pdev,
+ unsigned long flags)
 {
+   struct drm_device *dev;
struct ast_private *ast;
bool need_post;
int ret = 0;
 
+   dev = drm_dev_alloc(drv, >dev);
+   if (IS_ERR(dev))
+   return ERR_CAST(dev);
+
+   dev->pdev = pdev;
+   pci_set_drvdata(pdev, dev);
+
ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL);
if (!ast)
-   return -ENOMEM;
+   return ERR_PTR(-ENOMEM);
 
dev->dev_private = ast;
ast->dev = dev;
@@ -435,16 +446,17 @@ int ast_driver_load(struct drm_device *dev, unsigned long 
flags)
if (ret)
goto out_free;
 
-   return 0;
+   return ast;
+
 out_free:
kfree(ast);
dev->dev_private = NULL;
-   return ret;
+   return ERR_PTR(ret);
 }
 
-void ast_driver_unload(struct drm_device *dev)
+void ast_device_destroy(struct ast_private *ast)
 {
-   struct ast_private *ast = to_ast_private(dev);
+   struct drm_device *dev = ast->dev;
 
/* enable standard VGA decode */
 

[PATCH v2 8/9] drm/ast: Manage release of firmware backup memory

2020-07-30 Thread Thomas Zimmermann
The ast driver keeps a backup copy of the DP501 encoder's firmware. This
patch adds managed release of the allocated memory.

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
---
 drivers/gpu/drm/ast/ast_main.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index e3b7748335a3..67e20727d82d 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ast_drv.h"
 
@@ -231,11 +232,11 @@ static int ast_detect_chip(struct drm_device *dev, bool 
*need_post)
ast->tx_chip_type = AST_TX_SIL164;
break;
case 0x08:
-   ast->dp501_fw_addr = kzalloc(32*1024, GFP_KERNEL);
+   ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, 
GFP_KERNEL);
if (ast->dp501_fw_addr) {
/* backup firmware */
if (ast_backup_fw(dev, ast->dp501_fw_addr, 
32*1024)) {
-   kfree(ast->dp501_fw_addr);
+   drmm_kfree(dev, ast->dp501_fw_addr);
ast->dp501_fw_addr = NULL;
}
}
@@ -444,6 +445,4 @@ void ast_device_destroy(struct ast_private *ast)
 {
/* enable standard VGA decode */
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
-
-   kfree(ast->dp501_fw_addr);
 }
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 4/9] drm/ast: Replace struct_drm_device.dev_private with to_ast_private()

2020-07-30 Thread Thomas Zimmermann
The ast code still references dev_private in several place when looking
up the ast device structure. Convert the remaining locations to use
to_ast_private().

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
Acked-by: Sam Ravnborg 
---
 drivers/gpu/drm/ast/ast_cursor.c | 2 +-
 drivers/gpu/drm/ast/ast_mode.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_cursor.c b/drivers/gpu/drm/ast/ast_cursor.c
index acf0d23514e8..8d693c8b346f 100644
--- a/drivers/gpu/drm/ast/ast_cursor.c
+++ b/drivers/gpu/drm/ast/ast_cursor.c
@@ -47,7 +47,7 @@ static void ast_cursor_fini(struct ast_private *ast)
 
 static void ast_cursor_release(struct drm_device *dev, void *ptr)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
 
ast_cursor_fini(ast);
 }
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 78f28a4e6ed8..cdbdf3489dee 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -663,7 +663,7 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane 
*plane,
 {
struct drm_plane_state *state = plane->state;
struct drm_framebuffer *fb = state->fb;
-   struct ast_private *ast = plane->dev->dev_private;
+   struct ast_private *ast = to_ast_private(plane->dev);
unsigned int offset_x, offset_y;
 
offset_x = AST_MAX_HWC_WIDTH - fb->width;
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 6/9] drm/ast: Embed struct drm_device in struct ast_private

2020-07-30 Thread Thomas Zimmermann
Turns struct ast_private into a subclass of struct drm_device by
embedding the latter. This allows for using DRM's managed device
allocation.

The use of struct drm_device.dev_private is deprecated. The patch
converts the last remaining users to to_ast_private().

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
Acked-by: Sam Ravnborg 
---
 drivers/gpu/drm/ast/ast_cursor.c |  6 ++---
 drivers/gpu/drm/ast/ast_drv.c|  2 +-
 drivers/gpu/drm/ast/ast_drv.h|  4 +--
 drivers/gpu/drm/ast/ast_main.c   | 42 ++--
 drivers/gpu/drm/ast/ast_mm.c |  2 +-
 drivers/gpu/drm/ast/ast_mode.c   |  2 +-
 drivers/gpu/drm/ast/ast_post.c   |  2 +-
 7 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_cursor.c b/drivers/gpu/drm/ast/ast_cursor.c
index 8d693c8b346f..6c96f74cdb9e 100644
--- a/drivers/gpu/drm/ast/ast_cursor.c
+++ b/drivers/gpu/drm/ast/ast_cursor.c
@@ -57,7 +57,7 @@ static void ast_cursor_release(struct drm_device *dev, void 
*ptr)
  */
 int ast_cursor_init(struct ast_private *ast)
 {
-   struct drm_device *dev = ast->dev;
+   struct drm_device *dev = >base;
size_t size, i;
struct drm_gem_vram_object *gbo;
void __iomem *vaddr;
@@ -168,7 +168,7 @@ static void update_cursor_image(u8 __iomem *dst, const u8 
*src, int width, int h
 
 int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)
 {
-   struct drm_device *dev = ast->dev;
+   struct drm_device *dev = >base;
struct drm_gem_vram_object *gbo;
int ret;
void *src;
@@ -217,7 +217,7 @@ static void ast_cursor_set_base(struct ast_private *ast, 
u64 address)
 
 void ast_cursor_page_flip(struct ast_private *ast)
 {
-   struct drm_device *dev = ast->dev;
+   struct drm_device *dev = >base;
struct drm_gem_vram_object *gbo;
s64 off;
 
diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index ad93c35b4cf7..c394383a7979 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -124,7 +124,7 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
ret = PTR_ERR(ast);
goto err_drm_dev_put;
}
-   dev = ast->dev;
+   dev = >base;
 
ret = drm_dev_register(dev, ent->driver_data);
if (ret)
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index 210d62f69fb9..acd9bbfec98e 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -116,7 +116,7 @@ to_ast_connector(struct drm_connector *connector)
 }
 
 struct ast_private {
-   struct drm_device *dev;
+   struct drm_device base;
 
void __iomem *regs;
void __iomem *ioregs;
@@ -156,7 +156,7 @@ struct ast_private {
 
 static inline struct ast_private *to_ast_private(struct drm_device *dev)
 {
-   return dev->dev_private;
+   return container_of(dev, struct ast_private, base);
 }
 
 struct ast_private *ast_device_create(struct drm_driver *drv,
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 8d46166f8462..792fb7f616ec 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -388,25 +388,17 @@ struct ast_private *ast_device_create(struct drm_driver 
*drv,
bool need_post;
int ret = 0;
 
-   dev = drm_dev_alloc(drv, >dev);
-   if (IS_ERR(dev))
-   return ERR_CAST(dev);
+   ast = devm_drm_dev_alloc(>dev, drv, struct ast_private, base);
+   if (IS_ERR(ast))
+   return ast;
+   dev = >base;
 
dev->pdev = pdev;
pci_set_drvdata(pdev, dev);
 
-   ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL);
-   if (!ast)
-   return ERR_PTR(-ENOMEM);
-
-   dev->dev_private = ast;
-   ast->dev = dev;
-
ast->regs = pci_iomap(dev->pdev, 1, 0);
-   if (!ast->regs) {
-   ret = -EIO;
-   goto out_free;
-   }
+   if (!ast->regs)
+   return ERR_PTR(-EIO);
 
/*
 * If we don't have IO space at all, use MMIO now and
@@ -421,17 +413,16 @@ struct ast_private *ast_device_create(struct drm_driver 
*drv,
/* "map" IO regs if the above hasn't done so already */
if (!ast->ioregs) {
ast->ioregs = pci_iomap(dev->pdev, 2, 0);
-   if (!ast->ioregs) {
-   ret = -EIO;
-   goto out_free;
-   }
+   if (!ast->ioregs)
+   return ERR_PTR(-EIO);
}
 
ast_detect_chip(dev, _post);
 
ret = ast_get_dram_info(dev);
if (ret)
-   goto out_free;
+   return ERR_PTR(ret);
+
drm_info(dev, "dram MCLK=%u Mhz type=%d bus_width=%d\n",
 ast->mclk, ast->dram_type, ast->dram_bus_width);
 
@@ -440,29 +431,22 @@ struct ast_private *ast_device_create(struct drm_driver 
*drv,
 

[PATCH v2 2/9] drm/ast: Separate DRM driver from PCI code

2020-07-30 Thread Thomas Zimmermann
Putting the DRM driver to the top of the file and the PCI code to the
bottom makes ast_drv.c more readable. While at it, the patch prefixes
file-scope variables with ast_.

Signed-off-by: Thomas Zimmermann 
Acked-by: Daniel Vetter 
Acked-by: Sam Ravnborg 
---
 drivers/gpu/drm/ast/ast_drv.c | 59 ++-
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index 0b58f7aee6b0..9d04f2b5225c 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -43,9 +43,33 @@ int ast_modeset = -1;
 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
 module_param_named(modeset, ast_modeset, int, 0400);
 
-#define PCI_VENDOR_ASPEED 0x1a03
+/*
+ * DRM driver
+ */
+
+DEFINE_DRM_GEM_FOPS(ast_fops);
+
+static struct drm_driver ast_driver = {
+   .driver_features = DRIVER_ATOMIC |
+  DRIVER_GEM |
+  DRIVER_MODESET,
+
+   .fops = _fops,
+   .name = DRIVER_NAME,
+   .desc = DRIVER_DESC,
+   .date = DRIVER_DATE,
+   .major = DRIVER_MAJOR,
+   .minor = DRIVER_MINOR,
+   .patchlevel = DRIVER_PATCHLEVEL,
 
-static struct drm_driver driver;
+   DRM_GEM_VRAM_DRIVER
+};
+
+/*
+ * PCI driver
+ */
+
+#define PCI_VENDOR_ASPEED 0x1a03
 
 #define AST_VGA_DEVICE(id, info) { \
.class = PCI_BASE_CLASS_DISPLAY << 16,  \
@@ -56,13 +80,13 @@ static struct drm_driver driver;
.subdevice = PCI_ANY_ID,\
.driver_data = (unsigned long) info }
 
-static const struct pci_device_id pciidlist[] = {
+static const struct pci_device_id ast_pciidlist[] = {
AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL),
AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL),
{0, 0, 0},
 };
 
-MODULE_DEVICE_TABLE(pci, pciidlist);
+MODULE_DEVICE_TABLE(pci, ast_pciidlist);
 
 static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
 {
@@ -94,7 +118,7 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (ret)
return ret;
 
-   dev = drm_dev_alloc(, >dev);
+   dev = drm_dev_alloc(_driver, >dev);
if (IS_ERR(dev))
return  PTR_ERR(dev);
 
@@ -118,11 +142,9 @@ static int ast_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
 err_drm_dev_put:
drm_dev_put(dev);
return ret;
-
 }
 
-static void
-ast_pci_remove(struct pci_dev *pdev)
+static void ast_pci_remove(struct pci_dev *pdev)
 {
struct drm_device *dev = pci_get_drvdata(pdev);
 
@@ -217,30 +239,12 @@ static const struct dev_pm_ops ast_pm_ops = {
 
 static struct pci_driver ast_pci_driver = {
.name = DRIVER_NAME,
-   .id_table = pciidlist,
+   .id_table = ast_pciidlist,
.probe = ast_pci_probe,
.remove = ast_pci_remove,
.driver.pm = _pm_ops,
 };
 
-DEFINE_DRM_GEM_FOPS(ast_fops);
-
-static struct drm_driver driver = {
-   .driver_features = DRIVER_ATOMIC |
-  DRIVER_GEM |
-  DRIVER_MODESET,
-
-   .fops = _fops,
-   .name = DRIVER_NAME,
-   .desc = DRIVER_DESC,
-   .date = DRIVER_DATE,
-   .major = DRIVER_MAJOR,
-   .minor = DRIVER_MINOR,
-   .patchlevel = DRIVER_PATCHLEVEL,
-
-   DRM_GEM_VRAM_DRIVER
-};
-
 static int __init ast_init(void)
 {
if (vgacon_text_force() && ast_modeset == -1)
@@ -261,4 +265,3 @@ module_exit(ast_exit);
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL and additional rights");
-
-- 
2.27.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


  1   2   >