Lines Matching +full:start +full:- +full:up

1 // SPDX-License-Identifier: GPL-2.0-only
12 * Based on kexec-tools' kexec-ppc64.c, kexec-elf-rel-ppc64.c, fs2dt.c.
27 #include <asm/crashdump-ppc64.h>
30 u64 *buf; /* data buffer for usable-memory property */
35 /* usable memory ranges to look up */
46 * get_exclude_memory_ranges - Get exclude memory ranges. This list includes
47 * regions like opal/rtas, tce-table, initrd,
49 * setting up kexec load segments.
95 * get_usable_memory_ranges - Get usable memory ranges. This list includes
96 * regions like crashkernel, opal/rtas & tce-table,
109 * instead of [crashk_res.start, crashk_res.end] to workaround it. in get_usable_memory_ranges()
133 * get_crash_memory_ranges - Get crash memory ranges. This list includes
148 u64 size = end - base; in get_crash_memory_ranges()
154 size -= BACKUP_SRC_SIZE; in get_crash_memory_ranges()
164 if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges) in get_crash_memory_ranges()
170 if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) { in get_crash_memory_ranges()
177 ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end); in get_crash_memory_ranges()
182 * FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL in get_crash_memory_ranges()
184 * crash, they should actually be backed up just like the in get_crash_memory_ranges()
208 * get_reserved_memory_ranges - Get reserve memory ranges. This list includes
236 * __locate_mem_hole_top_down - Looks top down for a large enough memory hole
238 * for the buffer. If found, sets kbuf->mem.
248 int ret = -EADDRNOTAVAIL; in __locate_mem_hole_top_down()
249 phys_addr_t start, end; in __locate_mem_hole_top_down() local
252 for_each_mem_range_rev(i, &start, &end) { in __locate_mem_hole_top_down()
254 * memblock uses [start, end) convention while it is in __locate_mem_hole_top_down()
255 * [start, end] here. Fix the off-by-one to have the in __locate_mem_hole_top_down()
258 end -= 1; in __locate_mem_hole_top_down()
260 if (start > buf_max) in __locate_mem_hole_top_down()
268 if (start < buf_min) in __locate_mem_hole_top_down()
269 start = buf_min; in __locate_mem_hole_top_down()
273 start = ALIGN(start, kbuf->buf_align); in __locate_mem_hole_top_down()
274 if (start < end && (end - start + 1) >= kbuf->memsz) { in __locate_mem_hole_top_down()
275 /* Suitable memory range found. Set kbuf->mem */ in __locate_mem_hole_top_down()
276 kbuf->mem = ALIGN_DOWN(end - kbuf->memsz + 1, in __locate_mem_hole_top_down()
277 kbuf->buf_align); in __locate_mem_hole_top_down()
287 * locate_mem_hole_top_down_ppc64 - Skip special memory regions to find a
300 int i, ret = 0, err = -EADDRNOTAVAIL; in locate_mem_hole_top_down_ppc64()
301 u64 start, end, tmin, tmax; in locate_mem_hole_top_down_ppc64() local
304 for (i = (emem->nr_ranges - 1); i >= 0; i--) { in locate_mem_hole_top_down_ppc64()
305 start = emem->ranges[i].start; in locate_mem_hole_top_down_ppc64()
306 end = emem->ranges[i].end; in locate_mem_hole_top_down_ppc64()
308 if (start > tmax) in locate_mem_hole_top_down_ppc64()
318 tmax = start - 1; in locate_mem_hole_top_down_ppc64()
335 * __locate_mem_hole_bottom_up - Looks bottom up for a large enough memory hole
337 * for the buffer. If found, sets kbuf->mem.
347 int ret = -EADDRNOTAVAIL; in __locate_mem_hole_bottom_up()
348 phys_addr_t start, end; in __locate_mem_hole_bottom_up() local
351 for_each_mem_range(i, &start, &end) { in __locate_mem_hole_bottom_up()
353 * memblock uses [start, end) convention while it is in __locate_mem_hole_bottom_up()
354 * [start, end] here. Fix the off-by-one to have the in __locate_mem_hole_bottom_up()
357 end -= 1; in __locate_mem_hole_bottom_up()
363 if (start > buf_max) in __locate_mem_hole_bottom_up()
367 if (start < buf_min) in __locate_mem_hole_bottom_up()
368 start = buf_min; in __locate_mem_hole_bottom_up()
372 start = ALIGN(start, kbuf->buf_align); in __locate_mem_hole_bottom_up()
373 if (start < end && (end - start + 1) >= kbuf->memsz) { in __locate_mem_hole_bottom_up()
374 /* Suitable memory range found. Set kbuf->mem */ in __locate_mem_hole_bottom_up()
375 kbuf->mem = start; in __locate_mem_hole_bottom_up()
385 * locate_mem_hole_bottom_up_ppc64 - Skip special memory regions to find a
386 * suitable buffer with bottom up approach.
398 int i, ret = 0, err = -EADDRNOTAVAIL; in locate_mem_hole_bottom_up_ppc64()
399 u64 start, end, tmin, tmax; in locate_mem_hole_bottom_up_ppc64() local
402 for (i = 0; i < emem->nr_ranges; i++) { in locate_mem_hole_bottom_up_ppc64()
403 start = emem->ranges[i].start; in locate_mem_hole_bottom_up_ppc64()
404 end = emem->ranges[i].end; in locate_mem_hole_bottom_up_ppc64()
409 if (start > tmin) { in locate_mem_hole_bottom_up_ppc64()
410 tmax = (start > buf_max ? buf_max : start - 1); in locate_mem_hole_bottom_up_ppc64()
433 * check_realloc_usable_mem - Reallocate buffer if it can't accommodate entries
437 * Frees up the old buffer if memory reallocation fails.
446 if ((um_info->idx + cnt) <= um_info->max_entries) in check_realloc_usable_mem()
447 return um_info->buf; in check_realloc_usable_mem()
449 new_size = um_info->size + MEM_RANGE_CHUNK_SZ; in check_realloc_usable_mem()
450 tbuf = krealloc(um_info->buf, new_size, GFP_KERNEL); in check_realloc_usable_mem()
452 um_info->buf = tbuf; in check_realloc_usable_mem()
453 um_info->size = new_size; in check_realloc_usable_mem()
454 um_info->max_entries = (um_info->size / sizeof(u64)); in check_realloc_usable_mem()
461 * add_usable_mem - Add the usable memory ranges within the given memory range
475 for (i = 0; i < um_info->nr_ranges; i++) { in add_usable_mem()
477 loc_base = um_info->ranges[i].start; in add_usable_mem()
478 loc_end = um_info->ranges[i].end; in add_usable_mem()
491 return -ENOMEM; in add_usable_mem()
493 um_info->buf[um_info->idx++] = cpu_to_be64(loc_base); in add_usable_mem()
494 um_info->buf[um_info->idx++] = in add_usable_mem()
495 cpu_to_be64(loc_end - loc_base + 1); in add_usable_mem()
503 * kdump_setup_usable_lmb - This is a callback function that gets called by
507 * @usm: linux,drconf-usable-memory property value.
521 * linux,drconf-usable-memory property. in kdump_setup_usable_lmb()
524 pr_err("linux,drconf-usable-memory property already exists!"); in kdump_setup_usable_lmb()
525 return -EINVAL; in kdump_setup_usable_lmb()
529 tmp_idx = um_info->idx; in kdump_setup_usable_lmb()
531 return -ENOMEM; in kdump_setup_usable_lmb()
533 um_info->idx++; in kdump_setup_usable_lmb()
534 base = lmb->base_addr; in kdump_setup_usable_lmb()
535 end = base + drmem_lmb_size() - 1; in kdump_setup_usable_lmb()
542 um_info->buf[tmp_idx] = in kdump_setup_usable_lmb()
543 cpu_to_be64((um_info->idx - tmp_idx - 1) / 2); in kdump_setup_usable_lmb()
551 * add_usable_mem_property - Add usable memory property for the given
570 if (snprintf(path, NODE_PATH_LEN, "%pOF", dn) > (NODE_PATH_LEN - 1)) { in add_usable_mem_property()
573 return -EOVERFLOW; in add_usable_mem_property()
581 ret = -EINVAL; in add_usable_mem_property()
591 um_info->idx = 0; in add_usable_mem_property()
593 ret = -ENOMEM; in add_usable_mem_property()
612 end = base + of_read_number(prop, n_mem_size_cells) - 1; in add_usable_mem_property()
622 * Write (0,0) tuple in linux,usable-memory property for in add_usable_mem_property()
625 if (um_info->idx == 0) { in add_usable_mem_property()
626 um_info->buf[0] = 0; in add_usable_mem_property()
627 um_info->buf[1] = 0; in add_usable_mem_property()
628 um_info->idx = 2; in add_usable_mem_property()
631 ret = fdt_setprop(fdt, node, "linux,usable-memory", um_info->buf, in add_usable_mem_property()
632 (um_info->idx * sizeof(u64))); in add_usable_mem_property()
641 * update_usable_mem_fdt - Updates kdump kernel's fdt with linux,usable-memory
642 * and linux,drconf-usable-memory DT properties as
657 return -ENOENT; in update_usable_mem_fdt()
660 node = fdt_path_offset(fdt, "/ibm,dynamic-reconfiguration-memory"); in update_usable_mem_fdt()
661 if (node == -FDT_ERR_NOTFOUND) in update_usable_mem_fdt()
664 pr_err("Malformed device tree: error reading /ibm,dynamic-reconfiguration-memory.\n"); in update_usable_mem_fdt()
665 return -EINVAL; in update_usable_mem_fdt()
672 /* Memory ranges to look up */ in update_usable_mem_fdt()
673 um_info.ranges = &(usable_mem->ranges[0]); in update_usable_mem_fdt()
674 um_info.nr_ranges = usable_mem->nr_ranges; in update_usable_mem_fdt()
676 dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); in update_usable_mem_fdt()
682 pr_err("Could not setup linux,drconf-usable-memory property for kdump\n"); in update_usable_mem_fdt()
686 ret = fdt_setprop(fdt, node, "linux,drconf-usable-memory", in update_usable_mem_fdt()
689 pr_err("Failed to update fdt with linux,drconf-usable-memory property"); in update_usable_mem_fdt()
695 * Walk through each memory node and set linux,usable-memory property in update_usable_mem_fdt()
701 pr_err("Failed to set linux,usable-memory property for %s node", in update_usable_mem_fdt()
702 dn->full_name); in update_usable_mem_fdt()
713 * load_backup_segment - Locate a memory hole to place the backup region.
734 return -ENOMEM; in load_backup_segment()
736 kbuf->buffer = buf; in load_backup_segment()
737 kbuf->mem = KEXEC_BUF_MEM_UNKNOWN; in load_backup_segment()
738 kbuf->bufsz = kbuf->memsz = BACKUP_SRC_SIZE; in load_backup_segment()
739 kbuf->top_down = false; in load_backup_segment()
747 image->arch.backup_buf = buf; in load_backup_segment()
748 image->arch.backup_start = kbuf->mem; in load_backup_segment()
753 * update_backup_region_phdr - Update backup region's offset for the core to
769 for (i = 0; i < ehdr->e_phnum; i++) { in update_backup_region_phdr()
770 if (phdr->p_paddr == BACKUP_SRC_START) { in update_backup_region_phdr()
771 phdr->p_offset = image->arch.backup_start; in update_backup_region_phdr()
773 image->arch.backup_start); in update_backup_region_phdr()
780 * load_elfcorehdr_segment - Setup crash memory ranges and initialize elfcorehdr
808 kbuf->buffer = headers; in load_elfcorehdr_segment()
809 kbuf->mem = KEXEC_BUF_MEM_UNKNOWN; in load_elfcorehdr_segment()
810 kbuf->bufsz = kbuf->memsz = headers_sz; in load_elfcorehdr_segment()
811 kbuf->top_down = false; in load_elfcorehdr_segment()
819 image->elf_load_addr = kbuf->mem; in load_elfcorehdr_segment()
820 image->elf_headers_sz = headers_sz; in load_elfcorehdr_segment()
821 image->elf_headers = headers; in load_elfcorehdr_segment()
828 * load_crashdump_segments_ppc64 - Initialize the additional segements needed
840 /* Load backup segment - first 64K bytes of the crashing kernel */ in load_crashdump_segments_ppc64()
846 pr_debug("Loaded the backup region at 0x%lx\n", kbuf->mem); in load_crashdump_segments_ppc64()
848 /* Load elfcorehdr segment - to export crashing kernel's vmcore */ in load_crashdump_segments_ppc64()
855 image->elf_load_addr, kbuf->bufsz, kbuf->memsz); in load_crashdump_segments_ppc64()
861 * setup_purgatory_ppc64 - initialize PPC64 specific purgatory's global
884 if (image->type == KEXEC_TYPE_CRASH) { in setup_purgatory_ppc64()
901 &image->arch.backup_start, in setup_purgatory_ppc64()
902 sizeof(image->arch.backup_start), in setup_purgatory_ppc64()
912 of_property_read_u64(dn, "opal-base-address", &val); in setup_purgatory_ppc64()
918 of_property_read_u64(dn, "opal-entry-address", &val); in setup_purgatory_ppc64()
930 * kexec_extra_fdt_size_ppc64 - Return the estimated additional size needed to
940 if (image->type != KEXEC_TYPE_CRASH) in kexec_extra_fdt_size_ppc64()
944 * For kdump kernel, account for linux,usable-memory and in kexec_extra_fdt_size_ppc64()
945 * linux,drconf-usable-memory properties. Get an approximate on the in kexec_extra_fdt_size_ppc64()
954 * add_node_props - Reads node properties from device node structure and add
968 return -EINVAL; in add_node_props()
971 ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length); in add_node_props()
973 pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret)); in add_node_props()
981 * update_cpus_node - Update cpus node of flattened device tree using of_root
993 if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) { in update_cpus_node()
1003 return -EINVAL; in update_cpus_node()
1011 return -EINVAL; in update_cpus_node()
1023 cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name); in update_cpus_node()
1025 pr_err("Unable to add %s subnode: %s\n", dn->full_name, in update_cpus_node()
1041 * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel
1060 * Restrict memory usage for kdump kernel by setting up in setup_new_fdt_ppc64()
1063 if (image->type == KEXEC_TYPE_CRASH) { in setup_new_fdt_ppc64()
1070 pr_err("Error setting up usable-memory property for kdump kernel\n"); in setup_new_fdt_ppc64()
1076 * first 64K of RAM, which will be backed up. in setup_new_fdt_ppc64()
1079 crashk_res.start - BACKUP_SRC_SIZE); in setup_new_fdt_ppc64()
1087 ret = fdt_add_mem_rsv(fdt, image->arch.backup_start, in setup_new_fdt_ppc64()
1106 nr_ranges = rmem ? rmem->nr_ranges : 0; in setup_new_fdt_ppc64()
1110 base = rmem->ranges[i].start; in setup_new_fdt_ppc64()
1111 size = rmem->ranges[i].end - base + 1; in setup_new_fdt_ppc64()
1127 * arch_kexec_locate_mem_hole - Skip special memory regions like rtas, opal,
1128 * tce-table, reserved-ranges & such (exclude
1130 * segment buffer. Sets kbuf->mem when a suitable
1134 * Assumes minimum of PAGE_SIZE alignment for kbuf->memsz & kbuf->buf_align.
1144 /* Look up the exclude ranges list while locating the memory hole */ in arch_kexec_locate_mem_hole()
1145 emem = &(kbuf->image->arch.exclude_ranges); in arch_kexec_locate_mem_hole()
1146 if (!(*emem) || ((*emem)->nr_ranges == 0)) { in arch_kexec_locate_mem_hole()
1151 buf_min = kbuf->buf_min; in arch_kexec_locate_mem_hole()
1152 buf_max = kbuf->buf_max; in arch_kexec_locate_mem_hole()
1154 if (kbuf->image->type == KEXEC_TYPE_CRASH) { in arch_kexec_locate_mem_hole()
1155 buf_min = (buf_min < crashk_res.start ? in arch_kexec_locate_mem_hole()
1156 crashk_res.start : buf_min); in arch_kexec_locate_mem_hole()
1163 return -EINVAL; in arch_kexec_locate_mem_hole()
1166 if (kbuf->top_down) in arch_kexec_locate_mem_hole()
1175 add_mem_range(emem, kbuf->mem, kbuf->memsz); in arch_kexec_locate_mem_hole()
1179 kbuf->memsz); in arch_kexec_locate_mem_hole()
1185 * arch_kexec_kernel_image_probe - Does additional handling needed to setup
1198 /* Get exclude memory ranges needed for setting up kexec segments */ in arch_kexec_kernel_image_probe()
1199 ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges)); in arch_kexec_kernel_image_probe()
1209 * arch_kimage_file_post_load_cleanup - Frees up all the allocations done
1217 kfree(image->arch.exclude_ranges); in arch_kimage_file_post_load_cleanup()
1218 image->arch.exclude_ranges = NULL; in arch_kimage_file_post_load_cleanup()
1220 vfree(image->arch.backup_buf); in arch_kimage_file_post_load_cleanup()
1221 image->arch.backup_buf = NULL; in arch_kimage_file_post_load_cleanup()
1223 vfree(image->elf_headers); in arch_kimage_file_post_load_cleanup()
1224 image->elf_headers = NULL; in arch_kimage_file_post_load_cleanup()
1225 image->elf_headers_sz = 0; in arch_kimage_file_post_load_cleanup()
1227 kvfree(image->arch.fdt); in arch_kimage_file_post_load_cleanup()
1228 image->arch.fdt = NULL; in arch_kimage_file_post_load_cleanup()