[PATCH] drm/amdgpu: fix suspend/resume hang regression

2022-02-28 Thread Qiang Yu
Regression has been reported that suspend/resume may hang with
the previous vm ready check commit:
https://gitlab.freedesktop.org/drm/amd/-/issues/1915#note_1278198

So bring back the evicted list check as a temp fix.

Fixes: cc8dd2cc1a97 ("drm/amdgpu: check vm ready by amdgpu_vm->evicting flag")
Signed-off-by: Qiang Yu 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 2cd9f1a2e5fa..fc4563cf2828 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -779,7 +779,8 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
amdgpu_vm_eviction_lock(vm);
ret = !vm->evicting;
amdgpu_vm_eviction_unlock(vm);
-   return ret;
+
+   return ret && list_empty(>evicted);
 }
 
 /**
-- 
2.25.1



Re: [PATCH v2] drm/amdgpu: check vm ready by amdgpu_vm->evicting flag

2022-02-22 Thread Qiang Yu
On Wed, Feb 23, 2022 at 3:47 PM Paul Menzel  wrote:
>
> Dear Qiang,
>
>
> Am 22.02.22 um 03:46 schrieb Qiang Yu:
> > Workstation application ANSA/META v21.1.4 get this error dmesg when
> > running CI test suite provided by ANSA/META:
> > [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)
> >
> > This is caused by:
> > 1. create a 256MB buffer in invisible VRAM
> > 2. CPU map the buffer and access it causes vm_fault and try to move
> > it to visible VRAM
> > 3. force visible VRAM space and traverse all VRAM bos to check if
> > evicting this bo is valuable
> > 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> > will set amdgpu_vm->evicting, but latter due to not in visible
> > VRAM, won't really evict it so not add it to amdgpu_vm->evicted
> > 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> > ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> > but fail in amdgpu_vm_bo_update_mapping() (check
> > amdgpu_vm->evicting) and get this error log
> >
> > This error won't affect functionality as next CS will finish the
> > waiting VM ops. But we'd better clear the error log by checking
> > the amdgpu_vm->evicting flag in amdgpu_vm_ready() to stop calling
> > amdgpu_vm_bo_update_mapping() latter.
>
> later
> > Another reason is amdgpu_vm->evicted list holds all BOs (both
> > user buffer and page table), but only page table BOs' eviction
> > prevent VM ops. amdgpu_vm->evicting flag is set only for page
> > table BOs, so we should use evicting flag instead of evicted list
> > in amdgpu_vm_ready().
> >
> > The side effect of This change is: previously blocked VM op (user
>
> this
>
> > buffer in "evicted" list but no page table in it) gets done
> > immediately.
> >
> > v2: update commit comments.
> >
> > Reviewed-by: Christian König 
> > Signed-off-by: Qiang Yu 
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++--
> >   1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > index 37acd8911168..2cd9f1a2e5fa 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > @@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device 
> > *adev, struct amdgpu_vm *vm,
> >* Check if all VM PDs/PTs are ready for updates
> >*
> >* Returns:
> > - * True if eviction list is empty.
> > + * True if VM is not evicting.
> >*/
> >   bool amdgpu_vm_ready(struct amdgpu_vm *vm)
> >   {
> > - return list_empty(>evicted);
> > + bool ret;
> > +
> > + amdgpu_vm_eviction_lock(vm);
> > + ret = !vm->evicting;
> > + amdgpu_vm_eviction_unlock(vm);
> > + return ret;
> >   }
> >
> >   /**
>
> Acked-by: Paul Menzel 
>
Thanks, will submit with the typo fixed.

Regards,
Qiang

>
> Kind regards,
>
> Paul


[PATCH v2] drm/amdgpu: check vm ready by amdgpu_vm->evicting flag

2022-02-21 Thread Qiang Yu
Workstation application ANSA/META v21.1.4 get this error dmesg when
running CI test suite provided by ANSA/META:
[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move
   it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if
   evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
   will set amdgpu_vm->evicting, but latter due to not in visible
   VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops
   ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
   but fail in amdgpu_vm_bo_update_mapping() (check
   amdgpu_vm->evicting) and get this error log

This error won't affect functionality as next CS will finish the
waiting VM ops. But we'd better clear the error log by checking
the amdgpu_vm->evicting flag in amdgpu_vm_ready() to stop calling
amdgpu_vm_bo_update_mapping() latter.

Another reason is amdgpu_vm->evicted list holds all BOs (both
user buffer and page table), but only page table BOs' eviction
prevent VM ops. amdgpu_vm->evicting flag is set only for page
table BOs, so we should use evicting flag instead of evicted list
in amdgpu_vm_ready().

The side effect of This change is: previously blocked VM op (user
buffer in "evicted" list but no page table in it) gets done
immediately.

v2: update commit comments.

Reviewed-by: Christian König 
Signed-off-by: Qiang Yu 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 37acd8911168..2cd9f1a2e5fa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, 
struct amdgpu_vm *vm,
  * Check if all VM PDs/PTs are ready for updates
  *
  * Returns:
- * True if eviction list is empty.
+ * True if VM is not evicting.
  */
 bool amdgpu_vm_ready(struct amdgpu_vm *vm)
 {
-   return list_empty(>evicted);
+   bool ret;
+
+   amdgpu_vm_eviction_lock(vm);
+   ret = !vm->evicting;
+   amdgpu_vm_eviction_unlock(vm);
+   return ret;
 }
 
 /**
-- 
2.25.1



[PATCH] drm/amdgpu: check vm ready by evicting

2022-02-21 Thread Qiang Yu
Workstation application ANSA/META get this error dmesg:
[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move
   it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if
   evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
   will set amdgpu_vm->evicting, but latter due to not in visible
   VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops
   ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
   but fail in amdgpu_vm_bo_update_mapping() (check
   amdgpu_vm->evicting) and get this error log

This error won't affect functionality as next CS will finish the
waiting VM ops. But we'd better clear the error log by check the
evicting flag which really stop VM ops latter.

Signed-off-by: Qiang Yu 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 37acd8911168..2cd9f1a2e5fa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -770,11 +770,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, 
struct amdgpu_vm *vm,
  * Check if all VM PDs/PTs are ready for updates
  *
  * Returns:
- * True if eviction list is empty.
+ * True if VM is not evicting.
  */
 bool amdgpu_vm_ready(struct amdgpu_vm *vm)
 {
-   return list_empty(>evicted);
+   bool ret;
+
+   amdgpu_vm_eviction_lock(vm);
+   ret = !vm->evicting;
+   amdgpu_vm_eviction_unlock(vm);
+   return ret;
 }
 
 /**
-- 
2.25.1



Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-20 Thread Qiang Yu
On Fri, Feb 18, 2022 at 6:24 PM Christian König
 wrote:
>
> Am 18.02.22 um 11:16 schrieb Qiang Yu:
> > [SNIP]
> >>> If amdgpu_vm_ready() use evicting flag, it's still not equivalent to check
> >>> vm idle: true -> vm idle, false -> vm may be idle or busy.
> >> Yeah, but why should that be relevant?
> >>
> >> The amdgpu_vm_ready() return if we can do page table updates or not. If
> >> the VM is idle or not is only relevant for eviction.
> >>
> >> In other words any CS or page table update makes the VM busy, but that
> >> only affects if the VM can be evicted or not.
> >>
> > My point is: we can't use amdgpu_vm_ready() to replace vm_is_busy(), so
> > currently we update vm even when vm is busy. So why not use:
Sorry, should be "vm is idle".

> > if (!amdgpu_vm_ready() || vm_is_busy()) return;
> > in amdgpu_gem_va_update_vm(), as you mentioned we prefer to not
> > update vm when it's idle.
>
> Because updating the VM while it is busy is perfectly fine, we do it all
> the time.
>
Yeah, as above, my typo.

> We should just not update it when it is already idle and was considered
> for eviction.
"and", not "or"?

> In this situation it makes most of the time sense to keep
> it idle and postpone the update till the next command submission.
>
> >>>>> Then we can keep the evicting flag accurate (after solving your
> >>>>> concern for this patch that eviction may fail latter by further delay
> >>>>> the flag update after eviction success).
> >>>> That won't work. See we need to mark the VM as evicted before we
> >>>> actually evict them because otherwise somebody could use the VM in
> >>>> parallel and add another fence to it.
> >>>>
> >>> I see, make this too accurate should cost too much like holding the
> >>> eviction_lock when eviction. But just delay it in
> >>> amdgpu_ttm_bo_eviction_valuable()
> >>> could avoid most false positive case.
> >> Partially correct. Another fundamental problem is that we can't hold the
> >> eviction lock because that would result in lock inversion and potential
> >> deadlock.
> >>
> >> We could set the flag later on, but as I said before that when we set
> >> the evicted flag when the VM is already idle is a desired effect.
> >>
> > As above, this confuse me as we can explicitly check vm idle when
> > user update vm, why bother to embed it in evicting flag implicitly?
>
> Well as I said it's irrelevant for the update if the VM is idle or not.
>
> To summarize the rules once more:
> 1. When VM page tables are used by CS or page tables updates it is
> considered busy, e.g. not idle.
>
> 2. When we want to evict a VM it must be idle. As soon as we considered
> this we should set the evicted flag to make sure to keep it idle as much
> as possible.
>
> 3. When we want to update the page tables we just need to check if the
> VM is idle or not.
>
But now we does not check vm idle directly in amdgpu_gem_va_update_vm().
If VM bo has not been considered for eviction, it could be either idle or busy.

Just want to confirm if the fix should be only change amdgpu_vm_ready()
to use evicting flag or besides using evicting flag, also check vm_idle() in
amdgpu_gem_va_update_vm().

Regards,
Qiang

> 4. When a CS happens we don't have another chance and make the VM busy
> again. And do all postponed page table updates.
>
Anyway,

> Regards,
> Christian.
>
> >
> > Check vm idle need to hold resv lock. Read your patch for adding
> > evicting flag is to update vm without resv lock. But user vm ops in
> > amdgpu_gem_va_update_vm() do hold the resv lock, so the difference
> > happens when calling amdgpu_vm_bo_update_mapping() from
> > svm_range_(un)map_to_gpu(). So embed vm idle in evicting flag
> > is for svm_range_(un)map_to_gpu() also do nothing when vm idle?
>
>
>
> >
> > Regards,
> > Qiang
> >
> >> Regards,
> >> Christian.
> >>
> >>> Regards,
> >>> Qiang
> >>>
> >>>> Regards,
> >>>> Christian.
> >>>>
> >>>>> Regards,
> >>>>> Qiang
> >>>>>
> >>>>>
> >>>>>> Regards,
> >>>>>> Christian.
> >>>>>>
> >>>>>>> Regards,
> >>>>>>> Qiang
> >>>>>>>
> >>>>>>>> Regards,
> >>>>>&g

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-18 Thread Qiang Yu
On Fri, Feb 18, 2022 at 5:27 PM Christian König
 wrote:
>
> Am 18.02.22 um 09:58 schrieb Qiang Yu:
> > On Fri, Feb 18, 2022 at 3:46 PM Christian König
> >  wrote:
> >> Am 18.02.22 um 04:08 schrieb Qiang Yu:
> >>> On Thu, Feb 17, 2022 at 8:22 PM Christian König
> >>>  wrote:
> >>>> Am 17.02.22 um 11:58 schrieb Qiang Yu:
> >>>>> On Thu, Feb 17, 2022 at 6:39 PM Christian König
> >>>>>  wrote:
> >>>>>> Am 17.02.22 um 11:13 schrieb Qiang Yu:
> >>>>>>> On Thu, Feb 17, 2022 at 5:46 PM Christian König
> >>>>>>>  wrote:
> >>>>>>>> Am 17.02.22 um 10:40 schrieb Qiang Yu:
> >>>>>>>>> On Thu, Feb 17, 2022 at 5:15 PM Christian König
> >>>>>>>>>  wrote:
> >>>>>>>>>> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> >>>>>>>>>>> Workstation application ANSA/META get this error dmesg:
> >>>>>>>>>>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA 
> >>>>>>>>>>> (-16)
> >>>>>>>>>>>
> >>>>>>>>>>> This is caused by:
> >>>>>>>>>>> 1. create a 256MB buffer in invisible VRAM
> >>>>>>>>>>> 2. CPU map the buffer and access it causes vm_fault and try to 
> >>>>>>>>>>> move
> >>>>>>>>>>>  it to visible VRAM
> >>>>>>>>>>> 3. force visible VRAM space and traverse all VRAM bos to check if
> >>>>>>>>>>>  evicting this bo is valuable
> >>>>>>>>>>> 4. when checking a VM bo (in invisible VRAM), 
> >>>>>>>>>>> amdgpu_vm_evictable()
> >>>>>>>>>>>  will set amdgpu_vm->evicting, but latter due to not in 
> >>>>>>>>>>> visible
> >>>>>>>>>>>  VRAM, won't really evict it so not add it to 
> >>>>>>>>>>> amdgpu_vm->evicted
> >>>>>>>>>>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> >>>>>>>>>>>  ioctl will pass amdgpu_vm_ready() (check 
> >>>>>>>>>>> amdgpu_vm->evicted)
> >>>>>>>>>>>  but fail in amdgpu_vm_bo_update_mapping() (check
> >>>>>>>>>>>  amdgpu_vm->evicting) and get this error log
> >>>>>>>>>>>
> >>>>>>>>>>> This error won't affect functionality as next CS will finish the
> >>>>>>>>>>> waiting VM ops. But we'd better make the amdgpu_vm->evicting
> >>>>>>>>>>> correctly reflact the vm status and clear the error log.
> >>>>>>>>>> Well NAK, that is intentional behavior.
> >>>>>>>>>>
> >>>>>>>>>> The VM page tables where considered for eviction, so setting the 
> >>>>>>>>>> flag is
> >>>>>>>>>> correct even when the page tables later on are not actually 
> >>>>>>>>>> evicted.
> >>>>>>>>>>
> >>>>>>>>> But this will unnecessarily stop latter user VM ops in ioctl before 
> >>>>>>>>> CS
> >>>>>>>>> even when the VM bos are not evicted.
> >>>>>>>>> Won't this have any negative effect when could do better?
> >>>>>>>> No, this will have a positive effect. See the VM was already 
> >>>>>>>> considered
> >>>>>>>> for eviction because it is idle.
> >>>>>>>>
> >>>>>>>> Updating it immediately doesn't necessarily make sense, we should 
> >>>>>>>> wait
> >>>>>>>> with that until its next usage.
> >>>>>>>>
> >>>>>>>> Additional to that this patch doesn't really fix the problem, it just
> >>>>>>>> mitigates it.
> >>>>>>>>
> >>>>>>>> Eviction can fail later on for a couple of reasons and 

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-18 Thread Qiang Yu
On Fri, Feb 18, 2022 at 3:46 PM Christian König
 wrote:
>
> Am 18.02.22 um 04:08 schrieb Qiang Yu:
> > On Thu, Feb 17, 2022 at 8:22 PM Christian König
> >  wrote:
> >> Am 17.02.22 um 11:58 schrieb Qiang Yu:
> >>> On Thu, Feb 17, 2022 at 6:39 PM Christian König
> >>>  wrote:
> >>>>
> >>>> Am 17.02.22 um 11:13 schrieb Qiang Yu:
> >>>>> On Thu, Feb 17, 2022 at 5:46 PM Christian König
> >>>>>  wrote:
> >>>>>> Am 17.02.22 um 10:40 schrieb Qiang Yu:
> >>>>>>> On Thu, Feb 17, 2022 at 5:15 PM Christian König
> >>>>>>>  wrote:
> >>>>>>>> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> >>>>>>>>> Workstation application ANSA/META get this error dmesg:
> >>>>>>>>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA 
> >>>>>>>>> (-16)
> >>>>>>>>>
> >>>>>>>>> This is caused by:
> >>>>>>>>> 1. create a 256MB buffer in invisible VRAM
> >>>>>>>>> 2. CPU map the buffer and access it causes vm_fault and try to move
> >>>>>>>>> it to visible VRAM
> >>>>>>>>> 3. force visible VRAM space and traverse all VRAM bos to check if
> >>>>>>>>> evicting this bo is valuable
> >>>>>>>>> 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> >>>>>>>>> will set amdgpu_vm->evicting, but latter due to not in 
> >>>>>>>>> visible
> >>>>>>>>> VRAM, won't really evict it so not add it to 
> >>>>>>>>> amdgpu_vm->evicted
> >>>>>>>>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> >>>>>>>>> ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> >>>>>>>>> but fail in amdgpu_vm_bo_update_mapping() (check
> >>>>>>>>> amdgpu_vm->evicting) and get this error log
> >>>>>>>>>
> >>>>>>>>> This error won't affect functionality as next CS will finish the
> >>>>>>>>> waiting VM ops. But we'd better make the amdgpu_vm->evicting
> >>>>>>>>> correctly reflact the vm status and clear the error log.
> >>>>>>>> Well NAK, that is intentional behavior.
> >>>>>>>>
> >>>>>>>> The VM page tables where considered for eviction, so setting the 
> >>>>>>>> flag is
> >>>>>>>> correct even when the page tables later on are not actually evicted.
> >>>>>>>>
> >>>>>>> But this will unnecessarily stop latter user VM ops in ioctl before CS
> >>>>>>> even when the VM bos are not evicted.
> >>>>>>> Won't this have any negative effect when could do better?
> >>>>>> No, this will have a positive effect. See the VM was already considered
> >>>>>> for eviction because it is idle.
> >>>>>>
> >>>>>> Updating it immediately doesn't necessarily make sense, we should wait
> >>>>>> with that until its next usage.
> >>>>>>
> >>>>>> Additional to that this patch doesn't really fix the problem, it just
> >>>>>> mitigates it.
> >>>>>>
> >>>>>> Eviction can fail later on for a couple of reasons and we absolutely
> >>>>>> need to check the flag instead of the list in amdgpu_vm_ready().
> >>>>> The flag only for both flag and list? Looks like should be both as
> >>>>> the list indicate some vm page table need to be updated and could
> >>>>> delay the user update with the same logic as you described above.
> >>>> I think checking the flag should be enough. The issue is that the list
> >>>> was there initially, but to avoid race conditions we added the flag with
> >>>> separate lock protection later on.
> >>>>
> >>> But list and flag does not align always, there are cases like
> >>> list-empty/flag-set (this problem) and list-non-empty/flag-unset (non-vm 
> >>> bo
> >

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-17 Thread Qiang Yu
On Thu, Feb 17, 2022 at 8:22 PM Christian König
 wrote:
>
> Am 17.02.22 um 11:58 schrieb Qiang Yu:
> > On Thu, Feb 17, 2022 at 6:39 PM Christian König
> >  wrote:
> >>
> >>
> >> Am 17.02.22 um 11:13 schrieb Qiang Yu:
> >>> On Thu, Feb 17, 2022 at 5:46 PM Christian König
> >>>  wrote:
> >>>> Am 17.02.22 um 10:40 schrieb Qiang Yu:
> >>>>> On Thu, Feb 17, 2022 at 5:15 PM Christian König
> >>>>>  wrote:
> >>>>>> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> >>>>>>> Workstation application ANSA/META get this error dmesg:
> >>>>>>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)
> >>>>>>>
> >>>>>>> This is caused by:
> >>>>>>> 1. create a 256MB buffer in invisible VRAM
> >>>>>>> 2. CPU map the buffer and access it causes vm_fault and try to move
> >>>>>>>it to visible VRAM
> >>>>>>> 3. force visible VRAM space and traverse all VRAM bos to check if
> >>>>>>>evicting this bo is valuable
> >>>>>>> 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> >>>>>>>will set amdgpu_vm->evicting, but latter due to not in visible
> >>>>>>>VRAM, won't really evict it so not add it to amdgpu_vm->evicted
> >>>>>>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> >>>>>>>ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> >>>>>>>but fail in amdgpu_vm_bo_update_mapping() (check
> >>>>>>>amdgpu_vm->evicting) and get this error log
> >>>>>>>
> >>>>>>> This error won't affect functionality as next CS will finish the
> >>>>>>> waiting VM ops. But we'd better make the amdgpu_vm->evicting
> >>>>>>> correctly reflact the vm status and clear the error log.
> >>>>>> Well NAK, that is intentional behavior.
> >>>>>>
> >>>>>> The VM page tables where considered for eviction, so setting the flag 
> >>>>>> is
> >>>>>> correct even when the page tables later on are not actually evicted.
> >>>>>>
> >>>>> But this will unnecessarily stop latter user VM ops in ioctl before CS
> >>>>> even when the VM bos are not evicted.
> >>>>> Won't this have any negative effect when could do better?
> >>>> No, this will have a positive effect. See the VM was already considered
> >>>> for eviction because it is idle.
> >>>>
> >>>> Updating it immediately doesn't necessarily make sense, we should wait
> >>>> with that until its next usage.
> >>>>
> >>>> Additional to that this patch doesn't really fix the problem, it just
> >>>> mitigates it.
> >>>>
> >>>> Eviction can fail later on for a couple of reasons and we absolutely
> >>>> need to check the flag instead of the list in amdgpu_vm_ready().
> >>> The flag only for both flag and list? Looks like should be both as
> >>> the list indicate some vm page table need to be updated and could
> >>> delay the user update with the same logic as you described above.
> >> I think checking the flag should be enough. The issue is that the list
> >> was there initially, but to avoid race conditions we added the flag with
> >> separate lock protection later on.
> >>
> > But list and flag does not align always, there are cases like
> > list-empty/flag-set (this problem) and list-non-empty/flag-unset (non-vm bo
> > eviction). If only check flag list-non-empty/flag-unset change behavior.
>
> Yeah, but I think that the flag unset list-non-empty case would be
> correctly handled if we only test the flag.
>
> In other words we can update the page tables as long as they are not
> partially or fully evicted and that's not the case when non-vm BOs are
> evicted.
>
This sounds like two standard for the same thing, because this problem
does not evict page tables too. But I see your point is:
There's a difference that this problem's case can make sure vm is idle,
and we prefer to delay vm updates when vm is idle.

If so, why not just stop user vm update by checking vm busy in
amdgpu_gem_va_ioctl() to skip amdgpu_gem_va_update_vm()?

Then we can

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-17 Thread Qiang Yu
On Thu, Feb 17, 2022 at 6:39 PM Christian König
 wrote:
>
>
>
> Am 17.02.22 um 11:13 schrieb Qiang Yu:
> > On Thu, Feb 17, 2022 at 5:46 PM Christian König
> >  wrote:
> >> Am 17.02.22 um 10:40 schrieb Qiang Yu:
> >>> On Thu, Feb 17, 2022 at 5:15 PM Christian König
> >>>  wrote:
> >>>> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> >>>>> Workstation application ANSA/META get this error dmesg:
> >>>>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)
> >>>>>
> >>>>> This is caused by:
> >>>>> 1. create a 256MB buffer in invisible VRAM
> >>>>> 2. CPU map the buffer and access it causes vm_fault and try to move
> >>>>>   it to visible VRAM
> >>>>> 3. force visible VRAM space and traverse all VRAM bos to check if
> >>>>>   evicting this bo is valuable
> >>>>> 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> >>>>>   will set amdgpu_vm->evicting, but latter due to not in visible
> >>>>>   VRAM, won't really evict it so not add it to amdgpu_vm->evicted
> >>>>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> >>>>>   ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> >>>>>   but fail in amdgpu_vm_bo_update_mapping() (check
> >>>>>   amdgpu_vm->evicting) and get this error log
> >>>>>
> >>>>> This error won't affect functionality as next CS will finish the
> >>>>> waiting VM ops. But we'd better make the amdgpu_vm->evicting
> >>>>> correctly reflact the vm status and clear the error log.
> >>>> Well NAK, that is intentional behavior.
> >>>>
> >>>> The VM page tables where considered for eviction, so setting the flag is
> >>>> correct even when the page tables later on are not actually evicted.
> >>>>
> >>> But this will unnecessarily stop latter user VM ops in ioctl before CS
> >>> even when the VM bos are not evicted.
> >>> Won't this have any negative effect when could do better?
> >> No, this will have a positive effect. See the VM was already considered
> >> for eviction because it is idle.
> >>
> >> Updating it immediately doesn't necessarily make sense, we should wait
> >> with that until its next usage.
> >>
> >> Additional to that this patch doesn't really fix the problem, it just
> >> mitigates it.
> >>
> >> Eviction can fail later on for a couple of reasons and we absolutely
> >> need to check the flag instead of the list in amdgpu_vm_ready().
> > The flag only for both flag and list? Looks like should be both as
> > the list indicate some vm page table need to be updated and could
> > delay the user update with the same logic as you described above.
>
> I think checking the flag should be enough. The issue is that the list
> was there initially, but to avoid race conditions we added the flag with
> separate lock protection later on.
>
But list and flag does not align always, there are cases like
list-empty/flag-set (this problem) and list-non-empty/flag-unset (non-vm bo
eviction). If only check flag list-non-empty/flag-unset change behavior.

Regards,
Qiang

> Regards,
> Christian.
>
> >
> > Regards,
> > Qiang
> >
> >> Regards,
> >> Christian.
> >>
> >>> Regards,
> >>> Qiang
> >>>
> >>>> What we should rather do is to fix amdgpu_vm_ready() to take a look at
> >>>> the flag instead of the linked list.
> >>>>
> >>>> Regards,
> >>>> Christian.
> >>>>
> >>>>> Signed-off-by: Qiang Yu 
> >>>>> ---
> >>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 85 
> >>>>> ++---
> >>>>> 1 file changed, 47 insertions(+), 38 deletions(-)
> >>>>>
> >>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> >>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>>>> index 5a32ee66d8c8..88a27911054f 100644
> >>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>>>> @@ -1306,45 +1306,11 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct 
> >>>>> amdgpu_device *adev, struct 

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-17 Thread Qiang Yu
On Thu, Feb 17, 2022 at 5:46 PM Christian König
 wrote:
>
> Am 17.02.22 um 10:40 schrieb Qiang Yu:
> > On Thu, Feb 17, 2022 at 5:15 PM Christian König
> >  wrote:
> >> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> >>> Workstation application ANSA/META get this error dmesg:
> >>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)
> >>>
> >>> This is caused by:
> >>> 1. create a 256MB buffer in invisible VRAM
> >>> 2. CPU map the buffer and access it causes vm_fault and try to move
> >>>  it to visible VRAM
> >>> 3. force visible VRAM space and traverse all VRAM bos to check if
> >>>  evicting this bo is valuable
> >>> 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> >>>  will set amdgpu_vm->evicting, but latter due to not in visible
> >>>  VRAM, won't really evict it so not add it to amdgpu_vm->evicted
> >>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> >>>  ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> >>>  but fail in amdgpu_vm_bo_update_mapping() (check
> >>>  amdgpu_vm->evicting) and get this error log
> >>>
> >>> This error won't affect functionality as next CS will finish the
> >>> waiting VM ops. But we'd better make the amdgpu_vm->evicting
> >>> correctly reflact the vm status and clear the error log.
> >> Well NAK, that is intentional behavior.
> >>
> >> The VM page tables where considered for eviction, so setting the flag is
> >> correct even when the page tables later on are not actually evicted.
> >>
> > But this will unnecessarily stop latter user VM ops in ioctl before CS
> > even when the VM bos are not evicted.
> > Won't this have any negative effect when could do better?
>
> No, this will have a positive effect. See the VM was already considered
> for eviction because it is idle.
>
> Updating it immediately doesn't necessarily make sense, we should wait
> with that until its next usage.
>
> Additional to that this patch doesn't really fix the problem, it just
> mitigates it.
>
> Eviction can fail later on for a couple of reasons and we absolutely
> need to check the flag instead of the list in amdgpu_vm_ready().
The flag only for both flag and list? Looks like should be both as
the list indicate some vm page table need to be updated and could
delay the user update with the same logic as you described above.

Regards,
Qiang

>
> Regards,
> Christian.
>
> >
> > Regards,
> > Qiang
> >
> >> What we should rather do is to fix amdgpu_vm_ready() to take a look at
> >> the flag instead of the linked list.
> >>
> >> Regards,
> >> Christian.
> >>
> >>> Signed-off-by: Qiang Yu 
> >>> ---
> >>>drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 85 ++---
> >>>1 file changed, 47 insertions(+), 38 deletions(-)
> >>>
> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>> index 5a32ee66d8c8..88a27911054f 100644
> >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >>> @@ -1306,45 +1306,11 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct 
> >>> amdgpu_device *adev, struct ttm_tt *ttm,
> >>>return flags;
> >>>}
> >>>
> >>> -/*
> >>> - * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a 
> >>> buffer
> >>> - * object.
> >>> - *
> >>> - * Return true if eviction is sensible. Called by ttm_mem_evict_first() 
> >>> on
> >>> - * behalf of ttm_bo_mem_force_space() which tries to evict buffer 
> >>> objects until
> >>> - * it can find space for a new object and by ttm_bo_force_list_clean() 
> >>> which is
> >>> - * used to clean out a memory space.
> >>> - */
> >>> -static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
> >>> - const struct ttm_place *place)
> >>> +static bool amdgpu_ttm_mem_eviction_valuable(struct ttm_buffer_object 
> >>> *bo,
> >>> +  const struct ttm_place *place)
> >>>{
> >>>unsigned long num_pages = bo->resource

Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-17 Thread Qiang Yu
On Thu, Feb 17, 2022 at 5:15 PM Christian König
 wrote:
>
> Am 17.02.22 um 10:04 schrieb Qiang Yu:
> > Workstation application ANSA/META get this error dmesg:
> > [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)
> >
> > This is caused by:
> > 1. create a 256MB buffer in invisible VRAM
> > 2. CPU map the buffer and access it causes vm_fault and try to move
> > it to visible VRAM
> > 3. force visible VRAM space and traverse all VRAM bos to check if
> > evicting this bo is valuable
> > 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
> > will set amdgpu_vm->evicting, but latter due to not in visible
> > VRAM, won't really evict it so not add it to amdgpu_vm->evicted
> > 5. before next CS to clear the amdgpu_vm->evicting, user VM ops
> > ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
> > but fail in amdgpu_vm_bo_update_mapping() (check
> > amdgpu_vm->evicting) and get this error log
> >
> > This error won't affect functionality as next CS will finish the
> > waiting VM ops. But we'd better make the amdgpu_vm->evicting
> > correctly reflact the vm status and clear the error log.
>
> Well NAK, that is intentional behavior.
>
> The VM page tables where considered for eviction, so setting the flag is
> correct even when the page tables later on are not actually evicted.
>
But this will unnecessarily stop latter user VM ops in ioctl before CS
even when the VM bos are not evicted.
Won't this have any negative effect when could do better?

Regards,
Qiang

> What we should rather do is to fix amdgpu_vm_ready() to take a look at
> the flag instead of the linked list.
>
> Regards,
> Christian.
>
> >
> > Signed-off-by: Qiang Yu 
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 85 ++---
> >   1 file changed, 47 insertions(+), 38 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > index 5a32ee66d8c8..88a27911054f 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > @@ -1306,45 +1306,11 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct 
> > amdgpu_device *adev, struct ttm_tt *ttm,
> >   return flags;
> >   }
> >
> > -/*
> > - * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a buffer
> > - * object.
> > - *
> > - * Return true if eviction is sensible. Called by ttm_mem_evict_first() on
> > - * behalf of ttm_bo_mem_force_space() which tries to evict buffer objects 
> > until
> > - * it can find space for a new object and by ttm_bo_force_list_clean() 
> > which is
> > - * used to clean out a memory space.
> > - */
> > -static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
> > - const struct ttm_place *place)
> > +static bool amdgpu_ttm_mem_eviction_valuable(struct ttm_buffer_object *bo,
> > +  const struct ttm_place *place)
> >   {
> >   unsigned long num_pages = bo->resource->num_pages;
> >   struct amdgpu_res_cursor cursor;
> > - struct dma_resv_list *flist;
> > - struct dma_fence *f;
> > - int i;
> > -
> > - /* Swapout? */
> > - if (bo->resource->mem_type == TTM_PL_SYSTEM)
> > - return true;
> > -
> > - if (bo->type == ttm_bo_type_kernel &&
> > - !amdgpu_vm_evictable(ttm_to_amdgpu_bo(bo)))
> > - return false;
> > -
> > - /* If bo is a KFD BO, check if the bo belongs to the current process.
> > -  * If true, then return false as any KFD process needs all its BOs to
> > -  * be resident to run successfully
> > -  */
> > - flist = dma_resv_shared_list(bo->base.resv);
> > - if (flist) {
> > - for (i = 0; i < flist->shared_count; ++i) {
> > - f = rcu_dereference_protected(flist->shared[i],
> > - dma_resv_held(bo->base.resv));
> > - if (amdkfd_fence_check_mm(f, current->mm))
> > - return false;
> > - }
> > - }
> >
> >   switch (bo->resource->mem_type) {
> >   case AMDGPU_PL_PREEMPT:
> > @@ -1377,10 +1343,53 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct 
> > ttm_buffer_object *bo,
> >   return false;
> >
> >   default:
> &

[PATCH] drm/amdgpu: check vm bo eviction valuable at last

2022-02-17 Thread Qiang Yu
Workstation application ANSA/META get this error dmesg:
[drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16)

This is caused by:
1. create a 256MB buffer in invisible VRAM
2. CPU map the buffer and access it causes vm_fault and try to move
   it to visible VRAM
3. force visible VRAM space and traverse all VRAM bos to check if
   evicting this bo is valuable
4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable()
   will set amdgpu_vm->evicting, but latter due to not in visible
   VRAM, won't really evict it so not add it to amdgpu_vm->evicted
5. before next CS to clear the amdgpu_vm->evicting, user VM ops
   ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted)
   but fail in amdgpu_vm_bo_update_mapping() (check
   amdgpu_vm->evicting) and get this error log

This error won't affect functionality as next CS will finish the
waiting VM ops. But we'd better make the amdgpu_vm->evicting
correctly reflact the vm status and clear the error log.

Signed-off-by: Qiang Yu 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 85 ++---
 1 file changed, 47 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 5a32ee66d8c8..88a27911054f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1306,45 +1306,11 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device 
*adev, struct ttm_tt *ttm,
return flags;
 }
 
-/*
- * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a buffer
- * object.
- *
- * Return true if eviction is sensible. Called by ttm_mem_evict_first() on
- * behalf of ttm_bo_mem_force_space() which tries to evict buffer objects until
- * it can find space for a new object and by ttm_bo_force_list_clean() which is
- * used to clean out a memory space.
- */
-static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
-   const struct ttm_place *place)
+static bool amdgpu_ttm_mem_eviction_valuable(struct ttm_buffer_object *bo,
+const struct ttm_place *place)
 {
unsigned long num_pages = bo->resource->num_pages;
struct amdgpu_res_cursor cursor;
-   struct dma_resv_list *flist;
-   struct dma_fence *f;
-   int i;
-
-   /* Swapout? */
-   if (bo->resource->mem_type == TTM_PL_SYSTEM)
-   return true;
-
-   if (bo->type == ttm_bo_type_kernel &&
-   !amdgpu_vm_evictable(ttm_to_amdgpu_bo(bo)))
-   return false;
-
-   /* If bo is a KFD BO, check if the bo belongs to the current process.
-* If true, then return false as any KFD process needs all its BOs to
-* be resident to run successfully
-*/
-   flist = dma_resv_shared_list(bo->base.resv);
-   if (flist) {
-   for (i = 0; i < flist->shared_count; ++i) {
-   f = rcu_dereference_protected(flist->shared[i],
-   dma_resv_held(bo->base.resv));
-   if (amdkfd_fence_check_mm(f, current->mm))
-   return false;
-   }
-   }
 
switch (bo->resource->mem_type) {
case AMDGPU_PL_PREEMPT:
@@ -1377,10 +1343,53 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct 
ttm_buffer_object *bo,
return false;
 
default:
-   break;
+   return ttm_bo_eviction_valuable(bo, place);
}
+}
 
