diff mbox series

[edk2] ArmPkg/ArmMmuLib: Add new attribute WRITE_BACK_NONSHAREABLE

Message ID 1510059411-6608-2-git-send-email-heyi.guo@linaro.org
State New
Headers show
Series [edk2] ArmPkg/ArmMmuLib: Add new attribute WRITE_BACK_NONSHAREABLE | expand

Commit Message

gary guo Nov. 7, 2017, 12:56 p.m. UTC
From: Peicong Li <lipeicong@huawei.com>


Flash region needs to be set as cacheable (write back) to increase
performance, if PEI is still XIP on flash or DXE FV is decompressed
from flash FV. However some ARM platforms do not support to set flash
as inner shareable since flash is not normal DDR memory and it will
not respond to cache snoop request, which will causes system hang
after MMU is enabled.

So we need a new ARM memory region attribute WRITE_BACK_NONSHAREABLE
for flash region on these platforms specifically. This attribute will
set the region as write back but not inner shared.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Peicong Li <lipeicong@huawei.com>

Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPkg/Include/Library/ArmLib.h                  | 7 +++++++
 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 4 ++++
 2 files changed, 11 insertions(+)

-- 
2.7.2.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Ard Biesheuvel Nov. 7, 2017, 1:22 p.m. UTC | #1
On 7 November 2017 at 12:56, Heyi Guo <heyi.guo@linaro.org> wrote:
> From: Peicong Li <lipeicong@huawei.com>

>

> Flash region needs to be set as cacheable (write back) to increase

> performance, if PEI is still XIP on flash or DXE FV is decompressed

> from flash FV. However some ARM platforms do not support to set flash

> as inner shareable since flash is not normal DDR memory and it will

> not respond to cache snoop request, which will causes system hang

> after MMU is enabled.

>

> So we need a new ARM memory region attribute WRITE_BACK_NONSHAREABLE

> for flash region on these platforms specifically. This attribute will

> set the region as write back but not inner shared.

>

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Peicong Li <lipeicong@huawei.com>

> Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

> Cc: Leif Lindholm <leif.lindholm@linaro.org>

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>



> ---

>  ArmPkg/Include/Library/ArmLib.h                  | 7 +++++++

>  ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 4 ++++

>  2 files changed, 11 insertions(+)

>

> diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h

> index 24ffe9f..38199be 100644

> --- a/ArmPkg/Include/Library/ArmLib.h

> +++ b/ArmPkg/Include/Library/ArmLib.h

