Misunderstanding with function cpm_dpalloc in Linux 2.6.x

Laurent Lagrange lagrange at fr.oleane.com
Thu Jan 26 00:48:05 EST 2006


Hello,

I work on MPC boards with Linux 2.6.9 and I have a problem with the
cpm_dpalloc function.

In the file cpm2_common.c the function "uint cpm_dpalloc(uint size, uint
align)" is intended
to allocate a piece of memory in the dpram. This piece of memory has at
least "size" bytes
and I beleived that the returned address should be aligned on "align" bytes.

This function calls "void *rh_alloc(rh_info_t * info, int size, const char
*owner)" from rheap.c file.
In this function the alignment is only used to calculate the right size with
the formula :
size = (size + (info->alignment - 1)) & ~(info->alignment - 1);
It seems to be right but the alignment is not used to retreive an aligned
start address.

So if I do the following sequential calls, I have the following results :
cpm_dpalloc(16, 8)	-> 	0XC0		-> right aligned
cpm_dpalloc(64, 64)	-> 	0XD0		-> wrong aligned -> must be 0x100
cpm_dpalloc(16, 8)	-> 	0X110		-> right aligned but wrong to use
cpm_dpalloc(24, 8)	-> 	0X1200		-> right aligned but wrong to use

I can have the wanted values if instead of size, I try to allocate (size +
align - 1) bytes
but I don't think it is the solution.

Perhaps, I don't understand the allocation theory.
Any idea ?

Thanks all
Laurent





More information about the Linuxppc-embedded mailing list