diff mbox

[U-Boot] efi_loader: Always flush in cache line size granularity

Message ID 1460409639-60637-1-git-send-email-agraf@suse.de
State Accepted
Commit 36c37a8481551a6958fd91ccafc6936bf81e00f3
Delegated to: Tom Rini
Headers show

Commit Message

Alexander Graf April 11, 2016, 9:20 p.m. UTC
The cache line flush helpers only work properly when they get aligned
start and end addresses. Round our flush range to cache line size. It's
safe because we're guaranteed to flush within a single page which has the
same cache attributes.

Reported-by: Marek Vasut <marex@denx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - Fix compilation on systems without CONFIG_SYS_CACHELINE_SIZE

Comments

Andreas Färber April 13, 2016, 12:53 p.m. UTC | #1
Am 11.04.2016 um 23:20 schrieb Alexander Graf:
> The cache line flush helpers only work properly when they get aligned
> start and end addresses. Round our flush range to cache line size. It's
> safe because we're guaranteed to flush within a single page which has the
> same cache attributes.
> 
> Reported-by: Marek Vasut <marex@denx.de>
> Signed-off-by: Alexander Graf <agraf@suse.de>

Reviewed-by: Andreas Färber <afaerber@suse.de>
Tested-by: Andreas Färber <afaerber@suse.de>

Thanks,
Andreas
Tom Rini April 21, 2016, 11:22 a.m. UTC | #2
On Mon, Apr 11, 2016 at 11:20:39PM +0200, Alexander Graf wrote:

> The cache line flush helpers only work properly when they get aligned
> start and end addresses. Round our flush range to cache line size. It's
> safe because we're guaranteed to flush within a single page which has the
> same cache attributes.
> 
> Reported-by: Marek Vasut <marex@denx.de>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> Reviewed-by: Andreas Färber <afaerber@suse.de>
> Tested-by: Andreas Färber <afaerber@suse.de>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 22bcd08..3ee27ca 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -20,6 +20,13 @@  static efi_status_t EFI_RUNTIME_TEXT EFIAPI efi_unimplemented(void);
 static efi_status_t EFI_RUNTIME_TEXT EFIAPI efi_device_error(void);
 static efi_status_t EFI_RUNTIME_TEXT EFIAPI efi_invalid_parameter(void);
 
+#ifdef CONFIG_SYS_CACHELINE_SIZE
+#define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
+#else
+/* Just use the greatest cache flush alignment requirement I'm aware of */
+#define EFI_CACHELINE_SIZE 128
+#endif
+
 #if defined(CONFIG_ARM64)
 #define R_RELATIVE	1027
 #define R_MASK		0xffffffffULL
@@ -194,7 +201,8 @@  void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
 #endif
 
 		*p = newaddr;
-		flush_dcache_range((ulong)p, (ulong)&p[1]);
+		flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1),
+			ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE));
 	}
 
 #ifndef IS_RELA