-   return ttm_bo_eviction_valuable(bo, place);
+/*
+ * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a buffer
+ * object.
+ *
+ * Return true if eviction is sensible. Called by ttm_mem_evict_first() on
+ * behalf of ttm_bo_mem_force_space() which tries to evict buffer objects until
+ * it can find space for a new object and by ttm_bo_force_list_clean() which is
+ * used to clean out a memory space.
+ */
+static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+   const struct ttm_place *place)
+{
+   struct dma_resv_list *flist;
+   struct dma_fence *f;
+   int i;
+
+   /* Swapout? */
+   if (bo->resource->mem_type == TTM_PL_SYSTEM)
+   return true;
+
+   /* If bo is a KFD BO, check if the bo belongs to the current process.
+* If true, then return false as any KFD process needs all its BOs to
+* be resident to run successfully
+*/
+   flist = dma_resv_shared_list(bo->base.resv);
+   if (flist) {
+   for (i = 0; i < flist->shared_count; ++i) {
+   f = rcu_dereference_protected(flist->shared[i],
+   dma_resv_held(bo->base.resv));
+   if (amdkfd_fence_check_mm(f, current->mm))
+

[PATCH libdrm] amdgpu: fix typo in function comment

2018-09-03 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 amdgpu/amdgpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index dc51659..e6ec7a8 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -731,7 +731,7 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
 void amdgpu_bo_inc_ref(amdgpu_bo_handle bo);
 
 /**
- * Request CPU access to GPU accessable memory
+ * Request CPU access to GPU accessible memory
  *
  * \param   buf_handle - \c [in] Buffer handle
  * \param   cpu- \c [out] CPU address to be used for access
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH libdrm] amdgpu: amdgpu_bo_inc_ref don't return dummy int

2018-09-03 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 amdgpu/amdgpu-symbol-check | 2 +-
 amdgpu/amdgpu.h| 5 +
 amdgpu/amdgpu_bo.c | 3 +--
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check
index 487610e..58646e8 100755
--- a/amdgpu/amdgpu-symbol-check
+++ b/amdgpu/amdgpu-symbol-check
@@ -15,8 +15,8 @@ amdgpu_bo_cpu_map
 amdgpu_bo_cpu_unmap
 amdgpu_bo_export
 amdgpu_bo_free
-amdgpu_bo_inc_ref
 amdgpu_bo_import
+amdgpu_bo_inc_ref
 amdgpu_bo_list_create
 amdgpu_bo_list_destroy
 amdgpu_bo_list_update
diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index e1f93f8..dc51659 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -725,13 +725,10 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
  *
  * \param   bo - \c [in]  Buffer object handle to increase the reference count
  *
- * \return   0 on success\n
- *  <0 - Negative POSIX Error code
- *
  * \sa amdgpu_bo_alloc(), amdgpu_bo_free()
  *
 */
-int amdgpu_bo_inc_ref(amdgpu_bo_handle bo);
+void amdgpu_bo_inc_ref(amdgpu_bo_handle bo);
 
 /**
  * Request CPU access to GPU accessable memory
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index dceab01..6a95929 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -438,10 +438,9 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
return 0;
 }
 
-int amdgpu_bo_inc_ref(amdgpu_bo_handle bo)
+void amdgpu_bo_inc_ref(amdgpu_bo_handle bo)
 {
atomic_inc(>refcount);
-   return 0;
 }
 
 int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH libdrm] amdgpu: add amdgpu_bo_inc_ref() function.

2018-09-03 Thread Qiang Yu
For Pro OGL be able to work with upstream libdrm.

Signed-off-by: Qiang Yu 
Reviewed-by: Christian König 
---
 amdgpu/amdgpu-symbol-check |  1 +
 amdgpu/amdgpu.h| 15 ++-
 amdgpu/amdgpu_bo.c |  6 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check
index b5e4fe6..487610e 100755
--- a/amdgpu/amdgpu-symbol-check
+++ b/amdgpu/amdgpu-symbol-check
@@ -15,6 +15,7 @@ amdgpu_bo_cpu_map
 amdgpu_bo_cpu_unmap
 amdgpu_bo_export
 amdgpu_bo_free
+amdgpu_bo_inc_ref
 amdgpu_bo_import
 amdgpu_bo_list_create
 amdgpu_bo_list_destroy
diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index a8c353c..e1f93f8 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -721,7 +721,20 @@ int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev,
 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
 
 /**
- * Request CPU access to GPU accessible memory
+ * Increase the reference count of a buffer object
+ *
+ * \param   bo - \c [in]  Buffer object handle to increase the reference count
+ *
+ * \return   0 on success\n
+ *  <0 - Negative POSIX Error code
+ *
+ * \sa amdgpu_bo_alloc(), amdgpu_bo_free()
+ *
+*/
+int amdgpu_bo_inc_ref(amdgpu_bo_handle bo);
+
+/**
+ * Request CPU access to GPU accessable memory
  *
  * \param   buf_handle - \c [in] Buffer handle
  * \param   cpu- \c [out] CPU address to be used for access
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index a2fc525..dceab01 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -438,6 +438,12 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
return 0;
 }
 
+int amdgpu_bo_inc_ref(amdgpu_bo_handle bo)
+{
+   atomic_inc(>refcount);
+   return 0;
+}
+
 int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
 {
union drm_amdgpu_gem_mmap args;
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH libdrm] amdgpu: only add DRM_RDWR when kernel accept it

2018-04-17 Thread Qiang Yu
For kernel < 4.6 drm_prime_handle_to_fd_ioctl won't
accept DRM_RDWR.

Sigend-off-by: Qiang Yu <qiang...@amd.com>
---
 amdgpu/amdgpu_bo.c   | 8 ++--
 amdgpu/amdgpu_internal.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 9e37b14..17f848f 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -229,6 +229,7 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,
 uint32_t *shared_handle)
 {
int r;
+   uint32_t flags;
 
switch (type) {
case amdgpu_bo_handle_type_gem_flink_name:
@@ -246,8 +247,11 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,
 
case amdgpu_bo_handle_type_dma_buf_fd:
amdgpu_add_handle_to_table(bo);
-   return drmPrimeHandleToFD(bo->dev->fd, bo->handle,
- DRM_CLOEXEC | DRM_RDWR,
+   flags = DRM_CLOEXEC;
+   if (AMDGPU_VERSION(bo->dev->major_version, 
bo->dev->minor_version) >=
+   AMDGPU_VERSION(3, 1))
+   flags |= DRM_RDWR;
+   return drmPrimeHandleToFD(bo->dev->fd, bo->handle, flags,
  (int*)shared_handle);
}
return -EINVAL;
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 99b8ce0..09f5036 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -39,6 +39,8 @@
 #define ROUND_UP(x, y) x)-1) | __round_mask(x, y))+1)
 #define ROUND_DOWN(x, y) ((x) & ~__round_mask(x, y))
 
+#define AMDGPU_VERSION(major, minor) ((major << 16) | minor)
+
 #define AMDGPU_INVALID_VA_ADDRESS  0x
 #define AMDGPU_NULL_SUBMIT_SEQ 0
 
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH libdrm] headers: sync up amdgpu_drm.h with drm-next

2018-03-20 Thread Qiang Yu
From: Rex Zhu 

Add sensor_info type
AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK
AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK

Reviewed-by: Evan Quan 
Signed-off-by: Rex Zhu 
---
 include/drm/amdgpu_drm.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/drm/amdgpu_drm.h b/include/drm/amdgpu_drm.h
index f9d81bf..c519776 100644
--- a/include/drm/amdgpu_drm.h
+++ b/include/drm/amdgpu_drm.h
@@ -723,6 +723,10 @@ struct drm_amdgpu_cs_chunk_data {
#define AMDGPU_INFO_SENSOR_VDDNB0x6
/* Subquery id: Query graphics voltage */
#define AMDGPU_INFO_SENSOR_VDDGFX   0x7
+   /* Subquery id: Query GPU stable pstate shader clock */
+   #define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK   0x8
+   /* Subquery id: Query GPU stable pstate memory clock */
+   #define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK   0x9
 /* Number of VRAM page faults on CPU access. */
 #define AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS   0x1E
 #define AMDGPU_INFO_VRAM_LOST_COUNTER  0x1F
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH xserver] config: fix GPUDevice fail when AutoAddGPU off + BusID

2016-09-08 Thread Qiang Yu
This fix is for the following xorg.conf can work:

Section "ServerFlags"
Option  "AutoAddGPU" "off"
EndSection

Section "Device"
Identifier "Amd"
Driver "ati"
BusID "PCI:1:0:0"
EndSection

Section "Device"
Identifier "Intel"
Driver "modesetting"
BusID "pci:0:2:0"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Intel"
GPUDevice "Amd"
EndSection

Without AutoAddGPU off, modesetting DDX will also be loaded
for GPUDevice.

Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/common/xf86platformBus.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/common/xf86platformBus.c 
b/hw/xfree86/common/xf86platformBus.c
index 96895a6..03fd931 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -418,6 +418,19 @@ probeSingleDevice(struct xf86_platform_device *dev, 
DriverPtr drvp, GDevPtr gdev
 return foundScreen;
 }
 
+static Bool
+isGPUDevice(GDevPtr gdev)
+{
+int i;
+
+for (i = 0; i < gdev->myScreenSection->num_gpu_devices; i++) {
+if (gdev == gdev->myScreenSection->gpu_devices[i])
+return TRUE;
+}
+
+return FALSE;
+}
+
 int
 xf86platformProbeDev(DriverPtr drvp)
 {
@@ -450,9 +463,8 @@ xf86platformProbeDev(DriverPtr drvp)
 if (j == xf86_num_platform_devices)
  continue;
 
-foundScreen = probeSingleDevice(_platform_devices[j], drvp, 
devList[i], 0);
-if (!foundScreen)
-continue;
+foundScreen = probeSingleDevice(_platform_devices[j], drvp, 
devList[i],
+isGPUDevice(devList[i]) ? 
PLATFORM_PROBE_GPU_SCREEN : 0);
 }
 
 /* if autoaddgpu devices is enabled then go find any unclaimed platform
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH xf86-video-amdgpu] Fix amdgpu_dri2_exchange_buffers width/height miss copy

2016-08-22 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 src/amdgpu_dri2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index 03e3a0b..de701c2 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -665,7 +665,7 @@ amdgpu_dri2_exchange_buffers(DrawablePtr draw, 
DRI2BufferPtr front,
 
region.extents.x1 = region.extents.y1 = 0;
region.extents.x2 = front_priv->pixmap->drawable.width;
-   region.extents.y2 = front_priv->pixmap->drawable.width;
+   region.extents.y2 = front_priv->pixmap->drawable.height;
region.data = NULL;
DamageRegionAppend(_priv->pixmap->drawable, );
 
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v4 xserver 0/4] modesetting: add DRI2 page flip support

2016-08-22 Thread Qiang Yu
Hi guys,

This patch set is for adding DRI2 page flip support to modesetting
driver. I mainly take reference of amdgpu DDX and reuse present
page flip code in the modesetting driver.

V2:
1. fix DRI2 page flip success handler event memory leak
2. adjust patch sequence to make DRI2 use the common
   page flip code in pageflip.c from the beginning
3. some fix on debug output and comments

V3:
1. squash previous patch 5 into patch 4

V4:
1. fix ms_dri2_exchange_buffers width/height miss copy
2. some fix on debug output and comments

Regards,
Qiang

Qiang Yu (4):
  modesetting: make ms_do_pageflip generic for share with DRI2
  modesetting: move ms_do_pageflip to pageflip.c
  modesetting: move common page flip handle to pageflip.c
  modesetting: add DRI2 page flip support

 hw/xfree86/drivers/modesetting/Makefile.am   |   1 +
 hw/xfree86/drivers/modesetting/dri2.c| 237 +++-
 hw/xfree86/drivers/modesetting/driver.h  |  21 ++
 hw/xfree86/drivers/modesetting/drmmode_display.h |   3 +
 hw/xfree86/drivers/modesetting/pageflip.c| 344 +++
 hw/xfree86/drivers/modesetting/present.c | 335 +++---
 6 files changed, 630 insertions(+), 311 deletions(-)
 create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c

-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v4 xserver 3/4] modesetting: move common page flip handle to pageflip.c

2016-08-22 Thread Qiang Yu
The common page flip handle framework can be shared with DRI2
page flip.

Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/driver.h   |  28 
 hw/xfree86/drivers/modesetting/pageflip.c | 102 --
 hw/xfree86/drivers/modesetting/present.c  |  62 +++---
 3 files changed, 105 insertions(+), 87 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index c0d80a8..38f0ec0 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -156,34 +156,6 @@ Bool ms_present_screen_init(ScreenPtr screen);
 
 #ifdef GLAMOR
 
-/*
- * Event data for an in progress flip.
- * This contains a pointer to the vblank event,
- * and information about the flip in progress.
- * a reference to this is stored in the per-crtc
- * flips.
- */
-struct ms_flipdata {
-ScreenPtr screen;
-void *event;
-/* number of CRTC events referencing this */
-int flip_count;
-uint64_t fe_msc;
-uint64_t fe_usec;
-uint32_t old_fb_id;
-};
-
-/*
- * Per crtc pageflipping infomation,
- * These are submitted to the queuing code
- * one of them per crtc per flip.
- */
-struct ms_crtc_pageflip {
-Bool on_reference_crtc;
-/* reference to the ms_flipdata */
-struct ms_flipdata *flipdata;
-};
-
 typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
  uint64_t usec,
  void *data);
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
index 4549792..5f35999 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -32,6 +32,97 @@
 #ifdef GLAMOR
 
 /*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+ScreenPtr screen;
+void *event;
+ms_pageflip_handler_proc event_handler;
+ms_pageflip_abort_proc abort_handler;
+/* number of CRTC events referencing this */
+int flip_count;
+uint64_t fe_msc;
+uint64_t fe_usec;
+uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+Bool on_reference_crtc;
+/* reference to the ms_flipdata */
+struct ms_flipdata *flipdata;
+};
+
+/**
+ * Free an ms_crtc_pageflip.
+ *
+ * Drops the reference count on the flipdata.
+ */
+static void
+ms_pageflip_free(struct ms_crtc_pageflip *flip)
+{
+struct ms_flipdata *flipdata = flip->flipdata;
+
+free(flip);
+if (--flipdata->flip_count > 0)
+return;
+free(flipdata);
+}
+
+/**
+ * Callback for the DRM event queue when a single flip has completed
+ *
+ * Once the flip has been completed on all pipes, notify the
+ * extension code telling it when that happened
+ */
+static void
+ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data)
+{
+struct ms_crtc_pageflip *flip = data;
+struct ms_flipdata *flipdata = flip->flipdata;
+ScreenPtr screen = flipdata->screen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+
+if (flip->on_reference_crtc) {
+flipdata->fe_msc = msc;
+flipdata->fe_usec = ust;
+}
+
+if (flipdata->flip_count == 1) {
+flipdata->event_handler(flipdata->fe_msc,
+flipdata->fe_usec,
+flipdata->event);
+
+drmModeRmFB(ms->fd, flipdata->old_fb_id);
+}
+ms_pageflip_free(flip);
+}
+
+/*
+ * Callback for the DRM queue abort code.  A flip has been aborted.
+ */
+static void
+ms_pageflip_abort(void *data)
+{
+struct ms_crtc_pageflip *flip = data;
+struct ms_flipdata *flipdata = flip->flipdata;
+
+if (flipdata->flip_count == 1)
+flipdata->abort_handler(flipdata->event);
+
+ms_pageflip_free(flip);
+}
+
+/*
  * Flush the DRM event queue when full; makes space for new events.
  *
  * Returns a negative value on error, 0 if there was nothing to process,
@@ -68,9 +159,7 @@ ms_flush_drm_events(ScreenPtr screen)
 static Bool
 queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
struct ms_flipdata *flipdata,
-   int ref_crtc_vblank_pipe, uint32_t flags,
-   ms_pageflip_handler_proc pageflip_handler,
-   ms_pageflip_abort_proc pageflip_abort)
+   int ref_crtc_vblank_pipe, uint32_t flags)
 {
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 modesettingPtr ms = modesettingPTR(scrn);
@@ -92,7 +181,7 @@ queue_flip_on_crtc(ScreenPtr screen, xf86Cr

[PATCH v4 xserver 2/4] modesetting: move ms_do_pageflip to pageflip.c

2016-08-22 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/Makefile.am |   1 +
 hw/xfree86/drivers/modesetting/driver.h|  48 ++
 hw/xfree86/drivers/modesetting/pageflip.c  | 251 
 hw/xfree86/drivers/modesetting/present.c   | 252 -
 4 files changed, 300 insertions(+), 252 deletions(-)
 create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am 
b/hw/xfree86/drivers/modesetting/Makefile.am
index ca7e05a..44823b0 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -54,6 +54,7 @@ modesetting_drv_la_SOURCES = \
 sh3224.c \
 sh3224.h \
 vblank.c \
+pageflip.c \
 $(NULL)
 
 drivermandir = $(DRIVER_MAN_DIR)
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index 498b9bf..c0d80a8 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -153,3 +153,51 @@ Bool ms_vblank_screen_init(ScreenPtr screen);
 void ms_vblank_close_screen(ScreenPtr screen);
 
 Bool ms_present_screen_init(ScreenPtr screen);
+
+#ifdef GLAMOR
+
+/*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+ScreenPtr screen;
+void *event;
+/* number of CRTC events referencing this */
+int flip_count;
+uint64_t fe_msc;
+uint64_t fe_usec;
+uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+Bool on_reference_crtc;
+/* reference to the ms_flipdata */
+struct ms_flipdata *flipdata;
+};
+
+typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+ uint64_t usec,
+ void *data);
+
+typedef void (*ms_pageflip_abort_proc)(void *data);
+
+int ms_flush_drm_events(ScreenPtr screen);
+
+Bool ms_do_pageflip(ScreenPtr screen,
+PixmapPtr new_front,
+void *event,
+int ref_crtc_vblank_pipe,
+Bool async,
+ms_pageflip_handler_proc pageflip_handler,
+ms_pageflip_abort_proc pageflip_abort);
+
+#endif
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
new file mode 100644
index 000..4549792
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
+#endif
+
+#include 
+#include 
+
+#include "driver.h"
+
+#ifdef GLAMOR
+
+/*
+ * Flush the DRM event queue when full; makes space for new events.
+ *
+ * Returns a negative value on error, 0 if there was nothing to process,
+ * or 1 if we handled any events.
+ */
+int
+ms_flush_drm_events(ScreenPtr screen)
+{
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+
+struct pollfd p = { .fd = ms->fd, .events = POLLIN };
+int r;
+
+do {
+r = xserver_poll(, 1, 0);
+} while (r == -1 && (errno == EINTR || errno == EAGAIN));
+
+/* If there was an error, r will be < 0.  Return that.  If there was
+ * nothing to process, r == 0.  Return that.
+ */
+if (r <= 0)
+return r;
+
+/* Try to handle the event.  If there was an error, return it. */
+r = drmHandleEvent

[PATCH v4 xserver 4/4] modesetting: add DRI2 page flip support

2016-08-22 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c| 237 ++-
 hw/xfree86/drivers/modesetting/driver.h  |   5 +-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   3 +
 hw/xfree86/drivers/modesetting/pageflip.c|   7 +-
 hw/xfree86/drivers/modesetting/present.c |  20 +-
 5 files changed, 257 insertions(+), 15 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index 83cb3e0..d9d4de8 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -46,6 +46,7 @@
 
 enum ms_dri2_frame_event_type {
 MS_DRI2_QUEUE_SWAP,
+MS_DRI2_QUEUE_FLIP,
 MS_DRI2_WAIT_MSC,
 };
 
@@ -399,6 +400,197 @@ ms_dri2_blit_swap(DrawablePtr drawable,
 ms_dri2_copy_region(drawable, , dst, src);
 }
 
+struct ms_dri2_vblank_event {
+XID drawable_id;
+ClientPtr client;
+DRI2SwapEventPtr event_complete;
+void *event_data;
+};
+
+static void
+ms_dri2_flip_abort(modesettingPtr ms, void *data)
+{
+struct ms_present_vblank_event *event = data;
+
+ms->drmmode.dri2_flipping = FALSE;
+free(event);
+}
+
+static void
+ms_dri2_flip_handler(modesettingPtr ms, uint64_t msc, 
+ uint64_t ust, void *data)
+{
+struct ms_dri2_vblank_event *event = data;
+uint32_t frame = msc;
+uint32_t tv_sec = ust / 100;
+uint32_t tv_usec = ust % 100;
+DrawablePtr drawable;
+int status;
+
+status = dixLookupDrawable(, event->drawable_id, serverClient,
+   M_ANY, DixWriteAccess);
+if (status == Success)
+DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec,
+ DRI2_FLIP_COMPLETE, event->event_complete,
+ event->event_data);
+
+ms->drmmode.dri2_flipping = FALSE;
+free(event);
+}
+
+static Bool
+ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
+{
+DrawablePtr draw = info->drawable;
+ScreenPtr screen = draw->pScreen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;
+struct ms_dri2_vblank_event *event;
+drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
+
+event = calloc(1, sizeof(struct ms_dri2_vblank_event));
+if (!event)
+return FALSE;
+
+event->drawable_id = draw->id;
+event->client = info->client;
+event->event_complete = info->event_complete;
+event->event_data = info->event_data;
+
+if (ms_do_pageflip(screen, back_priv->pixmap, event,
+   drmmode_crtc->vblank_pipe, FALSE,
+   ms_dri2_flip_handler,
+   ms_dri2_flip_abort)) {
+ms->drmmode.dri2_flipping = TRUE;
+return TRUE;
+}
+return FALSE;
+}
+
+static Bool
+update_front(DrawablePtr draw, DRI2BufferPtr front)
+{
+ScreenPtr screen = draw->pScreen;
+PixmapPtr pixmap = get_drawable_pixmap(draw);
+ms_dri2_buffer_private_ptr priv = front->driverPrivate;
+CARD32 size;
+CARD16 pitch;
+
+front->name = glamor_name_from_pixmap(pixmap, , );
+if (front->name < 0)
+return FALSE;
+
+(*screen->DestroyPixmap) (priv->pixmap);
+front->pitch = pixmap->devKind;
+front->cpp = pixmap->drawable.bitsPerPixel / 8;
+priv->pixmap = pixmap;
+pixmap->refcnt++;
+
+return TRUE;
+}
+
+static Bool
+can_exchange(ScrnInfoPtr scrn, DrawablePtr draw,
+DRI2BufferPtr front, DRI2BufferPtr back)
+{
+ms_dri2_buffer_private_ptr front_priv = front->driverPrivate;
+ms_dri2_buffer_private_ptr back_priv = back->driverPrivate;
+PixmapPtr front_pixmap;
+PixmapPtr back_pixmap = back_priv->pixmap;
+xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+int num_crtcs_on = 0;
+int i;
+
+for (i = 0; i < config->num_crtc; i++) {
+drmmode_crtc_private_ptr drmmode_crtc = 
config->crtc[i]->driver_private;
+
+/* Don't do pageflipping if CRTCs are rotated. */
+#ifdef GLAMOR_HAS_GBM
+if (drmmode_crtc->rotate_bo.gbm)
+return FALSE;
+#endif
+
+if (ms_crtc_on(config->crtc[i]))
+num_crtcs_on++;
+}
+
+/* We can't do pageflipping if all the CRTCs are off. */
+if (num_crtcs_on == 0)
+return FALSE;
+
+if (!update_front(draw, front))
+return FALSE;
+
+front_pixmap = front_priv->pixmap;
+
+if (front_pixmap->drawable.width != back_pixmap->drawable.width)
+return FALSE;
+
+if (front_pixmap->drawable.height != back_pixmap->drawable.height)
+return FALSE;
+
+if (front_pixmap->drawable.bitsPerPixel !=
+ 

[PATCH v3 xserver 1/4] modesetting: make ms_do_pageflip generic for share with DRI2

2016-08-21 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/present.c | 38 
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index 0093fb5..b680fe5 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -235,7 +235,7 @@ ms_present_flush(WindowPtr window)
  */
 struct ms_flipdata {
 ScreenPtr screen;
-struct ms_present_vblank_event *event;
+void *event;
 /* number of CRTC events referencing this */
 int flip_count;
 uint64_t fe_msc;
@@ -254,6 +254,12 @@ struct ms_crtc_pageflip {
 struct ms_flipdata *flipdata;
 };
 
+typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+ uint64_t usec,
+ void *data);
+
+typedef void (*ms_pageflip_abort_proc)(void *data);
+
 /**
  * Free an ms_crtc_pageflip.
  *
@@ -277,7 +283,7 @@ ms_present_flip_free(struct ms_crtc_pageflip *flip)
  * extension code telling it when that happened
  */
 static void
-ms_flip_handler(uint64_t msc, uint64_t ust, void *data)
+ms_present_flip_handler(uint64_t msc, uint64_t ust, void *data)
 {
 struct ms_crtc_pageflip *flip = data;
 ScreenPtr screen = flip->flipdata->screen;
@@ -331,7 +337,9 @@ ms_present_flip_abort(void *data)
 static Bool
 queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
struct ms_flipdata *flipdata,
-   int ref_crtc_vblank_pipe, uint32_t flags)
+   int ref_crtc_vblank_pipe, uint32_t flags,
+   ms_pageflip_handler_proc pageflip_handler,
+   ms_pageflip_abort_proc pageflip_abort)
 {
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 modesettingPtr ms = modesettingPTR(scrn);
@@ -353,17 +361,12 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
 flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == 
ref_crtc_vblank_pipe);
 flip->flipdata = flipdata;
 
-seq = ms_drm_queue_alloc(crtc, flip, ms_flip_handler, 
ms_present_flip_abort);
+seq = ms_drm_queue_alloc(crtc, flip, pageflip_handler, pageflip_abort);
 if (!seq) {
 free(flip);
 return FALSE;
 }
 
-DebugPresent(("\t\tms:fq %lld c %d -> %d seq %llu\n",
-  (long long) flipdata->event->event_id,
-  flipdata->flip_count, flipdata->flip_count + 1,
-  (long long) seq));
-
 /* take a reference on flipdata for use in flip */
 flipdata->flip_count++;
 
@@ -394,9 +397,11 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
 static Bool
 ms_do_pageflip(ScreenPtr screen,
PixmapPtr new_front,
-   struct ms_present_vblank_event *event,
+   void *event,
int ref_crtc_vblank_pipe,
-   Bool async)
+   Bool async,
+   ms_pageflip_handler_proc pageflip_handler,
+   ms_pageflip_abort_proc pageflip_abort)
 {
 #ifndef GLAMOR_HAS_GBM
 return FALSE;
@@ -470,7 +475,8 @@ ms_do_pageflip(ScreenPtr screen,
 
 if (!queue_flip_on_crtc(screen, crtc, flipdata,
 ref_crtc_vblank_pipe,
-flags)) {
+flags, pageflip_handler,
+pageflip_abort)) {
 goto error_undo;
 }
 }
