Patchwork [U-Boot,v3,6/6] part_efi: dcache: allocate cacheline aligned buffers

login
register
mail settings
Submitter Anton staaf
Date Oct. 12, 2011, 11:56 p.m.
Message ID <1318463764-28244-7-git-send-email-robotboy@chromium.org>
Download mbox | patch
Permalink /patch/119332/
State Accepted
Commit f75dd584cdfe29dfdcfd424bb237b9238cfb8fe4
Headers show

Comments

Anton staaf - Oct. 12, 2011, 11:56 p.m.
Currently part_efi.c allocates buffers for the gpt_header, the
legacy_mbr, and the pte (partition table entry) that may be
incorrectly aligned for DMA operations.

This patch uses ALLOC_CACHE_ALIGN_BUFFER for the stack allocated
buffers and memalign to replace the malloc of the pte.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 disk/part_efi.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
Mike Frysinger - Oct. 13, 2011, 12:56 a.m.
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
Wolfgang Denk - Oct. 25, 2011, 7:26 a.m.
Dear Anton Staaf,

In message <1318463764-28244-7-git-send-email-robotboy@chromium.org> you wrote:
> Currently part_efi.c allocates buffers for the gpt_header, the
> legacy_mbr, and the pte (partition table entry) that may be
> incorrectly aligned for DMA operations.
> 
> This patch uses ALLOC_CACHE_ALIGN_BUFFER for the stack allocated
> buffers and memalign to replace the malloc of the pte.
> 
> Signed-off-by: Anton Staaf <robotboy@chromium.org>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Mike Frysinger <vapier@gentoo.org>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>  disk/part_efi.c |   18 +++++++++---------
>  1 files changed, 9 insertions(+), 9 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 0a513c6..e591724 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -120,7 +120,7 @@  static char *print_efiname(gpt_entry *pte)
 
 void print_part_efi(block_dev_desc_t * dev_desc)
 {
-	gpt_header gpt_head;
+	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
 	gpt_entry **pgpt_pte = NULL;
 	int i = 0;
 
@@ -130,7 +130,7 @@  void print_part_efi(block_dev_desc_t * dev_desc)
 	}
 	/* This function validates AND fills in the GPT header and PTE */
 	if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
-			 &(gpt_head), pgpt_pte) != 1) {
+			 gpt_head, pgpt_pte) != 1) {
 		printf("%s: *** ERROR: Invalid GPT ***\n", __FUNCTION__);
 		return;
 	}
@@ -138,7 +138,7 @@  void print_part_efi(block_dev_desc_t * dev_desc)
 	debug("%s: gpt-entry at 0x%08X\n", __FUNCTION__, (unsigned int)*pgpt_pte);
 
 	printf("Part\tName\t\t\tStart LBA\tEnd LBA\n");
-	for (i = 0; i < le32_to_int(gpt_head.num_partition_entries); i++) {
+	for (i = 0; i < le32_to_int(gpt_head->num_partition_entries); i++) {
 
 		if (is_pte_valid(&(*pgpt_pte)[i])) {
 			printf("%3d\t%-18s\t0x%08llX\t0x%08llX\n", (i + 1),
@@ -161,7 +161,7 @@  void print_part_efi(block_dev_desc_t * dev_desc)
 int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 				disk_partition_t * info)
 {
-	gpt_header gpt_head;
+	ALLOC_CACHE_ALIGN_BUFFER(gpt_header, gpt_head, 1);
 	gpt_entry **pgpt_pte = NULL;
 
 	/* "part" argument must be at least 1 */
@@ -172,7 +172,7 @@  int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
 	/* This function validates AND fills in the GPT header and PTE */
 	if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
-			&(gpt_head), pgpt_pte) != 1) {
+			 gpt_head, pgpt_pte) != 1) {
 		printf("%s: *** ERROR: Invalid GPT ***\n", __FUNCTION__);
 		return -1;
 	}
@@ -201,11 +201,11 @@  int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
 int test_part_efi(block_dev_desc_t * dev_desc)
 {
-	legacy_mbr legacymbr;
+	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, legacymbr, 1);
 
 	/* Read legacy MBR from block 0 and validate it */
-	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) & legacymbr) != 1)
-		|| (is_pmbr_valid(&legacymbr) != 1)) {
+	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)legacymbr) != 1)
+		|| (is_pmbr_valid(legacymbr) != 1)) {
 		return -1;
 	}
 	return 0;
@@ -388,7 +388,7 @@  static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
 	/* Allocate memory for PTE, remember to FREE */
 	if (count != 0) {
-		pte = malloc(count);
+		pte = memalign(CONFIG_SYS_CACHELINE_SIZE, count);
 	}
 
 	if (count == 0 || pte == NULL) {