summaryrefslogtreecommitdiff
path: root/arch/s390/kernel/kexec_image.c
blob: 3800852595e8a194387d91df4cb767f35a3c7687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: GPL-2.0
/*
 * Image loader for kexec_file_load system call.
 *
 * Copyright IBM Corp. 2018
 *
 * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
 */

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kexec.h>
#include <asm/setup.h>

static int kexec_file_add_image_kernel(struct kimage *image,
				       struct s390_load_data *data,
				       char *kernel, unsigned long kernel_len)
{
	struct kexec_buf buf;
	int ret;

	buf.image = image;

	buf.buffer = kernel + STARTUP_NORMAL_OFFSET;
	buf.bufsz = kernel_len - STARTUP_NORMAL_OFFSET;

	buf.mem = STARTUP_NORMAL_OFFSET;
	if (image->type == KEXEC_TYPE_CRASH)
		buf.mem += crashk_res.start;
	buf.memsz = buf.bufsz;

	ret = kexec_add_buffer(&buf);

	data->kernel_buf = kernel;
	data->memsz += buf.memsz + STARTUP_NORMAL_OFFSET;

	return ret;
}

static void *s390_image_load(struct kimage *image,
			     char *kernel, unsigned long kernel_len,
			     char *initrd, unsigned long initrd_len,
			     char *cmdline, unsigned long cmdline_len)
{
	struct s390_load_data data = {0};
	int ret;

	ret = kexec_file_add_image_kernel(image, &data, kernel, kernel_len);
	if (ret)
		return ERR_PTR(ret);

	if (initrd) {
		ret = kexec_file_add_initrd(image, &data, initrd, initrd_len);
		if (ret)
			return ERR_PTR(ret);
	}

	ret = kexec_file_add_purgatory(image, &data);
	if (ret)
		return ERR_PTR(ret);

	return kexec_file_update_kernel(image, &data);
}

static int s390_image_probe(const char *buf, unsigned long len)
{
	/* Can't reliably tell if an image is valid.  Therefore give the
	 * user whatever he wants.
	 */
	return 0;
}

const struct kexec_file_ops s390_kexec_image_ops = {
	.probe = s390_image_probe,
	.load = s390_image_load,
};