@@ -588,8 +594,11 @@ ms_present_flip(RRCrtcPtr crtc,
 if (!event)
 return FALSE;
 
+DebugPresent(("\t\tms:fq %lld\n", event_id));
+
 event->event_id = event_id;
-ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, 
!sync_flip);
+ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, 
!sync_flip,
+ ms_present_flip_handler, ms_present_flip_abort);
 if (!ret)
 xf86DrvMsg(scrn->scrnIndex, X_ERROR, "present flip failed\n");
 
@@ -615,7 +624,8 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id)
 event->event_id = event_id;
 
 if (ms_present_check_flip(NULL, screen->root, pixmap, TRUE) &&
-ms_do_pageflip(screen, pixmap, event, -1, FALSE)) {
+ms_do_pageflip(screen, pixmap, event, -1, FALSE,
+   ms_present_flip_handler, ms_present_flip_abort)) {
 return;
 }
 
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v2 xserver 4/5] modesetting: add DRI2 page flip support

2016-08-19 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c | 230 --
 1 file changed, 221 insertions(+), 9 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index 83cb3e0..acbb980 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -46,6 +46,7 @@
 
 enum ms_dri2_frame_event_type {
 MS_DRI2_QUEUE_SWAP,
+MS_DRI2_QUEUE_FLIP,
 MS_DRI2_WAIT_MSC,
 };
 
@@ -399,6 +400,190 @@ ms_dri2_blit_swap(DrawablePtr drawable,
 ms_dri2_copy_region(drawable, , dst, src);
 }
 
+struct ms_dri2_vblank_event {
+XID drawable_id;
+ClientPtr client;
+DRI2SwapEventPtr event_complete;
+void *event_data;
+};
+
+static void
+ms_dri2_flip_abort(void *data)
+{
+struct ms_present_vblank_event *event = data;
+
+free(event);
+}
+
+static void
+ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)
+{
+struct ms_dri2_vblank_event *event = data;
+uint32_t frame = msc;
+uint32_t tv_sec = ust / 100;
+uint32_t tv_usec = ust % 100;
+DrawablePtr drawable;
+int status;
+
+status = dixLookupDrawable(, event->drawable_id, serverClient,
+   M_ANY, DixWriteAccess);
+if (status == Success)
+DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec,
+ DRI2_FLIP_COMPLETE, event->event_complete,
+ event->event_data);
+
+free(event);
+}
+
+static Bool
+ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
+{
+DrawablePtr draw = info->drawable;
+ScreenPtr screen = draw->pScreen;
+ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;
+struct ms_dri2_vblank_event *event;
+drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
+
+event = calloc(1, sizeof(struct ms_dri2_vblank_event));
+if (!event)
+return FALSE;
+
+event->drawable_id = draw->id;
+event->client = info->client;
+event->event_complete = info->event_complete;
+event->event_data = info->event_data;
+
+if (ms_do_pageflip(screen, back_priv->pixmap, event,
+   drmmode_crtc->vblank_pipe, FALSE,
+   ms_dri2_flip_handler,
+   ms_dri2_flip_abort)) {
+return TRUE;
+}
+return FALSE;
+}
+
+static Bool
+update_front(DrawablePtr draw, DRI2BufferPtr front)
+{
+ScreenPtr screen = draw->pScreen;
+PixmapPtr pixmap = get_drawable_pixmap(draw);
+ms_dri2_buffer_private_ptr priv = front->driverPrivate;
+CARD32 size;
+CARD16 pitch;
+
+front->name = glamor_name_from_pixmap(pixmap, , );
+if (front->name < 0)
+return FALSE;
+
+(*screen->DestroyPixmap) (priv->pixmap);
+front->pitch = pixmap->devKind;
+front->cpp = pixmap->drawable.bitsPerPixel / 8;
+priv->pixmap = pixmap;
+pixmap->refcnt++;
+
+return TRUE;
+}
+
+static Bool
+can_exchange(ScrnInfoPtr scrn, DrawablePtr draw,
+DRI2BufferPtr front, DRI2BufferPtr back)
+{
+ms_dri2_buffer_private_ptr front_priv = front->driverPrivate;
+ms_dri2_buffer_private_ptr back_priv = back->driverPrivate;
+PixmapPtr front_pixmap;
+PixmapPtr back_pixmap = back_priv->pixmap;
+xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+int num_crtcs_on = 0;
+int i;
+
+for (i = 0; i < config->num_crtc; i++) {
+drmmode_crtc_private_ptr drmmode_crtc = 
config->crtc[i]->driver_private;
+
+/* Don't do pageflipping if CRTCs are rotated. */
+#ifdef GLAMOR_HAS_GBM
+if (drmmode_crtc->rotate_bo.gbm)
+return FALSE;
+#endif
+
+if (ms_crtc_on(config->crtc[i]))
+num_crtcs_on++;
+}
+
+/* We can't do pageflipping if all the CRTCs are off. */
+if (num_crtcs_on == 0)
+return FALSE;
+
+if (!update_front(draw, front))
+return FALSE;
+
+front_pixmap = front_priv->pixmap;
+
+if (front_pixmap->drawable.width != back_pixmap->drawable.width)
+return FALSE;
+
+if (front_pixmap->drawable.height != back_pixmap->drawable.height)
+return FALSE;
+
+if (front_pixmap->drawable.bitsPerPixel !=
+back_pixmap->drawable.bitsPerPixel)
+return FALSE;
+
+if (front_pixmap->devKind != back_pixmap->devKind)
+return FALSE;
+
+return TRUE;
+}
+
+static Bool
+can_flip(ScrnInfoPtr scrn, DrawablePtr draw,
+DRI2BufferPtr front, DRI2BufferPtr back)
+{
+modesettingPtr ms = modesettingPTR(scrn);
+
+return draw->type == DRAWABLE_WINDOW &&
+ms->drmmode.pageflip &&
+scrn->vtSema &&
+DRI2CanFlip(draw) && can_exchange(scrn, draw, front, back);
+}
+
+static void
+ms_dri2_exc

