blob: 01df9d8303e158829a6d4ae73cf686d86f63a78f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jiri Olsa696e2452017-10-11 17:01:24 +02002#include <linux/compiler.h>
3
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +02004static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
5{
6 struct ins_ops *ops = NULL;
7
8 /* catch all kind of jumps */
9 if (strchr(name, 'j') ||
10 !strncmp(name, "bct", 3) ||
11 !strncmp(name, "br", 2))
12 ops = &jump_ops;
13 /* override call/returns */
14 if (!strcmp(name, "bras") ||
15 !strcmp(name, "brasl") ||
16 !strcmp(name, "basr"))
17 ops = &call_ops;
18 if (!strcmp(name, "br"))
19 ops = &ret_ops;
20
Thomas Richter36c26362017-11-24 10:46:37 +010021 if (ops)
22 arch__associate_ins_ops(arch, name, ops);
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +020023 return ops;
24}
25
Thomas Richterc59124f2018-02-13 16:14:17 +010026static int s390__cpuid_parse(struct arch *arch, char *cpuid)
27{
28 unsigned int family;
29 char model[16], model_c[16], cpumf_v[16], cpumf_a[16];
30 int ret;
31
32 /*
33 * cpuid string format:
34 * "IBM,family,model-capacity,model[,cpum_cf-version,cpum_cf-authorization]"
35 */
36 ret = sscanf(cpuid, "%*[^,],%u,%[^,],%[^,],%[^,],%s", &family, model_c,
37 model, cpumf_v, cpumf_a);
38 if (ret >= 2) {
39 arch->family = family;
40 arch->model = 0;
41 return 0;
42 }
43
44 return -1;
45}
46
Jiri Olsa696e2452017-10-11 17:01:24 +020047static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +020048{
Thomas Richterc59124f2018-02-13 16:14:17 +010049 int err = 0;
50
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +020051 if (!arch->initialized) {
52 arch->initialized = true;
53 arch->associate_instruction_ops = s390__associate_ins_ops;
Thomas Richterc59124f2018-02-13 16:14:17 +010054 if (cpuid)
55 err = s390__cpuid_parse(arch, cpuid);
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +020056 }
57
Thomas Richterc59124f2018-02-13 16:14:17 +010058 return err;
Christian Borntraegerd9f8dfa2017-04-06 09:51:52 +020059}