> @@ -41,6 +41,13 @@ typedef enum {

>    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,

>    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,

>    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,

> +  // On some platforms, memory mapped flash region is designed as not supporting

> +  // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special

> +  // need.

> +  // Do NOT use below two attributes if you are not sure.

> +  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,

> +  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE,

> +

>    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,

>    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,

>    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,

> diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> index 8bd1c6f..4b62ecb 100644

> --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> @@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute (

>    )

>  {

>    switch (Attributes) {

> +  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:

> +  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:

> +    return TT_ATTR_INDX_MEMORY_WRITE_BACK;

> +

>    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:

>    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:

>      return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;

> --

> 2.7.2.windows.1

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Leif Lindholm Nov. 7, 2017, 1:29 p.m. UTC | #2
On Tue, Nov 07, 2017 at 01:22:19PM +0000, Ard Biesheuvel wrote:
> On 7 November 2017 at 12:56, Heyi Guo <heyi.guo@linaro.org> wrote:

> > From: Peicong Li <lipeicong@huawei.com>

> >

> > Flash region needs to be set as cacheable (write back) to increase

> > performance, if PEI is still XIP on flash or DXE FV is decompressed

> > from flash FV. However some ARM platforms do not support to set flash

> > as inner shareable since flash is not normal DDR memory and it will

> > not respond to cache snoop request, which will causes system hang

> > after MMU is enabled.

> >

> > So we need a new ARM memory region attribute WRITE_BACK_NONSHAREABLE

> > for flash region on these platforms specifically. This attribute will

> > set the region as write back but not inner shared.

> >

> > Contributed-under: TianoCore Contribution Agreement 1.1

> > Signed-off-by: Peicong Li <lipeicong@huawei.com>

> > Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

> > Cc: Leif Lindholm <leif.lindholm@linaro.org>

> > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> 

> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


> > ---

> >  ArmPkg/Include/Library/ArmLib.h                  | 7 +++++++

> >  ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 4 ++++

> >  2 files changed, 11 insertions(+)

> >

> > diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h

> > index 24ffe9f..38199be 100644

> > --- a/ArmPkg/Include/Library/ArmLib.h

> > +++ b/ArmPkg/Include/Library/ArmLib.h

> > @@ -41,6 +41,13 @@ typedef enum {

> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,

> >    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,

> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,

> > +  // On some platforms, memory mapped flash region is designed as not supporting

> > +  // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special

> > +  // need.

> > +  // Do NOT use below two attributes if you are not sure.

> > +  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,

> > +  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE,

> > +

> >    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,

> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,

> >    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,

> > diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> > index 8bd1c6f..4b62ecb 100644

> > --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> > +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

> > @@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute (

> >    )

> >  {

> >    switch (Attributes) {

> > +  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:

> > +  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:

> > +    return TT_ATTR_INDX_MEMORY_WRITE_BACK;

> > +

> >    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:

> >    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:

> >      return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;

> > --

> > 2.7.2.windows.1

> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel Nov. 7, 2017, 1:30 p.m. UTC | #3
On 7 November 2017 at 13:29, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Tue, Nov 07, 2017 at 01:22:19PM +0000, Ard Biesheuvel wrote:

>> On 7 November 2017 at 12:56, Heyi Guo <heyi.guo@linaro.org> wrote:

>> > From: Peicong Li <lipeicong@huawei.com>

>> >

>> > Flash region needs to be set as cacheable (write back) to increase

>> > performance, if PEI is still XIP on flash or DXE FV is decompressed

>> > from flash FV. However some ARM platforms do not support to set flash

>> > as inner shareable since flash is not normal DDR memory and it will

>> > not respond to cache snoop request, which will causes system hang

>> > after MMU is enabled.

>> >

>> > So we need a new ARM memory region attribute WRITE_BACK_NONSHAREABLE

>> > for flash region on these platforms specifically. This attribute will

>> > set the region as write back but not inner shared.

>> >

>> > Contributed-under: TianoCore Contribution Agreement 1.1

>> > Signed-off-by: Peicong Li <lipeicong@huawei.com>

>> > Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

>> > Cc: Leif Lindholm <leif.lindholm@linaro.org>

>> > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>>

>> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>

> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

>


Pushed as 829633e3a82d. Thanks!

>> > ---

>> >  ArmPkg/Include/Library/ArmLib.h                  | 7 +++++++

>> >  ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 4 ++++

>> >  2 files changed, 11 insertions(+)

>> >

>> > diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h

>> > index 24ffe9f..38199be 100644

>> > --- a/ArmPkg/Include/Library/ArmLib.h

>> > +++ b/ArmPkg/Include/Library/ArmLib.h

>> > @@ -41,6 +41,13 @@ typedef enum {

>> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,

>> >    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,

>> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,

>> > +  // On some platforms, memory mapped flash region is designed as not supporting

>> > +  // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special

>> > +  // need.

>> > +  // Do NOT use below two attributes if you are not sure.

>> > +  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,

>> > +  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE,

>> > +

>> >    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,

>> >    ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,

>> >    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,

>> > diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

>> > index 8bd1c6f..4b62ecb 100644

>> > --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

>> > +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

>> > @@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute (

>> >    )

>> >  {

>> >    switch (Attributes) {

>> > +  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:

>> > +  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:

>> > +    return TT_ATTR_INDX_MEMORY_WRITE_BACK;

>> > +

>> >    case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:

>> >    case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:

>> >      return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;

>> > --

>> > 2.7.2.windows.1

>> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
gary guo Nov. 8, 2017, 1:56 a.m. UTC | #4
Thanks,

Heyi


在 11/7/2017 9:30 PM, Ard Biesheuvel 写道:
> On 7 November 2017 at 13:29, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>> On Tue, Nov 07, 2017 at 01:22:19PM +0000, Ard Biesheuvel wrote:
>>> On 7 November 2017 at 12:56, Heyi Guo <heyi.guo@linaro.org> wrote:
>>>> From: Peicong Li <lipeicong@huawei.com>
>>>>
>>>> Flash region needs to be set as cacheable (write back) to increase
>>>> performance, if PEI is still XIP on flash or DXE FV is decompressed
>>>> from flash FV. However some ARM platforms do not support to set flash
>>>> as inner shareable since flash is not normal DDR memory and it will
>>>> not respond to cache snoop request, which will causes system hang
>>>> after MMU is enabled.
>>>>
>>>> So we need a new ARM memory region attribute WRITE_BACK_NONSHAREABLE
>>>> for flash region on these platforms specifically. This attribute will
>>>> set the region as write back but not inner shared.
>>>>
>>>> Contributed-under: TianoCore Contribution Agreement 1.1
>>>> Signed-off-by: Peicong Li <lipeicong@huawei.com>
>>>> Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
>>>> Cc: Leif Lindholm <leif.lindholm@linaro.org>
>>>> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>>
> Pushed as 829633e3a82d. Thanks!
>
>>>> ---
>>>>   ArmPkg/Include/Library/ArmLib.h                  | 7 +++++++
>>>>   ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 4 ++++
>>>>   2 files changed, 11 insertions(+)
>>>>
>>>> diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h
>>>> index 24ffe9f..38199be 100644
>>>> --- a/ArmPkg/Include/Library/ArmLib.h
>>>> +++ b/ArmPkg/Include/Library/ArmLib.h
>>>> @@ -41,6 +41,13 @@ typedef enum {
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,
>>>> +  // On some platforms, memory mapped flash region is designed as not supporting
>>>> +  // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special
>>>> +  // need.
>>>> +  // Do NOT use below two attributes if you are not sure.
>>>> +  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,
>>>> +  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE,
>>>> +
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,
>>>>     ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,
>>>> diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
>>>> index 8bd1c6f..4b62ecb 100644
>>>> --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
>>>> +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
>>>> @@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute (
>>>>     )
>>>>   {
>>>>     switch (Attributes) {
>>>> +  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:
>>>> +  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:
>>>> +    return TT_ATTR_INDX_MEMORY_WRITE_BACK;
>>>> +
>>>>     case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:
>>>>     case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:
>>>>       return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;
>>>> --
>>>> 2.7.2.windows.1
>>>>
diff mbox series

Patch

diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h
index 24ffe9f..38199be 100644
--- a/ArmPkg/Include/Library/ArmLib.h
+++ b/ArmPkg/Include/Library/ArmLib.h
@@ -41,6 +41,13 @@  typedef enum {
   ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED,
   ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,
   ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK,
+  // On some platforms, memory mapped flash region is designed as not supporting
+  // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special
+  // need.
+  // Do NOT use below two attributes if you are not sure.
+  ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,
+  ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE,
+
   ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,
   ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH,
   ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,
diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
index 8bd1c6f..4b62ecb 100644
--- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
+++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
@@ -35,6 +35,10 @@  ArmMemoryAttributeToPageAttribute (
   )
 {
   switch (Attributes) {
+  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:
+  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:
+    return TT_ATTR_INDX_MEMORY_WRITE_BACK;
+
   case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:
   case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:
     return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;