[PATCH v2 xserver 5/5] modesetting: exclude DRI2 and prensent page flip

2016-08-19 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c| 11 +--
 hw/xfree86/drivers/modesetting/driver.h  |  5 +++--
 hw/xfree86/drivers/modesetting/drmmode_display.h |  3 +++
 hw/xfree86/drivers/modesetting/pageflip.c|  7 +--
 hw/xfree86/drivers/modesetting/present.c | 20 ++--
 5 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index acbb980..125c413 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -408,15 +408,17 @@ struct ms_dri2_vblank_event {
 };
 
 static void
-ms_dri2_flip_abort(void *data)
+ms_dri2_flip_abort(modesettingPtr ms, void *data)
 {
 struct ms_present_vblank_event *event = data;
 
+ms->drmmode.dri2_flipping = FALSE;
 free(event);
 }
 
 static void
-ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)
+ms_dri2_flip_handler(modesettingPtr ms, uint64_t msc, 
+ uint64_t ust, void *data)
 {
 struct ms_dri2_vblank_event *event = data;
 uint32_t frame = msc;
@@ -432,6 +434,7 @@ ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)
  DRI2_FLIP_COMPLETE, event->event_complete,
  event->event_data);
 
+ms->drmmode.dri2_flipping = FALSE;
 free(event);
 }
 
