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.
28 #include <asm/crashdump-ppc64.h>
31 u64 *buf; /* data buffer for usable-memory property */
36 /* usable memory ranges to look up */
47 * get_exclude_memory_ranges - Get exclude memory ranges. This list includes
48 * regions like opal/rtas, tce-table, initrd,
50 * setting up kexec load segments.
96 * get_usable_memory_ranges - Get usable memory ranges. This list includes
97 * regions like crashkernel, opal/rtas & tce-table,
110 * instead of [crashk_res.start, crashk_res.end] to workaround it. in get_usable_memory_ranges()
134 * get_crash_memory_ranges - Get crash memory ranges. This list includes
149 u64 size = end - base; in get_crash_memory_ranges()
155 size -= BACKUP_SRC_SIZE; in get_crash_memory_ranges()
165 if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges) in get_crash_memory_ranges()
171 if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) { in get_crash_memory_ranges()
178 ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end); in get_crash_memory_ranges()
183 * FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL in get_crash_memory_ranges()
185 * crash, they should actually be backed up just like the in get_crash_memory_ranges()
209 * get_reserved_memory_ranges - Get reserve memory ranges. This list includes
237 * __locate_mem_hole_top_down - Looks top down for a large enough memory hole
239 * for the buffer. If found, sets kbuf->mem.
249 int ret = -EADDRNOTAVAIL; in __locate_mem_hole_top_down()
250 phys_addr_t start, end; in __locate_mem_hole_top_down() local
253 for_each_mem_range_rev(i, &start, &end) { in __locate_mem_hole_top_down()
255 * memblock uses [start, end) convention while it is in __locate_mem_hole_top_down()
256 * [start, end] here. Fix the off-by-one to have the in __locate_mem_hole_top_down()
259 end -= 1; in __locate_mem_hole_top_down()
261 if (start > buf_max) in __locate_mem_hole_top_down()
269 if (start < buf_min) in __locate_mem_hole_top_down()
270 start = buf_min; in __locate_mem_hole_top_down()
274 start = ALIGN(start, kbuf->buf_align); in __locate_mem_hole_top_down()
275 if (start < end && (end - start + 1) >= kbuf->memsz) { in __locate_mem_hole_top_down()
276 /* Suitable memory range found. Set kbuf->mem */ in __locate_mem_hole_top_down()
277 kbuf->mem = ALIGN_DOWN(end - kbuf->memsz + 1, in __locate_mem_hole_top_down()
278 kbuf->buf_align); in __locate_mem_hole_top_down()
288 * locate_mem_hole_top_down_ppc64 - Skip special memory regions to find a
301 int i, ret = 0, err = -EADDRNOTAVAIL; in locate_mem_hole_top_down_ppc64()
302 u64 start, end, tmin, tmax; in locate_mem_hole_top_down_ppc64() local
305 for (i = (emem->nr_ranges - 1); i >= 0; i--) { in locate_mem_hole_top_down_ppc64()
306 start = emem->ranges[i].start; in locate_mem_hole_top_down_ppc64()
307 end = emem->ranges[i].end; in locate_mem_hole_top_down_ppc64()
309 if (start > tmax) in locate_mem_hole_top_down_ppc64()
319 tmax = start - 1; in locate_mem_hole_top_down_ppc64()
336 * __locate_mem_hole_bottom_up - Looks bottom up for a large enough memory hole
338 * for the buffer. If found, sets kbuf->mem.
348 int ret = -EADDRNOTAVAIL; in __locate_mem_hole_bottom_up()
349 phys_addr_t start, end; in __locate_mem_hole_bottom_up() local
352 for_each_mem_range(i, &start, &end) { in __locate_mem_hole_bottom_up()
354 * memblock uses [start, end) convention while it is in __locate_mem_hole_bottom_up()
355 * [start, end] here. Fix the off-by-one to have the in __locate_mem_hole_bottom_up()
358 end -= 1; in __locate_mem_hole_bottom_up()
364 if (start > buf_max) in __locate_mem_hole_bottom_up()
368 if (start < buf_min) in __locate_mem_hole_bottom_up()
369 start = buf_min; in __locate_mem_hole_bottom_up()
373 start = ALIGN(start, kbuf->buf_align); in __locate_mem_hole_bottom_up()
374 if (start < end && (end - start + 1) >= kbuf->memsz) { in __locate_mem_hole_bottom_up()
375 /* Suitable memory range found. Set kbuf->mem */ in __locate_mem_hole_bottom_up()
376 kbuf->mem = start; in __locate_mem_hole_bottom_up()
386 * locate_mem_hole_bottom_up_ppc64 - Skip special memory regions to find a
387 * suitable buffer with bottom up approach.
399 int i, ret = 0, err = -EADDRNOTAVAIL; in locate_mem_hole_bottom_up_ppc64()
400 u64 start, end, tmin, tmax; in locate_mem_hole_bottom_up_ppc64() local
403 for (i = 0; i < emem->nr_ranges; i++) { in locate_mem_hole_bottom_up_ppc64()
404 start = emem->ranges[i].start; in locate_mem_hole_bottom_up_ppc64()
405 end = emem->ranges[i].end; in locate_mem_hole_bottom_up_ppc64()
410 if (start > tmin) { in locate_mem_hole_bottom_up_ppc64()
411 tmax = (start > buf_max ? buf_max : start - 1); in locate_mem_hole_bottom_up_ppc64()
434 * check_realloc_usable_mem - Reallocate buffer if it can't accommodate entries
438 * Frees up the old buffer if memory reallocation fails.
447 if ((um_info->idx + cnt) <= um_info->max_entries) in check_realloc_usable_mem()
448 return um_info->buf; in check_realloc_usable_mem()
450 new_size = um_info->size + MEM_RANGE_CHUNK_SZ; in check_realloc_usable_mem()
451 tbuf = krealloc(um_info->buf, new_size, GFP_KERNEL); in check_realloc_usable_mem()
453 um_info->buf = tbuf; in check_realloc_usable_mem()
454 um_info->size = new_size; in check_realloc_usable_mem()
455 um_info->max_entries = (um_info->size / sizeof(u64)); in check_realloc_usable_mem()
462 * add_usable_mem - Add the usable memory ranges within the given memory range
476 for (i = 0; i < um_info->nr_ranges; i++) { in add_usable_mem()
478 loc_base = um_info->ranges[i].start; in add_usable_mem()
479 loc_end = um_info->ranges[i].end; in add_usable_mem()
492 return -ENOMEM; in add_usable_mem()
494 um_info->buf[um_info->idx++] = cpu_to_be64(loc_base); in add_usable_mem()
495 um_info->buf[um_info->idx++] = in add_usable_mem()
496 cpu_to_be64(loc_end - loc_base + 1); in add_usable_mem()
504 * kdump_setup_usable_lmb - This is a callback function that gets called by
508 * @usm: linux,drconf-usable-memory property value.
522 * linux,drconf-usable-memory property. in kdump_setup_usable_lmb()
525 pr_err("linux,drconf-usable-memory property already exists!"); in kdump_setup_usable_lmb()
526 return -EINVAL; in kdump_setup_usable_lmb()
530 tmp_idx = um_info->idx; in kdump_setup_usable_lmb()
532 return -ENOMEM; in kdump_setup_usable_lmb()
534 um_info->idx++; in kdump_setup_usable_lmb()
535 base = lmb->base_addr; in kdump_setup_usable_lmb()
536 end = base + drmem_lmb_size() - 1; in kdump_setup_usable_lmb()
543 um_info->buf[tmp_idx] = in kdump_setup_usable_lmb()
544 cpu_to_be64((um_info->idx - tmp_idx - 1) / 2); in kdump_setup_usable_lmb()
552 * add_usable_mem_property - Add usable memory property for the given
571 if (snprintf(path, NODE_PATH_LEN, "%pOF", dn) > (NODE_PATH_LEN - 1)) { in add_usable_mem_property()
574 return -EOVERFLOW; in add_usable_mem_property()
582 ret = -EINVAL; in add_usable_mem_property()
592 um_info->idx = 0; in add_usable_mem_property()
594 ret = -ENOMEM; in add_usable_mem_property()
613 end = base + of_read_number(prop, n_mem_size_cells) - 1; in add_usable_mem_property()
623 * Write (0,0) tuple in linux,usable-memory property for in add_usable_mem_property()
626 if (um_info->idx == 0) { in add_usable_mem_property()
627 um_info->buf[0] = 0; in add_usable_mem_property()
628 um_info->buf[1] = 0; in add_usable_mem_property()
629 um_info->idx = 2; in add_usable_mem_property()
632 ret = fdt_setprop(fdt, node, "linux,usable-memory", um_info->buf, in add_usable_mem_property()
633 (um_info->idx * sizeof(u64))); in add_usable_mem_property()
642 * update_usable_mem_fdt - Updates kdump kernel's fdt with linux,usable-memory
643 * and linux,drconf-usable-memory DT properties as
658 return -ENOENT; in update_usable_mem_fdt()
661 node = fdt_path_offset(fdt, "/ibm,dynamic-reconfiguration-memory"); in update_usable_mem_fdt()
662 if (node == -FDT_ERR_NOTFOUND) in update_usable_mem_fdt()
665 pr_err("Malformed device tree: error reading /ibm,dynamic-reconfiguration-memory.\n"); in update_usable_mem_fdt()
666 return -EINVAL; in update_usable_mem_fdt()
673 /* Memory ranges to look up */ in update_usable_mem_fdt()
674 um_info.ranges = &(usable_mem->ranges[0]); in update_usable_mem_fdt()
675 um_info.nr_ranges = usable_mem->nr_ranges; in update_usable_mem_fdt()
677 dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); in update_usable_mem_fdt()
683 pr_err("Could not setup linux,drconf-usable-memory property for kdump\n"); in update_usable_mem_fdt()
687 ret = fdt_setprop(fdt, node, "linux,drconf-usable-memory", in update_usable_mem_fdt()
690 pr_err("Failed to update fdt with linux,drconf-usable-memory property"); in update_usable_mem_fdt()
696 * Walk through each memory node and set linux,usable-memory property in update_usable_mem_fdt()
702 pr_err("Failed to set linux,usable-memory property for %s node", in update_usable_mem_fdt()
703 dn->full_name); in update_usable_mem_fdt()
715 * load_backup_segment - Locate a memory hole to place the backup region.
736 return -ENOMEM; in load_backup_segment()
738 kbuf->buffer = buf; in load_backup_segment()
739 kbuf->mem = KEXEC_BUF_MEM_UNKNOWN; in load_backup_segment()
740 kbuf->bufsz = kbuf->memsz = BACKUP_SRC_SIZE; in load_backup_segment()
741 kbuf->top_down = false; in load_backup_segment()
749 image->arch.backup_buf = buf; in load_backup_segment()
750 image->arch.backup_start = kbuf->mem; in load_backup_segment()
755 * update_backup_region_phdr - Update backup region's offset for the core to
771 for (i = 0; i < ehdr->e_phnum; i++) { in update_backup_region_phdr()
772 if (phdr->p_paddr == BACKUP_SRC_START) { in update_backup_region_phdr()
773 phdr->p_offset = image->arch.backup_start; in update_backup_region_phdr()
775 image->arch.backup_start); in update_backup_region_phdr()
782 * load_elfcorehdr_segment - Setup crash memory ranges and initialize elfcorehdr
810 kbuf->buffer = headers; in load_elfcorehdr_segment()
811 kbuf->mem = KEXEC_BUF_MEM_UNKNOWN; in load_elfcorehdr_segment()
812 kbuf->bufsz = kbuf->memsz = headers_sz; in load_elfcorehdr_segment()
813 kbuf->top_down = false; in load_elfcorehdr_segment()
821 image->elf_load_addr = kbuf->mem; in load_elfcorehdr_segment()
822 image->elf_headers_sz = headers_sz; in load_elfcorehdr_segment()
823 image->elf_headers = headers; in load_elfcorehdr_segment()
830 * load_crashdump_segments_ppc64 - Initialize the additional segements needed
842 /* Load backup segment - first 64K bytes of the crashing kernel */ in load_crashdump_segments_ppc64()
848 pr_debug("Loaded the backup region at 0x%lx\n", kbuf->mem); in load_crashdump_segments_ppc64()
850 /* Load elfcorehdr segment - to export crashing kernel's vmcore */ in load_crashdump_segments_ppc64()
857 image->elf_load_addr, kbuf->bufsz, kbuf->memsz); in load_crashdump_segments_ppc64()
863 * setup_purgatory_ppc64 - initialize PPC64 specific purgatory's global
886 if (image->type == KEXEC_TYPE_CRASH) { in setup_purgatory_ppc64()
903 &image->arch.backup_start, in setup_purgatory_ppc64()
904 sizeof(image->arch.backup_start), in setup_purgatory_ppc64()
914 of_property_read_u64(dn, "opal-base-address", &val); in setup_purgatory_ppc64()
920 of_property_read_u64(dn, "opal-entry-address", &val); in setup_purgatory_ppc64()
932 * kexec_extra_fdt_size_ppc64 - Return the estimated additional size needed to
942 if (image->type != KEXEC_TYPE_CRASH) in kexec_extra_fdt_size_ppc64()
946 * For kdump kernel, account for linux,usable-memory and in kexec_extra_fdt_size_ppc64()
947 * linux,drconf-usable-memory properties. Get an approximate on the in kexec_extra_fdt_size_ppc64()
956 * add_node_props - Reads node properties from device node structure and add
970 return -EINVAL; in add_node_props()
973 ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length); in add_node_props()
975 pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret)); in add_node_props()
983 * update_cpus_node - Update cpus node of flattened device tree using of_root
995 if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) { in update_cpus_node()
1005 return -EINVAL; in update_cpus_node()
1013 return -EINVAL; in update_cpus_node()
1025 cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name); in update_cpus_node()
1027 pr_err("Unable to add %s subnode: %s\n", dn->full_name, in update_cpus_node()
1056 return -FDT_ERR_NOTFOUND; in copy_property()
1073 ret = copy_property(fdt, pci_offset, dn, "ibm,dma-window"); in update_pci_dma_nodes()
1085 * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel
1104 * Restrict memory usage for kdump kernel by setting up in setup_new_fdt_ppc64()
1107 if (image->type == KEXEC_TYPE_CRASH) { in setup_new_fdt_ppc64()
1114 pr_err("Error setting up usable-memory property for kdump kernel\n"); in setup_new_fdt_ppc64()
1120 * first 64K of RAM, which will be backed up. in setup_new_fdt_ppc64()
1123 crashk_res.start - BACKUP_SRC_SIZE); in setup_new_fdt_ppc64()
1131 ret = fdt_add_mem_rsv(fdt, image->arch.backup_start, in setup_new_fdt_ppc64()
1145 #define DIRECT64_PROPNAME "linux,direct64-ddr-window-info" in setup_new_fdt_ppc64()
1146 #define DMA64_PROPNAME "linux,dma64-ddr-window-info" in setup_new_fdt_ppc64()
1162 nr_ranges = rmem ? rmem->nr_ranges : 0; in setup_new_fdt_ppc64()
1166 base = rmem->ranges[i].start; in setup_new_fdt_ppc64()
1167 size = rmem->ranges[i].end - base + 1; in setup_new_fdt_ppc64()
1183 * arch_kexec_locate_mem_hole - Skip special memory regions like rtas, opal,
1184 * tce-table, reserved-ranges & such (exclude
1186 * segment buffer. Sets kbuf->mem when a suitable
1190 * Assumes minimum of PAGE_SIZE alignment for kbuf->memsz & kbuf->buf_align.
1200 /* Look up the exclude ranges list while locating the memory hole */ in arch_kexec_locate_mem_hole()
1201 emem = &(kbuf->image->arch.exclude_ranges); in arch_kexec_locate_mem_hole()
1202 if (!(*emem) || ((*emem)->nr_ranges == 0)) { in arch_kexec_locate_mem_hole()
1207 buf_min = kbuf->buf_min; in arch_kexec_locate_mem_hole()
1208 buf_max = kbuf->buf_max; in arch_kexec_locate_mem_hole()
1210 if (kbuf->image->type == KEXEC_TYPE_CRASH) { in arch_kexec_locate_mem_hole()
1211 buf_min = (buf_min < crashk_res.start ? in arch_kexec_locate_mem_hole()
1212 crashk_res.start : buf_min); in arch_kexec_locate_mem_hole()
1219 return -EINVAL; in arch_kexec_locate_mem_hole()
1222 if (kbuf->top_down) in arch_kexec_locate_mem_hole()
1231 add_mem_range(emem, kbuf->mem, kbuf->memsz); in arch_kexec_locate_mem_hole()
1235 kbuf->memsz); in arch_kexec_locate_mem_hole()
1241 * arch_kexec_kernel_image_probe - Does additional handling needed to setup
1254 /* Get exclude memory ranges needed for setting up kexec segments */ in arch_kexec_kernel_image_probe()
1255 ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges)); in arch_kexec_kernel_image_probe()
1265 * arch_kimage_file_post_load_cleanup - Frees up all the allocations done
1273 kfree(image->arch.exclude_ranges); in arch_kimage_file_post_load_cleanup()
1274 image->arch.exclude_ranges = NULL; in arch_kimage_file_post_load_cleanup()
1276 vfree(image->arch.backup_buf); in arch_kimage_file_post_load_cleanup()
1277 image->arch.backup_buf = NULL; in arch_kimage_file_post_load_cleanup()
1279 vfree(image->elf_headers); in arch_kimage_file_post_load_cleanup()
1280 image->elf_headers = NULL; in arch_kimage_file_post_load_cleanup()
1281 image->elf_headers_sz = 0; in arch_kimage_file_post_load_cleanup()
1283 kvfree(image->arch.fdt); in arch_kimage_file_post_load_cleanup()
1284 image->arch.fdt = NULL; in arch_kimage_file_post_load_cleanup()