public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* System hang when using SetMemoryAttributes
@ 2016-09-25 19:01 Michael Zimmermann
  2016-09-26  6:35 ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-25 19:01 UTC (permalink / raw)
  To: edk2-devel@lists.01.org, Ard Biesheuvel, Leif Lindholm

Hi,

which side effects can SetMemoryAttributes have?
I have a device where setting the framebuffer(which is part of DRAM)
to EFI_MEMORY_UC makes UEFI hang later on(when already outside the lcd
driver).

If I do the same on a memory range allocated with AllocateAnyPages instead
of AllocateAddress UEFI boots just fine(but ofc, the screen doesn't work).

Unfortunately I don't have UART on that device but I'm sure there's no
assert because I configured DebugLib to reboot the device in that case -
which never happens, it's just stuck when the console drivers(TerminalDxe
etc) initialize later on.

Thanks
Michael


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-25 19:01 System hang when using SetMemoryAttributes Michael Zimmermann
@ 2016-09-26  6:35 ` Ard Biesheuvel
  2016-09-26  7:13   ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-26  6:35 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 25 September 2016 at 20:01, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
> Hi,
>
> which side effects can SetMemoryAttributes have?
> I have a device where setting the framebuffer(which is part of DRAM) to
> EFI_MEMORY_UC makes UEFI hang later on(when already outside the lcd driver).
>
> If I do the same on a memory range allocated with AllocateAnyPages instead
> of AllocateAddress UEFI boots just fine(but ofc, the screen doesn't work).
>
> Unfortunately I don't have UART on that device but I'm sure there's no
> assert because I configured DebugLib to reboot the device in that case -
> which never happens, it's just stuck when the console drivers(TerminalDxe
> etc) initialize later on.
>

Hello Michael,

EFI_MEMORY_WC is more suitable for a framebuffer than EFI_MEMORY_UC,
since the latter does not allow unaligned accesses, so any unaligned
store will crash the system.

Since the framebuffer is in DRAM, I assume the reason for setting the
memory attributes is that the device is not DMA coherent? Could you
perhaps describe the hardware in more detail?

-- 
Ard.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26  6:35 ` Ard Biesheuvel
@ 2016-09-26  7:13   ` Michael Zimmermann
  2016-09-26  7:44     ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-26  7:13 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

Ard,

I have to mark the framebuffer as uncached, because if writes to it are
cached, they don't instantly reach the underlying hardware. I'd have to
manually flush the cache for that region every time otherwise.

Isn't that the normal way? I don't think that any device would work with a
write-cache framebuffer - I actually copied the code from the ArmVirt LCD
drivers which do the same.

Thanks
Michael

On Mon, Sep 26, 2016 at 8:35 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 25 September 2016 at 20:01, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
> > Hi,
> >
> > which side effects can SetMemoryAttributes have?
> > I have a device where setting the framebuffer(which is part of DRAM) to
> > EFI_MEMORY_UC makes UEFI hang later on(when already outside the lcd
> driver).
> >
> > If I do the same on a memory range allocated with AllocateAnyPages
> instead
> > of AllocateAddress UEFI boots just fine(but ofc, the screen doesn't
> work).
> >
> > Unfortunately I don't have UART on that device but I'm sure there's no
> > assert because I configured DebugLib to reboot the device in that case -
> > which never happens, it's just stuck when the console drivers(TerminalDxe
> > etc) initialize later on.
> >
>
> Hello Michael,
>
> EFI_MEMORY_WC is more suitable for a framebuffer than EFI_MEMORY_UC,
> since the latter does not allow unaligned accesses, so any unaligned
> store will crash the system.
>
> Since the framebuffer is in DRAM, I assume the reason for setting the
> memory attributes is that the device is not DMA coherent? Could you
> perhaps describe the hardware in more detail?
>
> --
> Ard.
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26  7:13   ` Michael Zimmermann
@ 2016-09-26  7:44     ` Michael Zimmermann
  2016-09-26 10:23       ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-26  7:44 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

oh and in case it makes a difference: it's a 64bit ARM device running 32bit
code.

On Mon, Sep 26, 2016 at 9:13 AM, Michael Zimmermann <
sigmaepsilon92@gmail.com> wrote:

> Ard,
>
> I have to mark the framebuffer as uncached, because if writes to it are
> cached, they don't instantly reach the underlying hardware. I'd have to
> manually flush the cache for that region every time otherwise.
>
> Isn't that the normal way? I don't think that any device would work with a
> write-cache framebuffer - I actually copied the code from the ArmVirt LCD
> drivers which do the same.
>
> Thanks
> Michael
>
> On Mon, Sep 26, 2016 at 8:35 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org
> > wrote:
>
>> On 25 September 2016 at 20:01, Michael Zimmermann
>> <sigmaepsilon92@gmail.com> wrote:
>> > Hi,
>> >
>> > which side effects can SetMemoryAttributes have?
>> > I have a device where setting the framebuffer(which is part of DRAM) to
>> > EFI_MEMORY_UC makes UEFI hang later on(when already outside the lcd
>> driver).
>> >
>> > If I do the same on a memory range allocated with AllocateAnyPages
>> instead
>> > of AllocateAddress UEFI boots just fine(but ofc, the screen doesn't
>> work).
>> >
>> > Unfortunately I don't have UART on that device but I'm sure there's no
>> > assert because I configured DebugLib to reboot the device in that case -
>> > which never happens, it's just stuck when the console
>> drivers(TerminalDxe
>> > etc) initialize later on.
>> >
>>
>> Hello Michael,
>>
>> EFI_MEMORY_WC is more suitable for a framebuffer than EFI_MEMORY_UC,
>> since the latter does not allow unaligned accesses, so any unaligned
>> store will crash the system.
>>
>> Since the framebuffer is in DRAM, I assume the reason for setting the
>> memory attributes is that the device is not DMA coherent? Could you
>> perhaps describe the hardware in more detail?
>>
>> --
>> Ard.
>>
>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26  7:44     ` Michael Zimmermann
@ 2016-09-26 10:23       ` Ard Biesheuvel
  2016-09-26 12:44         ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-26 10:23 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 26 September 2016 at 00:44, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
> oh and in case it makes a difference: it's a 64bit ARM device running 32bit
> code.
>

That shouldn't matter.

> On Mon, Sep 26, 2016 at 9:13 AM, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
>>
>> Ard,
>>
>> I have to mark the framebuffer as uncached, because if writes to it are
>> cached, they don't instantly reach the underlying hardware. I'd have to
>> manually flush the cache for that region every time otherwise.
>>
>> Isn't that the normal way? I don't think that any device would work with a
>> write-cache framebuffer - I actually copied the code from the ArmVirt LCD
>> drivers which do the same.
>>

_WC means write-combining, and so these accesses are not cacheable,
but they do allow unaligned accesses, unlike _UC


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26 10:23       ` Ard Biesheuvel
@ 2016-09-26 12:44         ` Michael Zimmermann
  2016-09-26 12:47           ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-26 12:44 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

I'm thankful for the hint about _WC because it drastically improves the
speed on my other devices.
Unfortunately, it doesn't fix the device I have problems with. I tested all
possible attributes and only EFI_MEMORY_WB seems to be
working(even EFI_MEMORY_WT is broken).

The weird thing is that even if I disable accesses to the framebuffer by
disabling all code in the Blt function, it hangs during boot.
I really can't explain this behavior.

On Mon, Sep 26, 2016 at 12:23 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 26 September 2016 at 00:44, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
> > oh and in case it makes a difference: it's a 64bit ARM device running
> 32bit
> > code.
> >
>
> That shouldn't matter.
>
> > On Mon, Sep 26, 2016 at 9:13 AM, Michael Zimmermann
> > <sigmaepsilon92@gmail.com> wrote:
> >>
> >> Ard,
> >>
> >> I have to mark the framebuffer as uncached, because if writes to it are
> >> cached, they don't instantly reach the underlying hardware. I'd have to
> >> manually flush the cache for that region every time otherwise.
> >>
> >> Isn't that the normal way? I don't think that any device would work
> with a
> >> write-cache framebuffer - I actually copied the code from the ArmVirt
> LCD
> >> drivers which do the same.
> >>
>
> _WC means write-combining, and so these accesses are not cacheable,
> but they do allow unaligned accesses, unlike _UC
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26 12:44         ` Michael Zimmermann
@ 2016-09-26 12:47           ` Ard Biesheuvel
  2016-09-26 12:52             ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-26 12:47 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 26 September 2016 at 05:44, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
> I'm thankful for the hint about _WC because it drastically improves the
> speed on my other devices.

Glad I could be of help.

> Unfortunately, it doesn't fix the device I have problems with. I tested all
> possible attributes and only EFI_MEMORY_WB seems to be working(even
> EFI_MEMORY_WT is broken).
>
> The weird thing is that even if I disable accesses to the framebuffer by
> disabling all code in the Blt function, it hangs during boot.
> I really can't explain this behavior.
>

Are you saying your framebuffer does work with cached attributes? That
would mean the graphics device is DMA coherent, which is actually a
good thing. What hardware are we talking about here?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26 12:47           ` Ard Biesheuvel
@ 2016-09-26 12:52             ` Michael Zimmermann
  2016-09-26 17:00               ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-26 12:52 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

> Are you saying your framebuffer does work with cached attributes? That
> would mean the graphics device is DMA coherent, which is actually a
> good thing. What hardware are we talking about here?
yes it does but ofc, it causes glitches since the writes aren't always
synced correctly.
My edk2 port is cross platorm by using PrePi and a function table provided
by another bootloader for hardware communication.

The device that's broken is 'Asus Zenfone 2 Laser ZE550KL' which uses a
'Qualcomm MSM8939 Snapdragon 615' chipset.

On Mon, Sep 26, 2016 at 2:47 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 26 September 2016 at 05:44, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
> > I'm thankful for the hint about _WC because it drastically improves the
> > speed on my other devices.
>
> Glad I could be of help.
>
> > Unfortunately, it doesn't fix the device I have problems with. I tested
> all
> > possible attributes and only EFI_MEMORY_WB seems to be working(even
> > EFI_MEMORY_WT is broken).
> >
> > The weird thing is that even if I disable accesses to the framebuffer by
> > disabling all code in the Blt function, it hangs during boot.
> > I really can't explain this behavior.
> >
>
> Are you saying your framebuffer does work with cached attributes? That
> would mean the graphics device is DMA coherent, which is actually a
> good thing. What hardware are we talking about here?
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26 12:52             ` Michael Zimmermann
@ 2016-09-26 17:00               ` Ard Biesheuvel
  2016-09-26 20:25                 ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-26 17:00 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 26 September 2016 at 05:52, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
>> Are you saying your framebuffer does work with cached attributes? That
>> would mean the graphics device is DMA coherent, which is actually a
>> good thing. What hardware are we talking about here?
> yes it does but ofc, it causes glitches since the writes aren't always
> synced correctly.
> My edk2 port is cross platorm by using PrePi and a function table provided
> by another bootloader for hardware communication.
>
> The device that's broken is 'Asus Zenfone 2 Laser ZE550KL' which uses a
> 'Qualcomm MSM8939 Snapdragon 615' chipset.
>

I couldn't find the exact info on this particular SoC, but in some
cases, devices are DMA coherent at L2 but not L1.

Does it help if you clean (not invalidate) the cache by virtual
address after each BLT operation? Note that the 'by virtual address'
bit is important in coherent systems, simply cleaning the whole L1 is
*not* guaranteed to work. [use WriteBackDataCacheRange()]


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: System hang when using SetMemoryAttributes
  2016-09-26 17:00               ` Ard Biesheuvel