@@ -440,6 +443,8 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
 {
 DrawablePtr draw = info->drawable;
 ScreenPtr screen = draw->pScreen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
 ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;
 struct ms_dri2_vblank_event *event;
 drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
@@ -457,6 +462,7 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
drmmode_crtc->vblank_pipe, FALSE,
ms_dri2_flip_handler,
ms_dri2_flip_abort)) {
+ms->drmmode.dri2_flipping = TRUE;
 return TRUE;
 }
 return FALSE;
@@ -542,6 +548,7 @@ can_flip(ScrnInfoPtr scrn, DrawablePtr draw,
 
 return draw->type == DRAWABLE_WINDOW &&
 ms->drmmode.pageflip &&
+!ms->drmmode.present_flipping &&
 scrn->vtSema &&
 DRI2CanFlip(draw) && can_exchange(scrn, draw, front, back);
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index 38f0ec0..761490a 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -156,11 +156,12 @@ Bool ms_present_screen_init(ScreenPtr screen);
 
 #ifdef GLAMOR
 
-typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+typedef void (*ms_pageflip_handler_proc)(modesettingPtr ms,
+ uint64_t frame,
  uint64_t usec,
  void *data);
 
-typedef void (*ms_pageflip_abort_proc)(void *data);
+typedef void (*ms_pageflip_abort_proc)(modesettingPtr ms, void *data);
 
 int ms_flush_drm_events(ScreenPtr screen);
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 5499c16..f774250 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -80,6 +80,9 @@ typedef struct {
 Bool is_secondary;
 
 PixmapPtr fbcon_pixmap;
+
+Bool dri2_flipping;
+Bool present_flipping;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
index 5f35999..a82e0d6 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -98,7 +98,7 @@ ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data)
 }
 
 if (flipdata->flip_count == 1) {
-flipdata->event_handler(flipdata->fe_msc,
+flipdata->event_handler(ms, flipdata->fe_msc,
 flipdata->fe_usec,
 flipdata->event);
 
@@ -115,9 +115,12 @@ ms_pageflip_abort(void *data)
 {
 struct ms_crtc_pageflip *flip = data;
 struct ms_flipdata *flipdata = flip->flipdata;
+ScreenPtr screen = flipdata->screen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
 
 if (flipdata->flip_count == 1)
-flipdata->abort_handler(flipdata->event);
+flipdata->abort_handler(ms, flipdata->event);
 
 ms_pageflip_free(flip);
 }
diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/presen

[PATCH v2 xserver 2/5] modesetting: move ms_do_pageflip to pageflip.c

2016-08-19 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
Reviewed-by: Michel Dänzer <michel.daen...@amd.com>
---
 hw/xfree86/drivers/modesetting/Makefile.am |   1 +
 hw/xfree86/drivers/modesetting/driver.h|  48 ++
 hw/xfree86/drivers/modesetting/pageflip.c  | 251 
 hw/xfree86/drivers/modesetting/present.c   | 252 -
 4 files changed, 300 insertions(+), 252 deletions(-)
 create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am 
b/hw/xfree86/drivers/modesetting/Makefile.am
index ca7e05a..44823b0 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -54,6 +54,7 @@ modesetting_drv_la_SOURCES = \
 sh3224.c \
 sh3224.h \
 vblank.c \
+pageflip.c \
 $(NULL)
 
 drivermandir = $(DRIVER_MAN_DIR)
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index 498b9bf..c0d80a8 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -153,3 +153,51 @@ Bool ms_vblank_screen_init(ScreenPtr screen);
 void ms_vblank_close_screen(ScreenPtr screen);
 
 Bool ms_present_screen_init(ScreenPtr screen);
+
+#ifdef GLAMOR
+
+/*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+ScreenPtr screen;
+void *event;
+/* number of CRTC events referencing this */
+int flip_count;
+uint64_t fe_msc;
+uint64_t fe_usec;
+uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+Bool on_reference_crtc;
+/* reference to the ms_flipdata */
+struct ms_flipdata *flipdata;
+};
+
+typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+ uint64_t usec,
+ void *data);
+
+typedef void (*ms_pageflip_abort_proc)(void *data);
+
+int ms_flush_drm_events(ScreenPtr screen);
+
+Bool ms_do_pageflip(ScreenPtr screen,
+PixmapPtr new_front,
+void *event,
+int ref_crtc_vblank_pipe,
+Bool async,
+ms_pageflip_handler_proc pageflip_handler,
+ms_pageflip_abort_proc pageflip_abort);
+
+#endif
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
new file mode 100644
index 000..4549792
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
+#endif
+
+#include 
+#include 
+
+#include "driver.h"
+
+#ifdef GLAMOR
+
+/*
+ * Flush the DRM event queue when full; makes space for new events.
+ *
+ * Returns a negative value on error, 0 if there was nothing to process,
+ * or 1 if we handled any events.
+ */
+int
+ms_flush_drm_events(ScreenPtr screen)
+{
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+
+struct pollfd p = { .fd = ms->fd, .events = POLLIN };
+int r;
+
+do {
+r = xserver_poll(, 1, 0);
+} while (r == -1 && (errno == EINTR || errno == EAGAIN));
+
+/* If there was an error, r will be < 0.  Return that.  If there was
+ * nothing to process, r == 0.  Return that.
+ */
+if (r <= 0)
+return r;
+
+/* Try to handle the event.  If there was an error, return it. */
+r = drmHandleEvent

[PATCH xserver 6/6] modesetting: remove redundent pixmap destroy

2016-08-17 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index 4cf638e..b18f0b8 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -193,8 +193,6 @@ ms_dri2_create_buffer(DrawablePtr drawable, unsigned int 
attachment,
   pixmap_cpp,
   0);
 if (pixmap == NULL) {
-if (pixmap)
-screen->DestroyPixmap(pixmap);
 free(private);
 free(buffer);
 return NULL;
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH xserver 2/6] modesetting: move ms_do_pageflip to pageflip.c

2016-08-17 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/Makefile.am |   1 +
 hw/xfree86/drivers/modesetting/driver.h|  48 ++
 hw/xfree86/drivers/modesetting/pageflip.c  | 251 
 hw/xfree86/drivers/modesetting/present.c   | 252 -
 4 files changed, 300 insertions(+), 252 deletions(-)
 create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am 
b/hw/xfree86/drivers/modesetting/Makefile.am
index ca7e05a..44823b0 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -54,6 +54,7 @@ modesetting_drv_la_SOURCES = \
 sh3224.c \
 sh3224.h \
 vblank.c \
+pageflip.c \
 $(NULL)
 
 drivermandir = $(DRIVER_MAN_DIR)
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index 498b9bf..c0d80a8 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -153,3 +153,51 @@ Bool ms_vblank_screen_init(ScreenPtr screen);
 void ms_vblank_close_screen(ScreenPtr screen);
 
 Bool ms_present_screen_init(ScreenPtr screen);
+
+#ifdef GLAMOR
+
+/*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+ScreenPtr screen;
+void *event;
+/* number of CRTC events referencing this */
+int flip_count;
+uint64_t fe_msc;
+uint64_t fe_usec;
+uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+Bool on_reference_crtc;
+/* reference to the ms_flipdata */
+struct ms_flipdata *flipdata;
+};
+
+typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+ uint64_t usec,
+ void *data);
+
+typedef void (*ms_pageflip_abort_proc)(void *data);
+
+int ms_flush_drm_events(ScreenPtr screen);
+
+Bool ms_do_pageflip(ScreenPtr screen,
+PixmapPtr new_front,
+void *event,
+int ref_crtc_vblank_pipe,
+Bool async,
+ms_pageflip_handler_proc pageflip_handler,
+ms_pageflip_abort_proc pageflip_abort);
+
+#endif
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c 
b/hw/xfree86/drivers/modesetting/pageflip.c
new file mode 100644
index 000..4549792
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
+#endif
+
+#include 
+#include 
+
+#include "driver.h"
+
+#ifdef GLAMOR
+
+/*
+ * Flush the DRM event queue when full; makes space for new events.
+ *
+ * Returns a negative value on error, 0 if there was nothing to process,
+ * or 1 if we handled any events.
+ */
+int
+ms_flush_drm_events(ScreenPtr screen)
+{
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+
+struct pollfd p = { .fd = ms->fd, .events = POLLIN };
+int r;
+
+do {
+r = xserver_poll(, 1, 0);
+} while (r == -1 && (errno == EINTR || errno == EAGAIN));
+
+/* If there was an error, r will be < 0.  Return that.  If there was
+ * nothing to process, r == 0.  Return that.
+ */
+if (r <= 0)
+return r;
+
+/* Try to handle the event.  If there was an error, return it. */
+r = drmHandleEvent(ms->fd, >event_context);
+if (r < 0)
+

[PATCH xserver 0/6] modesetting: add DRI2 page flip support

2016-08-17 Thread Qiang Yu
Hi guys,

This patch set is for adding DRI2 page flip support to modesetting
driver. I mainly take reference of amdgpu DDX and reuse present
page flip code in the modesetting driver.

Regards,
Qiang

Qiang Yu (6):
  modesetting: make ms_do_pageflip generic for share with DRI2
  modesetting: move ms_do_pageflip to pageflip.c
  modesetting: add DRI2 page flip support
  modesetting: exclude DRI2 and Present page flip
  modesetting: merge common page flip code for present and dri2
  modesetting: remove redundent pixmap destroy

 hw/xfree86/drivers/modesetting/Makefile.am   |   1 +
 hw/xfree86/drivers/modesetting/dri2.c| 237 +++-
 hw/xfree86/drivers/modesetting/driver.h  |  21 ++
 hw/xfree86/drivers/modesetting/drmmode_display.h |   3 +
 hw/xfree86/drivers/modesetting/pageflip.c| 344 +++
 hw/xfree86/drivers/modesetting/present.c | 333 ++
 6 files changed, 624 insertions(+), 315 deletions(-)
 create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c

-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH xserver 3/6] modesetting: add DRI2 page flip support

2016-08-17 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c | 260 --
 1 file changed, 251 insertions(+), 9 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index 83cb3e0..11e0e6f 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -46,6 +46,7 @@
 
 enum ms_dri2_frame_event_type {
 MS_DRI2_QUEUE_SWAP,
+MS_DRI2_QUEUE_FLIP,
 MS_DRI2_WAIT_MSC,
 };
 
@@ -399,6 +400,220 @@ ms_dri2_blit_swap(DrawablePtr drawable,
 ms_dri2_copy_region(drawable, , dst, src);
 }
 
+struct ms_dri2_vblank_event {
+XID drawable_id;
+ClientPtr client;
+DRI2SwapEventPtr event_complete;
+void *event_data;
+};
+
+static void
+ms_dri2_flip_free(struct ms_crtc_pageflip *flip)
+{
+struct ms_flipdata *flipdata = flip->flipdata;
+
+free(flip);
+if (--flipdata->flip_count > 0)
+return;
+free(flipdata);
+}
+
+static void
+ms_dri2_flip_abort(void *data)
+{
+struct ms_crtc_pageflip *flip = data;
+struct ms_flipdata *flipdata = flip->flipdata;
+
+if (flipdata->flip_count == 1)
+free(flipdata->event);
+
+ms_dri2_flip_free(flip);
+}
+
+static void
+ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)
+{
+struct ms_crtc_pageflip *flip = data;
+ScreenPtr screen = flip->flipdata->screen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
+struct ms_flipdata *flipdata = flip->flipdata;
+struct ms_dri2_vblank_event *event = flipdata->event;
+
+if (flip->on_reference_crtc) {
+flipdata->fe_msc = msc;
+flipdata->fe_usec = ust;
+}
+
+if (flipdata->flip_count == 1) {
+uint32_t frame = flipdata->fe_msc;
+uint32_t tv_sec = flipdata->fe_usec / 100;
+uint32_t tv_usec = flipdata->fe_usec % 100;
+DrawablePtr drawable;
+int status;
+
+status = dixLookupDrawable(, event->drawable_id, serverClient,
+   M_ANY, DixWriteAccess);
+if (status == Success)
+DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec,
+ DRI2_FLIP_COMPLETE, event->event_complete,
+ event->event_data);
+drmModeRmFB(ms->fd, flipdata->old_fb_id);
+}
+
+ms_dri2_flip_free(flip);
+}
+
+static Bool
+ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
+{
+DrawablePtr draw = info->drawable;
+ScreenPtr screen = draw->pScreen;
+ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;
+struct ms_dri2_vblank_event *event;
+drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
+
+event = calloc(1, sizeof(struct ms_dri2_vblank_event));
+if (!event)
+return FALSE;
+
+event->drawable_id = draw->id;
+event->client = info->client;
+event->event_complete = info->event_complete;
+event->event_data = info->event_data;
+
+if (ms_do_pageflip(screen, back_priv->pixmap, event,
+   drmmode_crtc->vblank_pipe, FALSE,
+   ms_dri2_flip_handler,
+   ms_dri2_flip_abort)) {
+return TRUE;
+}
+return FALSE;
+}
+
+static Bool
+update_front(DrawablePtr draw, DRI2BufferPtr front)
+{
+ScreenPtr screen = draw->pScreen;
+PixmapPtr pixmap = get_drawable_pixmap(draw);
+ms_dri2_buffer_private_ptr priv = front->driverPrivate;
+CARD32 size;
+CARD16 pitch;
+
+front->name = glamor_name_from_pixmap(pixmap, , );
+if (front->name < 0)
+return FALSE;
+
+(*screen->DestroyPixmap) (priv->pixmap);
+front->pitch = pixmap->devKind;
+front->cpp = pixmap->drawable.bitsPerPixel / 8;
+priv->pixmap = pixmap;
+pixmap->refcnt++;
+
+return TRUE;
+}
+
+static Bool
+can_exchange(ScrnInfoPtr scrn, DrawablePtr draw,
+DRI2BufferPtr front, DRI2BufferPtr back)
+{
+ms_dri2_buffer_private_ptr front_priv = front->driverPrivate;
+ms_dri2_buffer_private_ptr back_priv = back->driverPrivate;
+PixmapPtr front_pixmap;
+PixmapPtr back_pixmap = back_priv->pixmap;
+xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+int num_crtcs_on = 0;
+int i;
+
+for (i = 0; i < config->num_crtc; i++) {
+drmmode_crtc_private_ptr drmmode_crtc = 
config->crtc[i]->driver_private;
+
+/* Don't do pageflipping if CRTCs are rotated. */
+#ifdef GLAMOR_HAS_GBM
+if (drmmode_crtc->rotate_bo.gbm)
+return FALSE;
+#endif
+
+if (ms_crtc_on(config->crtc[i]))
+num_crtcs_on++;
+}
+
+/* We can't do pageflipping if all the CRTCs are off. */
+if (num_crtcs_on == 0)
+return FALSE;
+

[PATCH xserver 4/6] modesetting: exclude DRI2 and Present page flip

2016-08-17 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c| 13 +++--
 hw/xfree86/drivers/modesetting/drmmode_display.h |  3 +++
 hw/xfree86/drivers/modesetting/present.c | 15 +++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c 
b/hw/xfree86/drivers/modesetting/dri2.c
index 11e0e6f..1abf98c 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -423,9 +423,14 @@ ms_dri2_flip_abort(void *data)
 {
 struct ms_crtc_pageflip *flip = data;
 struct ms_flipdata *flipdata = flip->flipdata;
+ScreenPtr screen = flipdata->screen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
 
-if (flipdata->flip_count == 1)
-free(flipdata->event);
+if (flipdata->flip_count == 1) {
+ms->drmmode.dri2_flipping = FALSE;
+free(flipdata->event);
+}
 
 ms_dri2_flip_free(flip);
 }
@@ -469,6 +474,8 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
 {
 DrawablePtr draw = info->drawable;
 ScreenPtr screen = draw->pScreen;
+ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
 ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;
 struct ms_dri2_vblank_event *event;
 drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
@@ -486,6 +493,7 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info)
drmmode_crtc->vblank_pipe, FALSE,
ms_dri2_flip_handler,
ms_dri2_flip_abort)) {
+ms->drmmode.dri2_flipping = TRUE;
 return TRUE;
 }
 return FALSE;
@@ -571,6 +579,7 @@ can_flip(ScrnInfoPtr scrn, DrawablePtr draw,
 
 return draw->type == DRAWABLE_WINDOW &&
 ms->drmmode.pageflip &&
+!ms->drmmode.present_flipping &&
 scrn->vtSema &&
 DRI2CanFlip(draw) && can_exchange(scrn, draw, front, back);
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 5499c16..f774250 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -80,6 +80,9 @@ typedef struct {
 Bool is_secondary;
 
 PixmapPtr fbcon_pixmap;
+
+Bool dri2_flipping;
+Bool present_flipping;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index f4318b4..d10c674 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -53,6 +53,7 @@
 
 struct ms_present_vblank_event {
 uint64_tevent_id;
+Boolunflip;
 };
 
 static RRCrtcPtr
@@ -221,6 +222,7 @@ ms_present_flip_handler(uint64_t msc, uint64_t ust, void 
*data)
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 modesettingPtr ms = modesettingPTR(scrn);
 struct ms_flipdata *flipdata = flip->flipdata;
+struct ms_present_vblank_event *event = flipdata->event;
 
 DebugPresent(("\t\tms:fh %lld c %d msc %llu ust %llu\n",
   (long long) flipdata->event->event_id,
@@ -238,6 +240,8 @@ ms_present_flip_handler(uint64_t msc, uint64_t ust, void 
*data)
   flipdata->flip_count,
   (long long) flipdata->fe_msc, (long long) 
flipdata->fe_usec));
 
+if (event->unflip)
+ms->drmmode.present_flipping = FALSE;
 
 ms_present_vblank_handler(flipdata->fe_msc,
   flipdata->fe_usec,
@@ -284,6 +288,9 @@ ms_present_check_flip(RRCrtcPtr crtc,
 if (!ms->drmmode.pageflip)
 return FALSE;
 
+if (ms->drmmode.dri2_flipping)
+return FALSE;
+
 if (!scrn->vtSema)
 return FALSE;
 
@@ -330,6 +337,7 @@ ms_present_flip(RRCrtcPtr crtc,
 {
 ScreenPtr screen = crtc->pScreen;
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+modesettingPtr ms = modesettingPTR(scrn);
 xf86CrtcPtr xf86_crtc = crtc->devPrivate;
 drmmode_crtc_private_ptr drmmode_crtc = xf86_crtc->driver_private;
 Bool ret;
@@ -343,10 +351,14 @@ ms_present_flip(RRCrtcPtr crtc,
 return FALSE;
 
 event->event_id = event_id;
+event->unflip = FALSE;
+
 ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, 
!sync_flip,
  ms_present_flip_handler, ms_present_flip_abort);
 if (!ret)
 xf86DrvMsg(scrn->scrnIndex, X_ERROR, "present flip failed\n");
+else
+ms->drmmode.present_flipping = TRUE;
 
 return ret;
 }
@@ -358,6 +370,7 @@ static void
 ms_present_unflip(ScreenPtr screen, uint64_t event_i

[PATCH xserver 1/6] modesetting: make ms_do_pageflip generic for share with DRI2

2016-08-17 Thread Qiang Yu
Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 hw/xfree86/drivers/modesetting/present.c | 36 +++-
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index 0093fb5..ff24594 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -235,7 +235,7 @@ ms_present_flush(WindowPtr window)
  */
 struct ms_flipdata {
 ScreenPtr screen;
-struct ms_present_vblank_event *event;
+void *event;
 /* number of CRTC events referencing this */
 int flip_count;
 uint64_t fe_msc;
@@ -254,6 +254,12 @@ struct ms_crtc_pageflip {
 struct ms_flipdata *flipdata;
 };
 
+typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+ uint64_t usec,
+ void *data);
+
+typedef void (*ms_pageflip_abort_proc)(void *data);
+
 /**
  * Free an ms_crtc_pageflip.
  *
@@ -277,7 +283,7 @@ ms_present_flip_free(struct ms_crtc_pageflip *flip)
  * extension code telling it when that happened
  */
 static void
-ms_flip_handler(uint64_t msc, uint64_t ust, void *data)
+ms_present_flip_handler(uint64_t msc, uint64_t ust, void *data)
 {
 struct ms_crtc_pageflip *flip = data;
 ScreenPtr screen = flip->flipdata->screen;
@@ -331,7 +337,9 @@ ms_present_flip_abort(void *data)
 static Bool
 queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
struct ms_flipdata *flipdata,
-   int ref_crtc_vblank_pipe, uint32_t flags)
+   int ref_crtc_vblank_pipe, uint32_t flags,
+   ms_pageflip_handler_proc pageflip_handler,
+   ms_pageflip_abort_proc pageflip_abort)
 {
 ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 modesettingPtr ms = modesettingPTR(scrn);
@@ -353,17 +361,12 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
 flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == 
ref_crtc_vblank_pipe);
 flip->flipdata = flipdata;
 
-seq = ms_drm_queue_alloc(crtc, flip, ms_flip_handler, 
ms_present_flip_abort);
+seq = ms_drm_queue_alloc(crtc, flip, pageflip_handler, pageflip_abort);
 if (!seq) {
 free(flip);
 return FALSE;
 }
 
-DebugPresent(("\t\tms:fq %lld c %d -> %d seq %llu\n",
-  (long long) flipdata->event->event_id,
-  flipdata->flip_count, flipdata->flip_count + 1,
-  (long long) seq));
-
 /* take a reference on flipdata for use in flip */
 flipdata->flip_count++;
 
@@ -394,9 +397,11 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
 static Bool
 ms_do_pageflip(ScreenPtr screen,
PixmapPtr new_front,
-   struct ms_present_vblank_event *event,
+   void *event,
int ref_crtc_vblank_pipe,
-   Bool async)
+   Bool async,
+   ms_pageflip_handler_proc pageflip_handler,
+   ms_pageflip_abort_proc pageflip_abort)
 {
 #ifndef GLAMOR_HAS_GBM
 return FALSE;
@@ -470,7 +475,8 @@ ms_do_pageflip(ScreenPtr screen,
 
 if (!queue_flip_on_crtc(screen, crtc, flipdata,
 ref_crtc_vblank_pipe,
-flags)) {
+flags, pageflip_handler,
+pageflip_abort)) {
 goto error_undo;
 }
 }
@@ -589,7 +595,8 @@ ms_present_flip(RRCrtcPtr crtc,
 return FALSE;
 
 event->event_id = event_id;
-ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, 
!sync_flip);
+ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, 
!sync_flip,
+ ms_present_flip_handler, ms_present_flip_abort);
 if (!ret)
 xf86DrvMsg(scrn->scrnIndex, X_ERROR, "present flip failed\n");
 
@@ -615,7 +622,8 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id)
 event->event_id = event_id;
 
 if (ms_present_check_flip(NULL, screen->root, pixmap, TRUE) &&
-ms_do_pageflip(screen, pixmap, event, -1, FALSE)) {
+ms_do_pageflip(screen, pixmap, event, -1, FALSE,
+   ms_present_flip_handler, ms_present_flip_abort)) {
 return;
 }
 
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx