2 * Linux Guest Relocation (LGR) detection
4 * Copyright IBM Corp. 2012
5 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
8 #include <linux/init.h>
9 #include <linux/export.h>
10 #include <linux/timer.h>
11 #include <linux/slab.h>
12 #include <asm/facility.h>
13 #include <asm/sysinfo.h>
14 #include <asm/ebcdic.h>
15 #include <asm/debug.h>
18 #define LGR_TIMER_INTERVAL_SECS (30 * 60)
19 #define VM_LEVEL_MAX 2 /* Maximum is 8, but we only record two levels */
22 * LGR info: Contains stfle and stsi data
25 /* Bit field with facility information: 4 DWORDs are stored */
26 u64 stfle_fac_list
[4];
27 /* Level of system (1 = CEC, 2 = LPAR, 3 = z/VM */
29 /* Level 1: CEC info (stsi 1.1.1) */
30 char manufacturer
[16];
35 /* Level 2: LPAR info (stsi 2.2.2) */
38 /* Level 3: VM info (stsi 3.2.2) */
44 } __packed
__aligned(8);
49 static char lgr_page
[PAGE_SIZE
] __aligned(PAGE_SIZE
);
50 static struct lgr_info lgr_info_last
;
51 static struct lgr_info lgr_info_cur
;
52 static struct debug_info
*lgr_dbf
;
55 * Copy buffer and then convert it to ASCII
57 static void cpascii(char *dst
, char *src
, int size
)
59 memcpy(dst
, src
, size
);
64 * Fill LGR info with 1.1.1 stsi data
66 static void lgr_stsi_1_1_1(struct lgr_info
*lgr_info
)
68 struct sysinfo_1_1_1
*si
= (void *) lgr_page
;
70 if (stsi(si
, 1, 1, 1))
72 cpascii(lgr_info
->manufacturer
, si
->manufacturer
,
73 sizeof(si
->manufacturer
));
74 cpascii(lgr_info
->type
, si
->type
, sizeof(si
->type
));
75 cpascii(lgr_info
->model
, si
->model
, sizeof(si
->model
));
76 cpascii(lgr_info
->sequence
, si
->sequence
, sizeof(si
->sequence
));
77 cpascii(lgr_info
->plant
, si
->plant
, sizeof(si
->plant
));
81 * Fill LGR info with 2.2.2 stsi data
83 static void lgr_stsi_2_2_2(struct lgr_info
*lgr_info
)
85 struct sysinfo_2_2_2
*si
= (void *) lgr_page
;
87 if (stsi(si
, 2, 2, 2))
89 cpascii(lgr_info
->name
, si
->name
, sizeof(si
->name
));
90 memcpy(&lgr_info
->lpar_number
, &si
->lpar_number
,
91 sizeof(lgr_info
->lpar_number
));
95 * Fill LGR info with 3.2.2 stsi data
97 static void lgr_stsi_3_2_2(struct lgr_info
*lgr_info
)
99 struct sysinfo_3_2_2
*si
= (void *) lgr_page
;
102 if (stsi(si
, 3, 2, 2))
104 for (i
= 0; i
< min_t(u8
, si
->count
, VM_LEVEL_MAX
); i
++) {
105 cpascii(lgr_info
->vm
[i
].name
, si
->vm
[i
].name
,
106 sizeof(si
->vm
[i
].name
));
107 cpascii(lgr_info
->vm
[i
].cpi
, si
->vm
[i
].cpi
,
108 sizeof(si
->vm
[i
].cpi
));
110 lgr_info
->vm_count
= si
->count
;
114 * Fill LGR info with current data
116 static void lgr_info_get(struct lgr_info
*lgr_info
)
120 memset(lgr_info
, 0, sizeof(*lgr_info
));
121 stfle(lgr_info
->stfle_fac_list
, ARRAY_SIZE(lgr_info
->stfle_fac_list
));
122 level
= stsi(NULL
, 0, 0, 0);
123 lgr_info
->level
= level
;
125 lgr_stsi_1_1_1(lgr_info
);
127 lgr_stsi_2_2_2(lgr_info
);
129 lgr_stsi_3_2_2(lgr_info
);
133 * Check if LGR info has changed and if yes log new LGR info to s390dbf
135 void lgr_info_log(void)
137 static DEFINE_SPINLOCK(lgr_info_lock
);
140 if (!spin_trylock_irqsave(&lgr_info_lock
, flags
))
142 lgr_info_get(&lgr_info_cur
);
143 if (memcmp(&lgr_info_last
, &lgr_info_cur
, sizeof(lgr_info_cur
)) != 0) {
144 debug_event(lgr_dbf
, 1, &lgr_info_cur
, sizeof(lgr_info_cur
));
145 lgr_info_last
= lgr_info_cur
;
147 spin_unlock_irqrestore(&lgr_info_lock
, flags
);
149 EXPORT_SYMBOL_GPL(lgr_info_log
);
151 static void lgr_timer_set(void);
156 static void lgr_timer_fn(unsigned long ignored
)
162 static struct timer_list lgr_timer
=
163 TIMER_DEFERRED_INITIALIZER(lgr_timer_fn
, 0, 0);
166 * Setup next LGR timer
168 static void lgr_timer_set(void)
170 mod_timer(&lgr_timer
, jiffies
+ LGR_TIMER_INTERVAL_SECS
* HZ
);
174 * Initialize LGR: Add s390dbf, write initial lgr_info and setup timer
176 static int __init
lgr_init(void)
178 lgr_dbf
= debug_register("lgr", 1, 1, sizeof(struct lgr_info
));
181 debug_register_view(lgr_dbf
, &debug_hex_ascii_view
);
182 lgr_info_get(&lgr_info_last
);
183 debug_event(lgr_dbf
, 1, &lgr_info_last
, sizeof(lgr_info_last
));
187 device_initcall(lgr_init
);