@ 2016-09-26 20:25                 ` Michael Zimmermann
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-26 20:25 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

while this would help on other devices(I've already done that in the past
with edk2 and other environments), in this case it has no effect, there are
always glitches at the bottom of the screen and randomly a few artifact all
over the screen.

That obviously hints at some caching issue. Apparently the cache cleaning
has no effect for the framebuffer of this device.
And it still confuses me that the UC/WC case - even with Blt stubbed - can
cause the system to just hang.

On Mon, Sep 26, 2016 at 7:00 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 26 September 2016 at 05:52, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
> >> Are you saying your framebuffer does work with cached attributes? That
> >> would mean the graphics device is DMA coherent, which is actually a
> >> good thing. What hardware are we talking about here?
> > yes it does but ofc, it causes glitches since the writes aren't always
> > synced correctly.
> > My edk2 port is cross platorm by using PrePi and a function table
> provided
> > by another bootloader for hardware communication.
> >
> > The device that's broken is 'Asus Zenfone 2 Laser ZE550KL' which uses a
> > 'Qualcomm MSM8939 Snapdragon 615' chipset.
> >
>
> I couldn't find the exact info on this particular SoC, but in some
> cases, devices are DMA coherent at L2 but not L1.
>
> Does it help if you clean (not invalidate) the cache by virtual
> address after each BLT operation? Note that the 'by virtual address'
> bit is important in coherent systems, simply cleaning the whole L1 is
> *not* guaranteed to work. [use WriteBackDataCacheRange()]
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-09-26 20:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-25 19:01 System hang when using SetMemoryAttributes Michael Zimmermann
2016-09-26  6:35 ` Ard Biesheuvel
2016-09-26  7:13   ` Michael Zimmermann
2016-09-26  7:44     ` Michael Zimmermann
2016-09-26 10:23       ` Ard Biesheuvel
2016-09-26 12:44         ` Michael Zimmermann
2016-09-26 12:47           ` Ard Biesheuvel
2016-09-26 12:52             ` Michael Zimmermann
2016-09-26 17:00               ` Ard Biesheuvel
2016-09-26 20:25                 ` Michael Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox