diff mbox

[U-Boot] FAT: Properly align buffers to allow cache operations

Message ID 1333953903-26335-1-git-send-email-marex@denx.de
State Rejected
Headers show

Commit Message

Marek Vasut April 9, 2012, 6:45 a.m. UTC
Align the FAT FS buffers so DMA on various systems can directly pick them.

Signed-off-by: Marek Vasut <marex@denx.de>
---
 fs/fat/fat.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

Comments

Dirk Behme April 9, 2012, 8:20 a.m. UTC | #1
On 09.04.2012 08:45, Marek Vasut wrote:
> Align the FAT FS buffers so DMA on various systems can directly pick them.

Just fyi:

http://lists.denx.de/pipermail/u-boot/2012-March/119311.html

http://lists.denx.de/pipermail/u-boot/2012-March/119309.html

Best regards

Dirk

> Signed-off-by: Marek Vasut<marex@denx.de>
> ---
>   fs/fat/fat.c |   12 ++++++------
>   1 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 1f95eb4..d709e59 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -31,6 +31,7 @@
>   #include<fat.h>
>   #include<asm/byteorder.h>
>   #include<part.h>
> +#include<malloc.h>
>
>   /*
>    * Convert a string to lowercase.
> @@ -62,7 +63,7 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
>
>   int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
>   {
> -	unsigned char buffer[dev_desc->blksz];
> +	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
>
>   	/* First close any currently found FAT filesystem */
>   	cur_dev = NULL;
> @@ -293,9 +294,10 @@ get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
>   		return -1;
>   	}
>   	if (size % mydata->sect_size) {
> -		__u8 tmpbuf[mydata->sect_size];
> +		ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, mydata->sect_size);
>
>   		idx = size / mydata->sect_size;
> +
>   		ret = disk_read(startsect + idx, 1, tmpbuf);
>   		if (ret != 1) {
>   			debug("Error reading data (got %d)\n", ret);
> @@ -709,7 +711,7 @@ read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
>   		return -1;
>   	}
>
> -	block = malloc(cur_dev->blksz);
> +	block = memalign(ARCH_DMA_MINALIGN, cur_dev->blksz);
>   	if (block == NULL) {
>   		debug("Error: allocating block\n");
>   		return -1;
> @@ -765,9 +767,6 @@ exit:
>   	return ret;
>   }
>
> -__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
> -__u8 do_fat_read_block[MAX_CLUSTSIZE];
> -
>   long
>   do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
>   	     int dols)
> @@ -788,6 +787,7 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
>   	__u32 root_cluster = 0;
>   	int rootdir_size = 0;
>   	int j;
> +	uint8_t do_fat_read_block[MAX_CLUSTSIZE] __attribute__((aligned(32)));
>
>   	if (read_bootsectandvi(&bs,&volinfo,&mydata->fatsize)) {
>   		debug("Error: reading boot sector\n");
Marek Vasut April 9, 2012, 8:26 a.m. UTC | #2
Dear Dirk Behme,

> On 09.04.2012 08:45, Marek Vasut wrote:
> > Align the FAT FS buffers so DMA on various systems can directly pick
> > them.
> 
> Just fyi:
> 
> http://lists.denx.de/pipermail/u-boot/2012-March/119311.html
> 
> http://lists.denx.de/pipermail/u-boot/2012-March/119309.html

Heh, nice! :-)

I've been so dug up in debugging the USB cache issues I didn't bother to look 
around the list for previous efforts. So obviously, apply Eric's patch! :-)

> Best regards
> 
> Dirk
> 

Best regards,
Marek Vasut
Dirk Behme April 9, 2012, 10:28 a.m. UTC | #3
On 09.04.2012 10:26, Marek Vasut wrote:
> Dear Dirk Behme,
>
>> On 09.04.2012 08:45, Marek Vasut wrote:
>>> Align the FAT FS buffers so DMA on various systems can directly pick
>>> them.
>>
>> Just fyi:
>>
>> http://lists.denx.de/pipermail/u-boot/2012-March/119311.html
>>
>> http://lists.denx.de/pipermail/u-boot/2012-March/119309.html
>
> Heh, nice! :-)
>
> I've been so dug up in debugging the USB cache issues I didn't bother to look
> around the list for previous efforts. So obviously, apply Eric's patch! :-)

Do you need this for 2012.04? Or is the stuff which needs this 
scheduled for -next?

Best regards

Dirk
Marek Vasut April 9, 2012, 10:44 a.m. UTC | #4
Dear Dirk Behme,

> On 09.04.2012 10:26, Marek Vasut wrote:
> > Dear Dirk Behme,
> > 
> >> On 09.04.2012 08:45, Marek Vasut wrote:
> >>> Align the FAT FS buffers so DMA on various systems can directly pick
> >>> them.
> >> 
> >> Just fyi:
> >> 
> >> http://lists.denx.de/pipermail/u-boot/2012-March/119311.html
> >> 
> >> http://lists.denx.de/pipermail/u-boot/2012-March/119309.html
> > 
> > Heh, nice! :-)
> > 
> > I've been so dug up in debugging the USB cache issues I didn't bother to
> > look around the list for previous efforts. So obviously, apply Eric's
> > patch! :-)
> 
> Do you need this for 2012.04? Or is the stuff which needs this
> scheduled for -next?

Definitelly -next, we're on -RC1 now, close to RC2.

> 
> Best regards
> 
> Dirk

Best regards,
Marek Vasut
Mike Frysinger April 10, 2012, 4:36 a.m. UTC | #5
On Monday 09 April 2012 02:45:03 Marek Vasut wrote:
> @@ -765,9 +767,6 @@
> 
> -__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
> -__u8 do_fat_read_block[MAX_CLUSTSIZE];
> -
>
> @@ -788,6 +787,7 @@ do_fat_read (const char *filename, void *buffer,
>
>  	int rootdir_size = 0;
>  	int j;
> +	uint8_t do_fat_read_block[MAX_CLUSTSIZE] __attribute__((aligned(32)));

what's going on here exactly ?  the old code had the advantage of being in the 
bss and the linker taking care of the alignment.  this new code has an 
incorrectly hard-coded "32", and puts a 64KiB array onto the *stack*.
-mike
Marek Vasut April 10, 2012, 5 a.m. UTC | #6
Dear Mike Frysinger,

> On Monday 09 April 2012 02:45:03 Marek Vasut wrote:
> > @@ -765,9 +767,6 @@
> > 
> > -__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
> > -__u8 do_fat_read_block[MAX_CLUSTSIZE];
> > -
> > 
> > @@ -788,6 +787,7 @@ do_fat_read (const char *filename, void *buffer,
> > 
> >  	int rootdir_size = 0;
> >  	int j;
> > 
> > +	uint8_t do_fat_read_block[MAX_CLUSTSIZE] __attribute__((aligned(32)));
> 
> what's going on here exactly ?  the old code had the advantage of being in
> the bss and the linker taking care of the alignment.  this new code has an
> incorrectly hard-coded "32", and puts a 64KiB array onto the *stack*.

This will be probably fixed in Eric's patch

Best regards,
Marek Vasut
Eric Nelson April 10, 2012, 3:07 p.m. UTC | #7
On 04/09/2012 10:00 PM, Marek Vasut wrote:
> Dear Mike Frysinger,
>
>> On Monday 09 April 2012 02:45:03 Marek Vasut wrote:
>>> @@ -765,9 +767,6 @@
>>>
>>> -__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
>>> -__u8 do_fat_read_block[MAX_CLUSTSIZE];
>>> -
>>>
>>> @@ -788,6 +787,7 @@ do_fat_read (const char *filename, void *buffer,
>>>
>>>   	int rootdir_size = 0;
>>>   	int j;
>>>
>>> +	uint8_t do_fat_read_block[MAX_CLUSTSIZE] __attribute__((aligned(32)));
>>
>> what's going on here exactly ?  the old code had the advantage of being in
>> the bss and the linker taking care of the alignment.  this new code has an
>> incorrectly hard-coded "32", and puts a 64KiB array onto the *stack*.
>
> This will be probably fixed in Eric's patch
>
Yep. I left it in bss space.
Dirk Behme April 10, 2012, 4:20 p.m. UTC | #8
On 10.04.2012 17:07, Eric Nelson wrote:
> On 04/09/2012 10:00 PM, Marek Vasut wrote:
>> Dear Mike Frysinger,
>>
>>> On Monday 09 April 2012 02:45:03 Marek Vasut wrote:
>>>> @@ -765,9 +767,6 @@
>>>>
>>>> -__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
>>>> -__u8 do_fat_read_block[MAX_CLUSTSIZE];
>>>> -
>>>>
>>>> @@ -788,6 +787,7 @@ do_fat_read (const char *filename, void *buffer,
>>>>
>>>> int rootdir_size = 0;
>>>> int j;
>>>>
>>>> + uint8_t do_fat_read_block[MAX_CLUSTSIZE]
>>>> __attribute__((aligned(32)));
>>>
>>> what's going on here exactly ? the old code had the advantage of
>>> being in
>>> the bss and the linker taking care of the alignment. this new code
>>> has an
>>> incorrectly hard-coded "32", and puts a 64KiB array onto the *stack*.
>>
>> This will be probably fixed in Eric's patch
>>
> Yep. I left it in bss space.

Sorry guys, but I'm confused now.

We have two patches, Eric's [1] and Marek's [2]. Which one should we 
take? With the discussion here and [3] I'm somehow under the 
impression that both patches [1] [2] are not complete?

Do I miss anything? Or do we need a new version ("best of [1] & [2]")?

Best regards

Dirk

[1] http://lists.denx.de/pipermail/u-boot/2012-March/119311.html

[2] http://lists.denx.de/pipermail/u-boot/2012-April/122100.html

[3] http://lists.denx.de/pipermail/u-boot/2012-April/122126.html
Wolfgang Denk April 10, 2012, 8:34 p.m. UTC | #9
Dear Dirk,

In message <4F845DB6.7050002@googlemail.com> you wrote:
>
> Sorry guys, but I'm confused now.

Heh.  Me too ;-)

> We have two patches, Eric's [1] and Marek's [2]. Which one should we 
> take? With the discussion here and [3] I'm somehow under the 
> impression that both patches [1] [2] are not complete?
> 
> Do I miss anything? Or do we need a new version ("best of [1] & [2]")?

I'm waiting for Eric to post an updated patch that includes 1+2+3.

Best regards,

Wolfgang Denk
Eric Nelson April 10, 2012, 11:13 p.m. UTC | #10
On 04/10/2012 01:34 PM, Wolfgang Denk wrote:
> Dear Dirk,
>
> In message<4F845DB6.7050002@googlemail.com>  you wrote:
>>
>> Sorry guys, but I'm confused now.
>
> Heh.  Me too ;-)
>
>> We have two patches, Eric's [1] and Marek's [2]. Which one should we
>> take? With the discussion here and [3] I'm somehow under the
>> impression that both patches [1] [2] are not complete?
>>
>> Do I miss anything? Or do we need a new version ("best of [1]&  [2]")?
>
> I'm waiting for Eric to post an updated patch that includes 1+2+3.
>

I guess I had better get busy ;)

I can probably handle 1 and 2 and my guess is that #3 will appear with
a fresh re-read of the code.

I should be able to get this out in the A.M. (Arizona time).

Regards,


Eric
diff mbox

Patch

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 1f95eb4..d709e59 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -31,6 +31,7 @@ 
 #include <fat.h>
 #include <asm/byteorder.h>
 #include <part.h>
+#include <malloc.h>
 
 /*
  * Convert a string to lowercase.
@@ -62,7 +63,7 @@  static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
 
 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
 {
-	unsigned char buffer[dev_desc->blksz];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 
 	/* First close any currently found FAT filesystem */
 	cur_dev = NULL;
@@ -293,9 +294,10 @@  get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
 		return -1;
 	}
 	if (size % mydata->sect_size) {
-		__u8 tmpbuf[mydata->sect_size];
+		ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, mydata->sect_size);
 
 		idx = size / mydata->sect_size;
+
 		ret = disk_read(startsect + idx, 1, tmpbuf);
 		if (ret != 1) {
 			debug("Error reading data (got %d)\n", ret);
@@ -709,7 +711,7 @@  read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
 		return -1;
 	}
 
-	block = malloc(cur_dev->blksz);
+	block = memalign(ARCH_DMA_MINALIGN, cur_dev->blksz);
 	if (block == NULL) {
 		debug("Error: allocating block\n");
 		return -1;
@@ -765,9 +767,6 @@  exit:
 	return ret;
 }
 
-__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
-__u8 do_fat_read_block[MAX_CLUSTSIZE];
-
 long
 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 	     int dols)
@@ -788,6 +787,7 @@  do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 	__u32 root_cluster = 0;
 	int rootdir_size = 0;
 	int j;
+	uint8_t do_fat_read_block[MAX_CLUSTSIZE] __attribute__((aligned(32)));
 
 	if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
 		debug("Error: reading boot sector\n");