[PATCH 3/5] powerpc: booke: Remove code duplication in lowmem mapping

Kumar Gala galak at kernel.crashing.org
Thu Jan 8 03:13:53 EST 2009


>
> void __init
> adjust_total_lowmem(void)
> {
> -	phys_addr_t max_lowmem_size = __max_low_memory;
> -	phys_addr_t cam_max_size = 0x10000000;
> 	phys_addr_t ram;
> +	unsigned int max_cam = 28;	/* 2^28 = 256 Mb */
> +	char buf[ARRAY_SIZE(cam) * 5 + 1], *p = buf;
> +	int i;
>
> -	/* adjust CAM size to max_lowmem_size */
> -	if (max_lowmem_size < cam_max_size)
> -		cam_max_size = max_lowmem_size;
> -
> -	/* adjust lowmem size to max_lowmem_size */
> -	ram = min(max_lowmem_size, total_lowmem);
> +	/* adjust lowmem size to __max_low_memory */
> +	ram = min((phys_addr_t)__max_low_memory, (phys_addr_t)total_lowmem);
>
> 	/* Calculate CAM values */
> -	__cam0 = 1UL << 2 * (__ilog2(ram) / 2);
> -	if (__cam0 > cam_max_size)
> -		__cam0 = cam_max_size;
> -	ram -= __cam0;
> -	if (ram) {
> -		__cam1 = 1UL << 2 * (__ilog2(ram) / 2);
> -		if (__cam1 > cam_max_size)
> -			__cam1 = cam_max_size;
> -		ram -= __cam1;
> -	}
> -	if (ram) {
> -		__cam2 = 1UL << 2 * (__ilog2(ram) / 2);
> -		if (__cam2 > cam_max_size)
> -			__cam2 = cam_max_size;
> -		ram -= __cam2;
> +	__max_low_memory = 0;
> +	for (i = 0; ram && i < ARRAY_SIZE(cam); i++) {
> +		unsigned int camsize = __ilog2(ram) & ~1U;
> +		if (camsize > max_cam)
> +			camsize = max_cam;
> +		cam[i] = 1UL << camsize;
> +		ram -= cam[i];
> +		__max_low_memory += cam[i];
> +
> +		p += sprintf(p, "%lu/", cam[i] >> 20);
> 	}
> +	for (; i < ARRAY_SIZE(cam); i++)
> +		p += sprintf(p, "0/");
> +	p[-1] = '\0';

this all seems like overkill.  Can we use string_get_size() from lib/ 
string_helpers.c and just printf in a loop?

> -	printk(KERN_INFO "Memory CAM mapping: CAM0=%ldMb, CAM1=%ldMb,"
> -			" CAM2=%ldMb residual: %ldMb\n",
> -			__cam0 >> 20, __cam1 >> 20, __cam2 >> 20,
> -			(long int)((total_lowmem - __cam0 - __cam1 - __cam2)
> -				   >> 20));
> -	__max_low_memory = __cam0 + __cam1 + __cam2;
> +	pr_info("Memory CAM mapping: %s Mb, residual: %ldMb\n", buf,
> +	        (total_lowmem - __max_low_memory) >> 20);
> 	__initial_memory_limit_addr = memstart_addr + __max_low_memory;
> }

- k




More information about the Linuxppc-dev mailing list