int prev_valid = 0; struct range { u64 start; u64 end; } prev, curr; void *efi_map_start, *efi_map_end, *p, *q; efi_memory_desc_t *md, *check_md; u64 efi_desc_size, start, end, granule_addr, last_granule_addr, first_non_wb_addr = 0; unsigned long total_mem = 0;  efi_map_start = __va(ia64_boot_param->efi_memmap); efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size; efi_desc_size = ia64_boot_param->efi_memdesc_size;  for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) { md = p;  /* skip over non-WB memory descriptors; that's all we're interested in... */ if (!(md->attribute & EFI_MEMORY_WB)) continue;  /* * granule_addr is the base of md's first granule. * [granule_addr - first_non_wb_addr) is guaranteed to * be contiguous WB memory. */ granule_addr = GRANULEROUNDDOWN(md->phys_addr); first_non_wb_addr = max(first_non_wb_addr, granule_addr);  if (first_non_wb_addr < md->phys_addr) { trim_bottom(md, granule_addr + IA64_GRANULE_SIZE); granule_addr = GRANULEROUNDDOWN(md->phys_addr); first_non_wb_addr = max(first_non_wb_addr, granule_addr); }  for (q = p; q < efi_map_end; q += efi_desc_size) { check_md = q;  if ((check_md->attribute & EFI_MEMORY_WB) && (check_md->phys_addr == first_non_wb_addr)) first_non_wb_addr += check_md->num_pages << EFI_PAGE_SHIFT; else break;		/* non-WB or hole */ }  last_granule_addr = GRANULEROUNDDOWN(first_non_wb_addr); if (last_granule_addr < md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) trim_top(md, last_granule_addr);  if (is_available_memory(md)) { if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) >= max_addr) { if (md->phys_addr >= max_addr) continue; md->num_pages = (max_addr - md->phys_addr) >> EFI_PAGE_SHIFT; first_non_wb_addr = max_addr; }  if (total_mem >= mem_limit) continue;  if (total_mem + (md->num_pages << EFI_PAGE_SHIFT) > mem_limit) { unsigned long limit_addr = md->phys_addr;  limit_addr += mem_limit - total_mem; limit_addr = GRANULEROUNDDOWN(limit_addr);  if (md->phys_addr > limit_addr) continue;  md->num_pages = (limit_addr - md->phys_addr) >> EFI_PAGE_SHIFT; first_non_wb_addr = max_addr = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT); } total_mem += (md->num_pages << EFI_PAGE_SHIFT);  if (md->num_pages == 0) continue;  curr.start = PAGE_OFFSET + md->phys_addr; curr.end   = curr.start + (md->num_pages << EFI_PAGE_SHIFT);  if (!prev_valid) { prev = curr; prev_valid = 1; } else { if (curr.start < prev.start) printk(KERN_ERR "Oops: EFI memory table not ordered!\n");  if (prev.end == curr.start) { /* merge two consecutive memory ranges */ prev.end = curr.end; } else { start = PAGE_ALIGN(prev.start); end = prev.end & PAGE_MASK; if ((end > start) && (*callback)(start, end, arg) < 0) return; prev = curr; } } } } if (prev_valid) { start = PAGE_ALIGN(prev.start); end = prev.end & PAGE_MASK; if (end > start) (*callback)(start, end, arg); } 
walk(callback, arg, EFI_MEMORY_WB); 
efi_memmap_walk (efi_freemem_callback_t callback, void *arg){	int prev_valid = 0;	struct range {		u64 start;		u64 end;	} prev, curr;	void *efi_map_start, *efi_map_end, *p, *q;	efi_memory_desc_t *md, *check_md;	u64 efi_desc_size, start, end, granule_addr, last_granule_addr, first_non_wb_addr = 0;	unsigned long total_mem = 0;	efi_map_start = __va(ia64_boot_param->efi_memmap);	efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;	efi_desc_size = ia64_boot_param->efi_memdesc_size;	for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {		md = p;		/* skip over non-WB memory descriptors; that's all we're interested in... */		if (!(md->attribute & EFI_MEMORY_WB))			continue;		/*		 * granule_addr is the base of md's first granule.		 * [granule_addr - first_non_wb_addr) is guaranteed to		 * be contiguous WB memory.		 */		granule_addr = GRANULEROUNDDOWN(md->phys_addr);		first_non_wb_addr = max(first_non_wb_addr, granule_addr);		if (first_non_wb_addr < md->phys_addr) {			trim_bottom(md, granule_addr + IA64_GRANULE_SIZE);			granule_addr = GRANULEROUNDDOWN(md->phys_addr);			first_non_wb_addr = max(first_non_wb_addr, granule_addr);		}		for (q = p; q < efi_map_end; q += efi_desc_size) {			check_md = q;			if ((check_md->attribute & EFI_MEMORY_WB) &&			    (check_md->phys_addr == first_non_wb_addr))				first_non_wb_addr += check_md->num_pages << EFI_PAGE_SHIFT;			else				break;		/* non-WB or hole */		}		last_granule_addr = GRANULEROUNDDOWN(first_non_wb_addr);		if (last_granule_addr < md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT))			trim_top(md, last_granule_addr);		if (is_available_memory(md)) {			if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) >= max_addr) {				if (md->phys_addr >= max_addr)					continue;				md->num_pages = (max_addr - md->phys_addr) >> EFI_PAGE_SHIFT;				first_non_wb_addr = max_addr;			}			if (total_mem >= mem_limit)				continue;			if (total_mem + (md->num_pages << EFI_PAGE_SHIFT) > mem_limit) {				unsigned long limit_addr = md->phys_addr;				limit_addr += mem_limit - total_mem;				limit_addr = GRANULEROUNDDOWN(limit_addr);				if (md->phys_addr > limit_addr)					continue;				md->num_pages = (limit_addr - md->phys_addr) >>				                EFI_PAGE_SHIFT;				first_non_wb_addr = max_addr = md->phys_addr +				              (md->num_pages << EFI_PAGE_SHIFT);			}			total_mem += (md->num_pages << EFI_PAGE_SHIFT);			if (md->num_pages == 0)				continue;			curr.start = PAGE_OFFSET + md->phys_addr;			curr.end   = curr.start + (md->num_pages << EFI_PAGE_SHIFT);			if (!prev_valid) {				prev = curr;				prev_valid = 1;			} else {				if (curr.start < prev.start)					printk(KERN_ERR "Oops: EFI memory table not ordered!\n");				if (prev.end == curr.start) {					/* merge two consecutive memory ranges */					prev.end = curr.end;				} else {					start = PAGE_ALIGN(prev.start);					end = prev.end & PAGE_MASK;					if ((end > start) && (*callback)(start, end, arg) < 0)						return;					prev = curr;				}			}		}	}	if (prev_valid) {		start = PAGE_ALIGN(prev.start);		end = prev.end & PAGE_MASK;		if (end > start)			(*callback)(start, end, arg);	}}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/d8c97d5f3aa348272df2ccb4e224b1cf9a1eb6d7/efi.c/buggy/arch/ia64/kernel/efi.c