From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Achin Gupta <achin.gupta@arm.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
nd@arm.com, Supreeth Venkatesh <Supreeth.Venkatesh@arm.com>
Subject: Re: [PATCH] ArmPlatformPkg/ArmVExpressPkg: Fix memory attributes for NOR Flash
Date: Thu, 19 Jan 2017 18:16:00 +0000 [thread overview]
Message-ID: <CAKv+Gu_7Msry9=tfvGZCirSXDd8OnJVxRiv1+byuUfBkE65cXQ@mail.gmail.com> (raw)
In-Reply-To: <20170119123135.GB24076@e102648.cambridge.arm.com>
On 19 January 2017 at 12:31, Achin Gupta <achin.gupta@arm.com> wrote:
> Hi Leif/Ard,
>
> On Wed, Jan 18, 2017 at 10:05:00PM +0000, Leif Lindholm wrote:
>> Hi Achin,
>>
>> On Wed, Jan 18, 2017 at 08:24:06PM +0000, achin.gupta@arm.com wrote:
>> > From: Achin Gupta <achin.gupta@arm.com>
>> >
>> > The NOR flash banks were being mapped in the translation tables with the same
>> > memory attributes as RAM in the system. These attributes mark the region as
>> > Normal Memory and could additionally be cacheable or non-cacheable.
>> >
>> > Either type of attributes are unsuitable for NOR Flash since write operations
>> > could be performed on it. Normal Memory does not guarantee ordering of
>> > transactions that Device memory does. So the commands sent to the Flash device
>> > may not arrive in the right order unless barriers are used. Commands might not
>> > get past the CPU caches in case the region has been mapped with cacheable
>> > attributes.
>> >
>> > This patch fixes the problem by mapping the NOR Flash memory region with Device
>> > memory attributes.
>>
>> To add some background to Ard's comment - this was not unintentionally
>> done:
>> https://github.com/tianocore/edk2/commit/19bb46c411279dcd30d540c56e5993c5f771c319
>
> Thanks! I missed this commit. There is some background to the problem I am
> facing below.
>
>>
>> Was the reasoning behind this commit incorrect - do you have a
>> (pre-DXE?) use-case that creates a problem?
>
> AFAIU, The current memory attributes for NOR Flash work only for reads. They
> should additionally be RO to flag any unexpected writes.
>
> Mine is a DXE use case! In NorFlashDxe.c, commands are send to the Flash (erase
> block etc.). They might never reach the device if there is a write-back cache in
> between. So either device or Normal memory with non-cacheable/write-through
> attributes and barriers should work.
>
> If I turn on cache state modelling in the Base FVP, the code gets stuck in
> NorFlashReadStatusRegister() in the below loop in NorFlashEraseSingleBlock():
>
> // Wait until the status register gives us the all clear
> do {
> StatusRegister = NorFlashReadStatusRegister (Instance, BlockAddress);
> } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
>
> I think the SEND_NOR_COMMANDs at the beginning of the function get stuck in the
> cache. Changing the flash memory attributes as per this patch solves the
> problem.
>
> The original patch from Ard mentions that the NOR Flash DXE driver should change
> the attributes of the region it wants to write to. Is this what is missing?
>
NorFlashFvbInitialize() in
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c contains the
following calls:
Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo,
Instance->DeviceBaseAddress, RuntimeMmioRegionSize,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
);
ASSERT_EFI_ERROR (Status);
Status = gDS->SetMemorySpaceAttributes (
Instance->DeviceBaseAddress, RuntimeMmioRegionSize,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
ASSERT_EFI_ERROR (Status);
which is supposed to set device attributes on the NOR region that is
actually exposed to the upper layers as read-write capable.
Perhaps you can enable GCD debugging to trace these calls, to ensure
that the address you are stalled on is actually covered?
next prev parent reply other threads:[~2017-01-19 18:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 20:24 [PATCH] ArmPlatformPkg/ArmVExpressPkg: Fix memory attributes for NOR Flash achin.gupta
2017-01-18 20:56 ` Ard Biesheuvel
2017-01-18 22:05 ` Leif Lindholm
2017-01-18 22:26 ` Supreeth Venkatesh
2017-01-19 12:31 ` Achin Gupta
2017-01-19 18:16 ` Ard Biesheuvel [this message]
2017-01-19 21:57 ` Achin Gupta
2017-01-19 22:01 ` Ard Biesheuvel
2017-01-20 11:15 ` Achin Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKv+Gu_7Msry9=tfvGZCirSXDd8OnJVxRiv1+byuUfBkE65cXQ@mail.gmail.com' \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox