[PATCH] drm/amdgpu/display: fix dmub invalid register read

Thomas Lambertz mail at thomaslambertz.de
Wed Mar 24 23:13:21 UTC 2021



On 24/03/2021 22.26, Harry Wentland wrote:
> 
> 
> On 2021-03-24 5:13 p.m., Harry Wentland wrote:
>> +Nick, Bhawan
>>
>> On 2021-03-24 4:39 p.m., Alex Deucher wrote:
>>> On Tue, Mar 23, 2021 at 4:18 AM Thomas Lambertz <mail at thomaslambertz.de> wrote:
>>>>
>>>> DMCUB_SCRATCH_0 sometimes contains 0xdeadbeef during initialization.
>>>> If this is detected, return 0 instead. This prevents wrong bit-flags
>>>> from being read.
>>>>
>>>> The main impact of this bug is in the status check loop in
>>>> dmub_srv_wait_for_auto_load. As it is waiting for the device to become
>>>> ready, returning too early leads to a race condition. It is usually won
>>>> on first boot, but lost when laptop resumes from sleep, breaking screen
>>>> brightness control.
>>>>
>>>> This issue was always present, but previously mitigated by the fact that
>>>> the full register was compared to the wanted value. Currently, only the
>>>> bottom two bits are tested, which are also set in 0xdeadbeef, thus
>>>> returning readiness to early.
>>>>
>>>> Fixes: 5fe6b98ae00d ("drm/amd/display: Update dmub code")
>>>
>>> Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1518 Harry, Leo, Rodrigo, any ideas?
>>>
>>
>> When I checked with our DMUB experts yesterday they said they'd never expect to see 0xdeadbeef in SCRATCH0.
>>
>> That said based on Thomas's test it does look like we're getting deadbeef at resume so I'm almost inclined to ACK this patch. It doesn't really do any harm.
>>
> 
> Apparently an older version of the renoir_dmcub (and likely other versions) had a 0xdeadbeef write to SCRATCH0. In order to support these older FW this patch is
> Reviewed-by: Harry Wentland <harry.wentland at amd.com>
> 
> I recommend updating to the latest FW from linux-firmware if any other issues are observed.

Thank you for the quick triage!

I just tried the newest firmware from git, and have some good and some bad news.
The 0xdeadbeef issue is fixed, and initialization is way faster on the newer firmware.

But the screen brightness issue has been reintroduced. The cause is a different one, and I am not sure how to debug it further.

To test, I booted the same kernel (v5.12-RC4 with my patch applied) with two versions of linux-firmware.
The old one worked, the new one shows the same issue as the old without the patch.

Relevant dmesg parts:

a) NEW, 24/03/2021 (3f026a2)
[    6.350233] [drm] Display Core initialized with v3.2.122!
[    6.350256] DMCUB_SCRATCH0: 0x0
[    6.350359] DMCUB_SCRATCH0: 0x0
[    6.350461] DMCUB_SCRATCH0: 0x0
[    6.350563] DMCUB_SCRATCH0: 0x0
[    6.350666] DMCUB_SCRATCH0: 0x3
[    6.350883] [drm] DMUB hardware initialized: version=0x01020003
.... suspend, resume ....
[   59.709695] DMCUB_SCRATCH0: 0x0
     repeats 6 more times
[   59.710432] DMCUB_SCRATCH0: 0x3
[   59.710438] [drm] DMUB hardware initialized: version=0x01020003



b) OLD, 15/03/2021 (3568f96)
[    7.805468] [drm] Display Core initialized with v3.2.122!
[    7.805496] DMCUB_SCRATCH0: 0x0
[    7.805598] DMCUB_SCRATCH0: 0x0
[    7.805700] DMCUB_SCRATCH0: 0x0
[    7.805801] DMCUB_SCRATCH0: 0x0
[    7.805903] DMCUB_SCRATCH0: 0x1
     repeats 115 more times
[    7.817841] DMCUB_SCRATCH0: 0x1
[    7.817944] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818047] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818149] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818251] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818353] DMCUB_SCRATCH0: 0xdeadbeef
[    7.818454] DMCUB_SCRATCH0: 0x3
[    7.818676] [drm] DMUB hardware initialized: version=0x01000000
.... suspend, resume ....
[   89.818383] DMCUB_SCRATCH0: 0x0
[   89.818493] DMCUB_SCRATCH0: 0x0
[   89.818601] DMCUB_SCRATCH0: 0x0
[   89.818708] DMCUB_SCRATCH0: 0x0
[   89.818811] DMCUB_SCRATCH0: 0x0
[   89.818918] DMCUB_SCRATCH0: 0x0
[   89.819025] DMCUB_SCRATCH0: 0x1
     repeats 112 more times
[   89.831007] DMCUB_SCRATCH0: 0x1
[   89.831110] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831218] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831325] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831428] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831535] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831643] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831745] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831853] DMCUB_SCRATCH0: 0xdeadbeef
[   89.831956] DMCUB_SCRATCH0: 0x3
[   89.832299] [drm] DMUB hardware initialized: version=0x01000000

Thomas


> 
> Harry
> 
>> Harry
>>
>>> Alex
>>>
>>>> Signed-off-by: Thomas Lambertz <mail at thomaslambertz.de>
>>>> ---
>>>>   drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c | 8 +++++++-
>>>>   drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h | 2 ++
>>>>   2 files changed, 9 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c b/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c
>>>> index 8e8e65fa83c0..d6fcae182f68 100644
>>>> --- a/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c
>>>> +++ b/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.c
>>>> @@ -323,8 +323,14 @@ uint32_t dmub_dcn20_get_gpint_response(struct dmub_srv *dmub)
>>>>   union dmub_fw_boot_status dmub_dcn20_get_fw_boot_status(struct dmub_srv *dmub)
>>>>   {
>>>>          union dmub_fw_boot_status status;
>>>> +       uint32_t value;
>>>> +
>>>> +       value = REG_READ(DMCUB_SCRATCH0);
>>>> +       if (value == DMCUB_SCRATCH0_INVALID)
>>>> +               status.all = 0;
>>>> +       else
>>>> +               status.all = value;
>>>>
>>>> -       status.all = REG_READ(DMCUB_SCRATCH0);
>>>>          return status;
>>>>   }
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h b/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h
>>>> index a62be9c0652e..9557e76cf5d4 100644
>>>> --- a/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h
>>>> +++ b/drivers/gpu/drm/amd/display/dmub/src/dmub_dcn20.h
>>>> @@ -154,6 +154,8 @@ struct dmub_srv_common_regs {
>>>>
>>>>   extern const struct dmub_srv_common_regs dmub_srv_dcn20_regs;
>>>>
>>>> +#define DMCUB_SCRATCH0_INVALID 0xdeadbeef
>>>> +
>>>>   /* Hardware functions. */
>>>>
>>>>   void dmub_dcn20_init(struct dmub_srv *dmub);
>>>> -- 
>>>> 2.31.0
>>>> _______________________________________________
>>>> amd-gfx mailing list
>>>> amd-gfx at lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
> 


More information about the amd-gfx mailing list