Commit | Line | Data |
---|---|---|
08d07968 | 1 | /* |
03997904 | 2 | * Copyright IBM Corp. 2007, 2009 |
08d07968 | 3 | * |
03997904 GS |
4 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, |
5 | * Peter Oberparleiter <peter.oberparleiter@de.ibm.com> | |
08d07968 HC |
6 | */ |
7 | ||
b3ff088b MS |
8 | #define KMSG_COMPONENT "sclp_cmd" |
9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
10 | ||
08d07968 HC |
11 | #include <linux/completion.h> |
12 | #include <linux/init.h> | |
13 | #include <linux/errno.h> | |
03997904 | 14 | #include <linux/err.h> |
08d07968 HC |
15 | #include <linux/slab.h> |
16 | #include <linux/string.h> | |
e0bc2495 HC |
17 | #include <linux/mm.h> |
18 | #include <linux/mmzone.h> | |
19 | #include <linux/memory.h> | |
1526bf9c | 20 | #include <linux/module.h> |
03997904 | 21 | #include <linux/platform_device.h> |
6b70a920 | 22 | #include <asm/ctl_reg.h> |
4b28a8fe | 23 | #include <asm/chpid.h> |
23d75d9c | 24 | #include <asm/setup.h> |
6b70a920 HC |
25 | #include <asm/page.h> |
26 | #include <asm/sclp.h> | |
08d07968 | 27 | |
b3ff088b | 28 | #include "sclp.h" |
08d07968 HC |
29 | |
30 | #define SCLP_CMDW_READ_SCP_INFO 0x00020001 | |
31 | #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 | |
32 | ||
33 | struct read_info_sccb { | |
34 | struct sccb_header header; /* 0-7 */ | |
35 | u16 rnmax; /* 8-9 */ | |
36 | u8 rnsize; /* 10 */ | |
37 | u8 _reserved0[24 - 11]; /* 11-15 */ | |
38 | u8 loadparm[8]; /* 24-31 */ | |
39 | u8 _reserved1[48 - 32]; /* 32-47 */ | |
40 | u64 facilities; /* 48-55 */ | |
41 | u8 _reserved2[84 - 56]; /* 56-83 */ | |
42 | u8 fac84; /* 84 */ | |
1526bf9c CB |
43 | u8 fac85; /* 85 */ |
44 | u8 _reserved3[91 - 86]; /* 86-90 */ | |
08d07968 HC |
45 | u8 flags; /* 91 */ |
46 | u8 _reserved4[100 - 92]; /* 92-99 */ | |
47 | u32 rnsize2; /* 100-103 */ | |
48 | u64 rnmax2; /* 104-111 */ | |
49 | u8 _reserved5[4096 - 112]; /* 112-4095 */ | |
50 | } __attribute__((packed, aligned(PAGE_SIZE))); | |
51 | ||
cd183459 | 52 | static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE); |
08d07968 HC |
53 | static struct read_info_sccb __initdata early_read_info_sccb; |
54 | static int __initdata early_read_info_sccb_valid; | |
55 | ||
56 | u64 sclp_facilities; | |
57 | static u8 sclp_fac84; | |
1526bf9c | 58 | static u8 sclp_fac85; |
e0bc2495 HC |
59 | static unsigned long long rzm; |
60 | static unsigned long long rnmax; | |
08d07968 HC |
61 | |
62 | static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb) | |
63 | { | |
64 | int rc; | |
65 | ||
66 | __ctl_set_bit(0, 9); | |
67 | rc = sclp_service_call(cmd, sccb); | |
68 | if (rc) | |
69 | goto out; | |
b50511e4 MS |
70 | __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | |
71 | PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT); | |
08d07968 HC |
72 | local_irq_disable(); |
73 | out: | |
74 | /* Contents of the sccb might have changed. */ | |
75 | barrier(); | |
76 | __ctl_clear_bit(0, 9); | |
77 | return rc; | |
78 | } | |
79 | ||
23d17421 | 80 | static void __init sclp_read_info_early(void) |
08d07968 HC |
81 | { |
82 | int rc; | |
83 | int i; | |
84 | struct read_info_sccb *sccb; | |
85 | sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED, | |
86 | SCLP_CMDW_READ_SCP_INFO}; | |
87 | ||
88 | sccb = &early_read_info_sccb; | |
89 | for (i = 0; i < ARRAY_SIZE(commands); i++) { | |
90 | do { | |
91 | memset(sccb, 0, sizeof(*sccb)); | |
92 | sccb->header.length = sizeof(*sccb); | |
cb9d7160 | 93 | sccb->header.function_code = 0x80; |
08d07968 HC |
94 | sccb->header.control_mask[2] = 0x80; |
95 | rc = sclp_cmd_sync_early(commands[i], sccb); | |
96 | } while (rc == -EBUSY); | |
97 | ||
98 | if (rc) | |
99 | break; | |
100 | if (sccb->header.response_code == 0x10) { | |
101 | early_read_info_sccb_valid = 1; | |
102 | break; | |
103 | } | |
104 | if (sccb->header.response_code != 0x1f0) | |
105 | break; | |
106 | } | |
107 | } | |
108 | ||
cd183459 HG |
109 | static void __init sclp_event_mask_early(void) |
110 | { | |
111 | struct init_sccb *sccb = &early_event_mask_sccb; | |
112 | int rc; | |
113 | ||
114 | do { | |
115 | memset(sccb, 0, sizeof(*sccb)); | |
116 | sccb->header.length = sizeof(*sccb); | |
117 | sccb->mask_length = sizeof(sccb_mask_t); | |
118 | rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb); | |
119 | } while (rc == -EBUSY); | |
120 | } | |
121 | ||
08d07968 HC |
122 | void __init sclp_facilities_detect(void) |
123 | { | |
08d07968 HC |
124 | struct read_info_sccb *sccb; |
125 | ||
23d17421 | 126 | sclp_read_info_early(); |
08d07968 | 127 | if (!early_read_info_sccb_valid) |
23d17421 HC |
128 | return; |
129 | ||
08d07968 | 130 | sccb = &early_read_info_sccb; |
23d17421 HC |
131 | sclp_facilities = sccb->facilities; |
132 | sclp_fac84 = sccb->fac84; | |
1526bf9c | 133 | sclp_fac85 = sccb->fac85; |
e0bc2495 HC |
134 | rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2; |
135 | rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2; | |
136 | rzm <<= 20; | |
cd183459 HG |
137 | |
138 | sclp_event_mask_early(); | |
139 | } | |
140 | ||
141 | bool __init sclp_has_linemode(void) | |
142 | { | |
143 | struct init_sccb *sccb = &early_event_mask_sccb; | |
144 | ||
145 | if (sccb->header.response_code != 0x20) | |
146 | return 0; | |
147 | if (sccb->sclp_send_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)) | |
148 | return 1; | |
149 | return 0; | |
150 | } | |
151 | ||
152 | bool __init sclp_has_vt220(void) | |
153 | { | |
154 | struct init_sccb *sccb = &early_event_mask_sccb; | |
155 | ||
156 | if (sccb->header.response_code != 0x20) | |
157 | return 0; | |
158 | if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK) | |
159 | return 1; | |
160 | return 0; | |
23d17421 HC |
161 | } |
162 | ||
163 | unsigned long long sclp_get_rnmax(void) | |
164 | { | |
165 | return rnmax; | |
166 | } | |
167 | ||
168 | unsigned long long sclp_get_rzm(void) | |
169 | { | |
170 | return rzm; | |
08d07968 HC |
171 | } |
172 | ||
1526bf9c CB |
173 | u8 sclp_get_fac85(void) |
174 | { | |
175 | return sclp_fac85; | |
176 | } | |
177 | EXPORT_SYMBOL_GPL(sclp_get_fac85); | |
178 | ||
08d07968 | 179 | /* |
23d17421 HC |
180 | * This function will be called after sclp_facilities_detect(), which gets |
181 | * called from early.c code. Therefore the sccb should have valid contents. | |
08d07968 HC |
182 | */ |
183 | void __init sclp_get_ipl_info(struct sclp_ipl_info *info) | |
184 | { | |
185 | struct read_info_sccb *sccb; | |
186 | ||
187 | if (!early_read_info_sccb_valid) | |
188 | return; | |
189 | sccb = &early_read_info_sccb; | |
190 | info->is_valid = 1; | |
191 | if (sccb->flags & 0x2) | |
192 | info->has_dump = 1; | |
193 | memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN); | |
194 | } | |
195 | ||
196 | static void sclp_sync_callback(struct sclp_req *req, void *data) | |
197 | { | |
198 | struct completion *completion = data; | |
199 | ||
200 | complete(completion); | |
201 | } | |
202 | ||
203 | static int do_sync_request(sclp_cmdw_t cmd, void *sccb) | |
204 | { | |
205 | struct completion completion; | |
206 | struct sclp_req *request; | |
207 | int rc; | |
208 | ||
209 | request = kzalloc(sizeof(*request), GFP_KERNEL); | |
210 | if (!request) | |
211 | return -ENOMEM; | |
212 | request->command = cmd; | |
213 | request->sccb = sccb; | |
214 | request->status = SCLP_REQ_FILLED; | |
215 | request->callback = sclp_sync_callback; | |
216 | request->callback_data = &completion; | |
217 | init_completion(&completion); | |
218 | ||
219 | /* Perform sclp request. */ | |
220 | rc = sclp_add_request(request); | |
221 | if (rc) | |
222 | goto out; | |
223 | wait_for_completion(&completion); | |
224 | ||
225 | /* Check response. */ | |
226 | if (request->status != SCLP_REQ_DONE) { | |
b3ff088b MS |
227 | pr_warning("sync request failed (cmd=0x%08x, " |
228 | "status=0x%02x)\n", cmd, request->status); | |
08d07968 HC |
229 | rc = -EIO; |
230 | } | |
231 | out: | |
232 | kfree(request); | |
233 | return rc; | |
234 | } | |
235 | ||
236 | /* | |
237 | * CPU configuration related functions. | |
238 | */ | |
239 | ||
240 | #define SCLP_CMDW_READ_CPU_INFO 0x00010001 | |
241 | #define SCLP_CMDW_CONFIGURE_CPU 0x00110001 | |
242 | #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001 | |
243 | ||
244 | struct read_cpu_info_sccb { | |
245 | struct sccb_header header; | |
246 | u16 nr_configured; | |
247 | u16 offset_configured; | |
248 | u16 nr_standby; | |
249 | u16 offset_standby; | |
250 | u8 reserved[4096 - 16]; | |
251 | } __attribute__((packed, aligned(PAGE_SIZE))); | |
252 | ||
08d07968 HC |
253 | static void sclp_fill_cpu_info(struct sclp_cpu_info *info, |
254 | struct read_cpu_info_sccb *sccb) | |
255 | { | |
256 | char *page = (char *) sccb; | |
257 | ||
258 | memset(info, 0, sizeof(*info)); | |
259 | info->configured = sccb->nr_configured; | |
260 | info->standby = sccb->nr_standby; | |
261 | info->combined = sccb->nr_configured + sccb->nr_standby; | |
262 | info->has_cpu_type = sclp_fac84 & 0x1; | |
263 | memcpy(&info->cpu, page + sccb->offset_configured, | |
264 | info->combined * sizeof(struct sclp_cpu_entry)); | |
265 | } | |
266 | ||
48483b32 | 267 | int sclp_get_cpu_info(struct sclp_cpu_info *info) |
08d07968 HC |
268 | { |
269 | int rc; | |
270 | struct read_cpu_info_sccb *sccb; | |
271 | ||
272 | if (!SCLP_HAS_CPU_INFO) | |
273 | return -EOPNOTSUPP; | |
48483b32 | 274 | sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); |
08d07968 HC |
275 | if (!sccb) |
276 | return -ENOMEM; | |
08d07968 HC |
277 | sccb->header.length = sizeof(*sccb); |
278 | rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb); | |
279 | if (rc) | |
280 | goto out; | |
281 | if (sccb->header.response_code != 0x0010) { | |
b3ff088b MS |
282 | pr_warning("readcpuinfo failed (response=0x%04x)\n", |
283 | sccb->header.response_code); | |
08d07968 HC |
284 | rc = -EIO; |
285 | goto out; | |
286 | } | |
287 | sclp_fill_cpu_info(info, sccb); | |
288 | out: | |
289 | free_page((unsigned long) sccb); | |
290 | return rc; | |
291 | } | |
292 | ||
08d07968 HC |
293 | struct cpu_configure_sccb { |
294 | struct sccb_header header; | |
295 | } __attribute__((packed, aligned(8))); | |
296 | ||
297 | static int do_cpu_configure(sclp_cmdw_t cmd) | |
298 | { | |
299 | struct cpu_configure_sccb *sccb; | |
300 | int rc; | |
301 | ||
302 | if (!SCLP_HAS_CPU_RECONFIG) | |
303 | return -EOPNOTSUPP; | |
304 | /* | |
305 | * This is not going to cross a page boundary since we force | |
306 | * kmalloc to have a minimum alignment of 8 bytes on s390. | |
307 | */ | |
308 | sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA); | |
309 | if (!sccb) | |
310 | return -ENOMEM; | |
311 | sccb->header.length = sizeof(*sccb); | |
312 | rc = do_sync_request(cmd, sccb); | |
313 | if (rc) | |
314 | goto out; | |
315 | switch (sccb->header.response_code) { | |
316 | case 0x0020: | |
317 | case 0x0120: | |
318 | break; | |
319 | default: | |
b3ff088b MS |
320 | pr_warning("configure cpu failed (cmd=0x%08x, " |
321 | "response=0x%04x)\n", cmd, | |
322 | sccb->header.response_code); | |
08d07968 HC |
323 | rc = -EIO; |
324 | break; | |
325 | } | |
326 | out: | |
327 | kfree(sccb); | |
328 | return rc; | |
329 | } | |
330 | ||
331 | int sclp_cpu_configure(u8 cpu) | |
332 | { | |
333 | return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8); | |
334 | } | |
335 | ||
336 | int sclp_cpu_deconfigure(u8 cpu) | |
337 | { | |
338 | return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8); | |
339 | } | |
4b28a8fe | 340 | |
e0bc2495 HC |
341 | #ifdef CONFIG_MEMORY_HOTPLUG |
342 | ||
343 | static DEFINE_MUTEX(sclp_mem_mutex); | |
344 | static LIST_HEAD(sclp_mem_list); | |
345 | static u8 sclp_max_storage_id; | |
346 | static unsigned long sclp_storage_ids[256 / BITS_PER_LONG]; | |
03997904 | 347 | static int sclp_mem_state_changed; |
e0bc2495 HC |
348 | |
349 | struct memory_increment { | |
350 | struct list_head list; | |
351 | u16 rn; | |
352 | int standby; | |
353 | int usecount; | |
354 | }; | |
355 | ||
356 | struct assign_storage_sccb { | |
357 | struct sccb_header header; | |
358 | u16 rn; | |
359 | } __packed; | |
360 | ||
9c95258c HC |
361 | int arch_get_memory_phys_device(unsigned long start_pfn) |
362 | { | |
363 | if (!rzm) | |
364 | return 0; | |
365 | return PFN_PHYS(start_pfn) >> ilog2(rzm); | |
366 | } | |
367 | ||
e0bc2495 HC |
368 | static unsigned long long rn2addr(u16 rn) |
369 | { | |
370 | return (unsigned long long) (rn - 1) * rzm; | |
371 | } | |
372 | ||
373 | static int do_assign_storage(sclp_cmdw_t cmd, u16 rn) | |
374 | { | |
375 | struct assign_storage_sccb *sccb; | |
376 | int rc; | |
377 | ||
378 | sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
379 | if (!sccb) | |
380 | return -ENOMEM; | |
381 | sccb->header.length = PAGE_SIZE; | |
382 | sccb->rn = rn; | |
383 | rc = do_sync_request(cmd, sccb); | |
384 | if (rc) | |
385 | goto out; | |
386 | switch (sccb->header.response_code) { | |
387 | case 0x0020: | |
388 | case 0x0120: | |
389 | break; | |
390 | default: | |
675be97a HC |
391 | pr_warning("assign storage failed (cmd=0x%08x, " |
392 | "response=0x%04x, rn=0x%04x)\n", cmd, | |
393 | sccb->header.response_code, rn); | |
e0bc2495 HC |
394 | rc = -EIO; |
395 | break; | |
396 | } | |
397 | out: | |
398 | free_page((unsigned long) sccb); | |
399 | return rc; | |
400 | } | |
401 | ||
402 | static int sclp_assign_storage(u16 rn) | |
403 | { | |
6b70a920 | 404 | unsigned long long start; |
0cd2f620 HC |
405 | int rc; |
406 | ||
407 | rc = do_assign_storage(0x000d0001, rn); | |
408 | if (rc) | |
6b70a920 HC |
409 | return rc; |
410 | start = rn2addr(rn); | |
411 | storage_key_init_range(start, start + rzm); | |
412 | return 0; | |
e0bc2495 HC |
413 | } |
414 | ||
415 | static int sclp_unassign_storage(u16 rn) | |
416 | { | |
417 | return do_assign_storage(0x000c0001, rn); | |
418 | } | |
419 | ||
420 | struct attach_storage_sccb { | |
421 | struct sccb_header header; | |
422 | u16 :16; | |
423 | u16 assigned; | |
424 | u32 :32; | |
425 | u32 entries[0]; | |
426 | } __packed; | |
427 | ||
428 | static int sclp_attach_storage(u8 id) | |
429 | { | |
430 | struct attach_storage_sccb *sccb; | |
431 | int rc; | |
432 | int i; | |
433 | ||
434 | sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
435 | if (!sccb) | |
436 | return -ENOMEM; | |
437 | sccb->header.length = PAGE_SIZE; | |
438 | rc = do_sync_request(0x00080001 | id << 8, sccb); | |
439 | if (rc) | |
440 | goto out; | |
441 | switch (sccb->header.response_code) { | |
442 | case 0x0020: | |
443 | set_bit(id, sclp_storage_ids); | |
8adb4ca3 HC |
444 | for (i = 0; i < sccb->assigned; i++) { |
445 | if (sccb->entries[i]) | |
446 | sclp_unassign_storage(sccb->entries[i] >> 16); | |
447 | } | |
e0bc2495 HC |
448 | break; |
449 | default: | |
450 | rc = -EIO; | |
451 | break; | |
452 | } | |
453 | out: | |
454 | free_page((unsigned long) sccb); | |
455 | return rc; | |
456 | } | |
457 | ||
458 | static int sclp_mem_change_state(unsigned long start, unsigned long size, | |
459 | int online) | |
460 | { | |
461 | struct memory_increment *incr; | |
462 | unsigned long long istart; | |
463 | int rc = 0; | |
464 | ||
465 | list_for_each_entry(incr, &sclp_mem_list, list) { | |
466 | istart = rn2addr(incr->rn); | |
467 | if (start + size - 1 < istart) | |
468 | break; | |
469 | if (start > istart + rzm - 1) | |
470 | continue; | |
471 | if (online) { | |
472 | if (incr->usecount++) | |
473 | continue; | |
474 | /* | |
475 | * Don't break the loop if one assign fails. Loop may | |
476 | * be walked again on CANCEL and we can't save | |
477 | * information if state changed before or not. | |
478 | * So continue and increase usecount for all increments. | |
479 | */ | |
480 | rc |= sclp_assign_storage(incr->rn); | |
481 | } else { | |
482 | if (--incr->usecount) | |
483 | continue; | |
484 | sclp_unassign_storage(incr->rn); | |
485 | } | |
486 | } | |
487 | return rc ? -EIO : 0; | |
488 | } | |
489 | ||
490 | static int sclp_mem_notifier(struct notifier_block *nb, | |
491 | unsigned long action, void *data) | |
492 | { | |
493 | unsigned long start, size; | |
494 | struct memory_notify *arg; | |
495 | unsigned char id; | |
496 | int rc = 0; | |
497 | ||
498 | arg = data; | |
499 | start = arg->start_pfn << PAGE_SHIFT; | |
500 | size = arg->nr_pages << PAGE_SHIFT; | |
501 | mutex_lock(&sclp_mem_mutex); | |
fc89db4b AM |
502 | for_each_clear_bit(id, sclp_storage_ids, sclp_max_storage_id + 1) |
503 | sclp_attach_storage(id); | |
e0bc2495 HC |
504 | switch (action) { |
505 | case MEM_ONLINE: | |
7e9238fb GS |
506 | case MEM_GOING_OFFLINE: |
507 | case MEM_CANCEL_OFFLINE: | |
e0bc2495 HC |
508 | break; |
509 | case MEM_GOING_ONLINE: | |
510 | rc = sclp_mem_change_state(start, size, 1); | |
511 | break; | |
512 | case MEM_CANCEL_ONLINE: | |
513 | sclp_mem_change_state(start, size, 0); | |
514 | break; | |
7e9238fb GS |
515 | case MEM_OFFLINE: |
516 | sclp_mem_change_state(start, size, 0); | |
517 | break; | |
e0bc2495 HC |
518 | default: |
519 | rc = -EINVAL; | |
520 | break; | |
521 | } | |
03997904 GS |
522 | if (!rc) |
523 | sclp_mem_state_changed = 1; | |
e0bc2495 HC |
524 | mutex_unlock(&sclp_mem_mutex); |
525 | return rc ? NOTIFY_BAD : NOTIFY_OK; | |
526 | } | |
527 | ||
528 | static struct notifier_block sclp_mem_nb = { | |
529 | .notifier_call = sclp_mem_notifier, | |
530 | }; | |
531 | ||
532 | static void __init add_memory_merged(u16 rn) | |
533 | { | |
534 | static u16 first_rn, num; | |
535 | unsigned long long start, size; | |
536 | ||
537 | if (rn && first_rn && (first_rn + num == rn)) { | |
538 | num++; | |
539 | return; | |
540 | } | |
541 | if (!first_rn) | |
542 | goto skip_add; | |
543 | start = rn2addr(first_rn); | |
544 | size = (unsigned long long ) num * rzm; | |
545 | if (start >= VMEM_MAX_PHYS) | |
546 | goto skip_add; | |
547 | if (start + size > VMEM_MAX_PHYS) | |
548 | size = VMEM_MAX_PHYS - start; | |
23d75d9c HC |
549 | if (memory_end_set && (start >= memory_end)) |
550 | goto skip_add; | |
551 | if (memory_end_set && (start + size > memory_end)) | |
552 | size = memory_end - start; | |
e0bc2495 HC |
553 | add_memory(0, start, size); |
554 | skip_add: | |
555 | first_rn = rn; | |
556 | num = 1; | |
557 | } | |
558 | ||
559 | static void __init sclp_add_standby_memory(void) | |
560 | { | |
561 | struct memory_increment *incr; | |
562 | ||
563 | list_for_each_entry(incr, &sclp_mem_list, list) | |
564 | if (incr->standby) | |
565 | add_memory_merged(incr->rn); | |
566 | add_memory_merged(0); | |
567 | } | |
568 | ||
569 | static void __init insert_increment(u16 rn, int standby, int assigned) | |
570 | { | |
571 | struct memory_increment *incr, *new_incr; | |
572 | struct list_head *prev; | |
573 | u16 last_rn; | |
574 | ||
575 | new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL); | |
576 | if (!new_incr) | |
577 | return; | |
578 | new_incr->rn = rn; | |
579 | new_incr->standby = standby; | |
fdb1bb15 HC |
580 | if (!standby) |
581 | new_incr->usecount = 1; | |
e0bc2495 HC |
582 | last_rn = 0; |
583 | prev = &sclp_mem_list; | |
584 | list_for_each_entry(incr, &sclp_mem_list, list) { | |
585 | if (assigned && incr->rn > rn) | |
586 | break; | |
587 | if (!assigned && incr->rn - last_rn > 1) | |
588 | break; | |
589 | last_rn = incr->rn; | |
590 | prev = &incr->list; | |
591 | } | |
592 | if (!assigned) | |
593 | new_incr->rn = last_rn + 1; | |
594 | if (new_incr->rn > rnmax) { | |
595 | kfree(new_incr); | |
596 | return; | |
597 | } | |
598 | list_add(&new_incr->list, prev); | |
599 | } | |
600 | ||
03997904 GS |
601 | static int sclp_mem_freeze(struct device *dev) |
602 | { | |
603 | if (!sclp_mem_state_changed) | |
604 | return 0; | |
605 | pr_err("Memory hotplug state changed, suspend refused.\n"); | |
606 | return -EPERM; | |
607 | } | |
608 | ||
e0bc2495 HC |
609 | struct read_storage_sccb { |
610 | struct sccb_header header; | |
611 | u16 max_id; | |
612 | u16 assigned; | |
613 | u16 standby; | |
614 | u16 :16; | |
615 | u32 entries[0]; | |
616 | } __packed; | |
617 | ||
47145210 | 618 | static const struct dev_pm_ops sclp_mem_pm_ops = { |
03997904 GS |
619 | .freeze = sclp_mem_freeze, |
620 | }; | |
621 | ||
622 | static struct platform_driver sclp_mem_pdrv = { | |
623 | .driver = { | |
624 | .name = "sclp_mem", | |
625 | .pm = &sclp_mem_pm_ops, | |
626 | }, | |
627 | }; | |
628 | ||
e0bc2495 HC |
629 | static int __init sclp_detect_standby_memory(void) |
630 | { | |
03997904 | 631 | struct platform_device *sclp_pdev; |
e0bc2495 HC |
632 | struct read_storage_sccb *sccb; |
633 | int i, id, assigned, rc; | |
634 | ||
635 | if (!early_read_info_sccb_valid) | |
636 | return 0; | |
637 | if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL) | |
638 | return 0; | |
639 | rc = -ENOMEM; | |
640 | sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA); | |
641 | if (!sccb) | |
642 | goto out; | |
643 | assigned = 0; | |
644 | for (id = 0; id <= sclp_max_storage_id; id++) { | |
645 | memset(sccb, 0, PAGE_SIZE); | |
646 | sccb->header.length = PAGE_SIZE; | |
647 | rc = do_sync_request(0x00040001 | id << 8, sccb); | |
648 | if (rc) | |
649 | goto out; | |
650 | switch (sccb->header.response_code) { | |
651 | case 0x0010: | |
652 | set_bit(id, sclp_storage_ids); | |
653 | for (i = 0; i < sccb->assigned; i++) { | |
654 | if (!sccb->entries[i]) | |
655 | continue; | |
656 | assigned++; | |
657 | insert_increment(sccb->entries[i] >> 16, 0, 1); | |
658 | } | |
659 | break; | |
660 | case 0x0310: | |
661 | break; | |
662 | case 0x0410: | |
663 | for (i = 0; i < sccb->assigned; i++) { | |
664 | if (!sccb->entries[i]) | |
665 | continue; | |
666 | assigned++; | |
667 | insert_increment(sccb->entries[i] >> 16, 1, 1); | |
668 | } | |
669 | break; | |
670 | default: | |
671 | rc = -EIO; | |
672 | break; | |
673 | } | |
674 | if (!rc) | |
675 | sclp_max_storage_id = sccb->max_id; | |
676 | } | |
677 | if (rc || list_empty(&sclp_mem_list)) | |
678 | goto out; | |
679 | for (i = 1; i <= rnmax - assigned; i++) | |
680 | insert_increment(0, 1, 0); | |
681 | rc = register_memory_notifier(&sclp_mem_nb); | |
682 | if (rc) | |
683 | goto out; | |
03997904 GS |
684 | rc = platform_driver_register(&sclp_mem_pdrv); |
685 | if (rc) | |
686 | goto out; | |
687 | sclp_pdev = platform_device_register_simple("sclp_mem", -1, NULL, 0); | |
688 | rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0; | |
689 | if (rc) | |
690 | goto out_driver; | |
e0bc2495 | 691 | sclp_add_standby_memory(); |
03997904 GS |
692 | goto out; |
693 | out_driver: | |
694 | platform_driver_unregister(&sclp_mem_pdrv); | |
e0bc2495 HC |
695 | out: |
696 | free_page((unsigned long) sccb); | |
697 | return rc; | |
698 | } | |
699 | __initcall(sclp_detect_standby_memory); | |
700 | ||
701 | #endif /* CONFIG_MEMORY_HOTPLUG */ | |
702 | ||
4b28a8fe HC |
703 | /* |
704 | * Channel path configuration related functions. | |
705 | */ | |
706 | ||
707 | #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001 | |
708 | #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001 | |
709 | #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001 | |
710 | ||
711 | struct chp_cfg_sccb { | |
712 | struct sccb_header header; | |
713 | u8 ccm; | |
714 | u8 reserved[6]; | |
715 | u8 cssid; | |
716 | } __attribute__((packed)); | |
717 | ||
718 | static int do_chp_configure(sclp_cmdw_t cmd) | |
719 | { | |
720 | struct chp_cfg_sccb *sccb; | |
721 | int rc; | |
722 | ||
723 | if (!SCLP_HAS_CHP_RECONFIG) | |
724 | return -EOPNOTSUPP; | |
725 | /* Prepare sccb. */ | |
726 | sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
727 | if (!sccb) | |
728 | return -ENOMEM; | |
729 | sccb->header.length = sizeof(*sccb); | |
730 | rc = do_sync_request(cmd, sccb); | |
731 | if (rc) | |
732 | goto out; | |
733 | switch (sccb->header.response_code) { | |
734 | case 0x0020: | |
735 | case 0x0120: | |
736 | case 0x0440: | |
737 | case 0x0450: | |
738 | break; | |
739 | default: | |
b3ff088b MS |
740 | pr_warning("configure channel-path failed " |
741 | "(cmd=0x%08x, response=0x%04x)\n", cmd, | |
742 | sccb->header.response_code); | |
4b28a8fe HC |
743 | rc = -EIO; |
744 | break; | |
745 | } | |
746 | out: | |
747 | free_page((unsigned long) sccb); | |
748 | return rc; | |
749 | } | |
750 | ||
751 | /** | |
752 | * sclp_chp_configure - perform configure channel-path sclp command | |
753 | * @chpid: channel-path ID | |
754 | * | |
755 | * Perform configure channel-path command sclp command for specified chpid. | |
756 | * Return 0 after command successfully finished, non-zero otherwise. | |
757 | */ | |
758 | int sclp_chp_configure(struct chp_id chpid) | |
759 | { | |
760 | return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8); | |
761 | } | |
762 | ||
763 | /** | |
764 | * sclp_chp_deconfigure - perform deconfigure channel-path sclp command | |
765 | * @chpid: channel-path ID | |
766 | * | |
767 | * Perform deconfigure channel-path command sclp command for specified chpid | |
768 | * and wait for completion. On success return 0. Return non-zero otherwise. | |
769 | */ | |
770 | int sclp_chp_deconfigure(struct chp_id chpid) | |
771 | { | |
772 | return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8); | |
773 | } | |
774 | ||
775 | struct chp_info_sccb { | |
776 | struct sccb_header header; | |
777 | u8 recognized[SCLP_CHP_INFO_MASK_SIZE]; | |
778 | u8 standby[SCLP_CHP_INFO_MASK_SIZE]; | |
779 | u8 configured[SCLP_CHP_INFO_MASK_SIZE]; | |
780 | u8 ccm; | |
781 | u8 reserved[6]; | |
782 | u8 cssid; | |
783 | } __attribute__((packed)); | |
784 | ||
785 | /** | |
786 | * sclp_chp_read_info - perform read channel-path information sclp command | |
787 | * @info: resulting channel-path information data | |
788 | * | |
789 | * Perform read channel-path information sclp command and wait for completion. | |
790 | * On success, store channel-path information in @info and return 0. Return | |
791 | * non-zero otherwise. | |
792 | */ | |
793 | int sclp_chp_read_info(struct sclp_chp_info *info) | |
794 | { | |
795 | struct chp_info_sccb *sccb; | |
796 | int rc; | |
797 | ||
798 | if (!SCLP_HAS_CHP_INFO) | |
799 | return -EOPNOTSUPP; | |
800 | /* Prepare sccb. */ | |
801 | sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | |
802 | if (!sccb) | |
803 | return -ENOMEM; | |
804 | sccb->header.length = sizeof(*sccb); | |
805 | rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb); | |
806 | if (rc) | |
807 | goto out; | |
808 | if (sccb->header.response_code != 0x0010) { | |
b3ff088b MS |
809 | pr_warning("read channel-path info failed " |
810 | "(response=0x%04x)\n", sccb->header.response_code); | |
4b28a8fe HC |
811 | rc = -EIO; |
812 | goto out; | |
813 | } | |
814 | memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE); | |
815 | memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE); | |
816 | memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE); | |
817 | out: | |
818 | free_page((unsigned long) sccb); | |
819 | return rc; | |
820 | } |