tracehook_notify_death: use task_detached() helper
[linux-2.6/mini2440.git] / drivers / s390 / char / sclp_cmd.c
blob77ab6e34a100b758bc3047888e78f1962a90146d
1 /*
2 * drivers/s390/char/sclp_cmd.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
6 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
7 */
9 #define KMSG_COMPONENT "sclp_cmd"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/completion.h>
13 #include <linux/init.h>
14 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
17 #include <linux/mm.h>
18 #include <linux/mmzone.h>
19 #include <linux/memory.h>
20 #include <asm/chpid.h>
21 #include <asm/sclp.h>
22 #include <asm/setup.h>
24 #include "sclp.h"
26 #define SCLP_CMDW_READ_SCP_INFO 0x00020001
27 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
29 struct read_info_sccb {
30 struct sccb_header header; /* 0-7 */
31 u16 rnmax; /* 8-9 */
32 u8 rnsize; /* 10 */
33 u8 _reserved0[24 - 11]; /* 11-15 */
34 u8 loadparm[8]; /* 24-31 */
35 u8 _reserved1[48 - 32]; /* 32-47 */
36 u64 facilities; /* 48-55 */
37 u8 _reserved2[84 - 56]; /* 56-83 */
38 u8 fac84; /* 84 */
39 u8 _reserved3[91 - 85]; /* 85-90 */
40 u8 flags; /* 91 */
41 u8 _reserved4[100 - 92]; /* 92-99 */
42 u32 rnsize2; /* 100-103 */
43 u64 rnmax2; /* 104-111 */
44 u8 _reserved5[4096 - 112]; /* 112-4095 */
45 } __attribute__((packed, aligned(PAGE_SIZE)));
47 static struct read_info_sccb __initdata early_read_info_sccb;
48 static int __initdata early_read_info_sccb_valid;
50 u64 sclp_facilities;
51 static u8 sclp_fac84;
52 static unsigned long long rzm;
53 static unsigned long long rnmax;
55 static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
57 int rc;
59 __ctl_set_bit(0, 9);
60 rc = sclp_service_call(cmd, sccb);
61 if (rc)
62 goto out;
63 __load_psw_mask(PSW_BASE_BITS | PSW_MASK_EXT |
64 PSW_MASK_WAIT | PSW_DEFAULT_KEY);
65 local_irq_disable();
66 out:
67 /* Contents of the sccb might have changed. */
68 barrier();
69 __ctl_clear_bit(0, 9);
70 return rc;
73 static void __init sclp_read_info_early(void)
75 int rc;
76 int i;
77 struct read_info_sccb *sccb;
78 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
79 SCLP_CMDW_READ_SCP_INFO};
81 sccb = &early_read_info_sccb;
82 for (i = 0; i < ARRAY_SIZE(commands); i++) {
83 do {
84 memset(sccb, 0, sizeof(*sccb));
85 sccb->header.length = sizeof(*sccb);
86 sccb->header.control_mask[2] = 0x80;
87 rc = sclp_cmd_sync_early(commands[i], sccb);
88 } while (rc == -EBUSY);
90 if (rc)
91 break;
92 if (sccb->header.response_code == 0x10) {
93 early_read_info_sccb_valid = 1;
94 break;
96 if (sccb->header.response_code != 0x1f0)
97 break;
101 void __init sclp_facilities_detect(void)
103 struct read_info_sccb *sccb;
105 sclp_read_info_early();
106 if (!early_read_info_sccb_valid)
107 return;
109 sccb = &early_read_info_sccb;
110 sclp_facilities = sccb->facilities;
111 sclp_fac84 = sccb->fac84;
112 rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
113 rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
114 rzm <<= 20;
117 unsigned long long sclp_get_rnmax(void)
119 return rnmax;
122 unsigned long long sclp_get_rzm(void)
124 return rzm;
128 * This function will be called after sclp_facilities_detect(), which gets
129 * called from early.c code. Therefore the sccb should have valid contents.
131 void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
133 struct read_info_sccb *sccb;
135 if (!early_read_info_sccb_valid)
136 return;
137 sccb = &early_read_info_sccb;
138 info->is_valid = 1;
139 if (sccb->flags & 0x2)
140 info->has_dump = 1;
141 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
144 static void sclp_sync_callback(struct sclp_req *req, void *data)
146 struct completion *completion = data;
148 complete(completion);
151 static int do_sync_request(sclp_cmdw_t cmd, void *sccb)
153 struct completion completion;
154 struct sclp_req *request;
155 int rc;
157 request = kzalloc(sizeof(*request), GFP_KERNEL);
158 if (!request)
159 return -ENOMEM;
160 request->command = cmd;
161 request->sccb = sccb;
162 request->status = SCLP_REQ_FILLED;
163 request->callback = sclp_sync_callback;
164 request->callback_data = &completion;
165 init_completion(&completion);
167 /* Perform sclp request. */
168 rc = sclp_add_request(request);
169 if (rc)
170 goto out;
171 wait_for_completion(&completion);
173 /* Check response. */
174 if (request->status != SCLP_REQ_DONE) {
175 pr_warning("sync request failed (cmd=0x%08x, "
176 "status=0x%02x)\n", cmd, request->status);
177 rc = -EIO;
179 out:
180 kfree(request);
181 return rc;
185 * CPU configuration related functions.
188 #define SCLP_CMDW_READ_CPU_INFO 0x00010001
189 #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
190 #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
192 struct read_cpu_info_sccb {
193 struct sccb_header header;
194 u16 nr_configured;
195 u16 offset_configured;
196 u16 nr_standby;
197 u16 offset_standby;
198 u8 reserved[4096 - 16];
199 } __attribute__((packed, aligned(PAGE_SIZE)));
201 static void sclp_fill_cpu_info(struct sclp_cpu_info *info,
202 struct read_cpu_info_sccb *sccb)
204 char *page = (char *) sccb;
206 memset(info, 0, sizeof(*info));
207 info->configured = sccb->nr_configured;
208 info->standby = sccb->nr_standby;
209 info->combined = sccb->nr_configured + sccb->nr_standby;
210 info->has_cpu_type = sclp_fac84 & 0x1;
211 memcpy(&info->cpu, page + sccb->offset_configured,
212 info->combined * sizeof(struct sclp_cpu_entry));
215 int sclp_get_cpu_info(struct sclp_cpu_info *info)
217 int rc;
218 struct read_cpu_info_sccb *sccb;
220 if (!SCLP_HAS_CPU_INFO)
221 return -EOPNOTSUPP;
222 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
223 if (!sccb)
224 return -ENOMEM;
225 sccb->header.length = sizeof(*sccb);
226 rc = do_sync_request(SCLP_CMDW_READ_CPU_INFO, sccb);
227 if (rc)
228 goto out;
229 if (sccb->header.response_code != 0x0010) {
230 pr_warning("readcpuinfo failed (response=0x%04x)\n",
231 sccb->header.response_code);
232 rc = -EIO;
233 goto out;
235 sclp_fill_cpu_info(info, sccb);
236 out:
237 free_page((unsigned long) sccb);
238 return rc;
241 struct cpu_configure_sccb {
242 struct sccb_header header;
243 } __attribute__((packed, aligned(8)));
245 static int do_cpu_configure(sclp_cmdw_t cmd)
247 struct cpu_configure_sccb *sccb;
248 int rc;
250 if (!SCLP_HAS_CPU_RECONFIG)
251 return -EOPNOTSUPP;
253 * This is not going to cross a page boundary since we force
254 * kmalloc to have a minimum alignment of 8 bytes on s390.
256 sccb = kzalloc(sizeof(*sccb), GFP_KERNEL | GFP_DMA);
257 if (!sccb)
258 return -ENOMEM;
259 sccb->header.length = sizeof(*sccb);
260 rc = do_sync_request(cmd, sccb);
261 if (rc)
262 goto out;
263 switch (sccb->header.response_code) {
264 case 0x0020:
265 case 0x0120:
266 break;
267 default:
268 pr_warning("configure cpu failed (cmd=0x%08x, "
269 "response=0x%04x)\n", cmd,
270 sccb->header.response_code);
271 rc = -EIO;
272 break;
274 out:
275 kfree(sccb);
276 return rc;
279 int sclp_cpu_configure(u8 cpu)
281 return do_cpu_configure(SCLP_CMDW_CONFIGURE_CPU | cpu << 8);
284 int sclp_cpu_deconfigure(u8 cpu)
286 return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
289 #ifdef CONFIG_MEMORY_HOTPLUG
291 static DEFINE_MUTEX(sclp_mem_mutex);
292 static LIST_HEAD(sclp_mem_list);
293 static u8 sclp_max_storage_id;
294 static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
296 struct memory_increment {
297 struct list_head list;
298 u16 rn;
299 int standby;
300 int usecount;
303 struct assign_storage_sccb {
304 struct sccb_header header;
305 u16 rn;
306 } __packed;
308 static unsigned long long rn2addr(u16 rn)
310 return (unsigned long long) (rn - 1) * rzm;
313 static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
315 struct assign_storage_sccb *sccb;
316 int rc;
318 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
319 if (!sccb)
320 return -ENOMEM;
321 sccb->header.length = PAGE_SIZE;
322 sccb->rn = rn;
323 rc = do_sync_request(cmd, sccb);
324 if (rc)
325 goto out;
326 switch (sccb->header.response_code) {
327 case 0x0020:
328 case 0x0120:
329 break;
330 default:
331 pr_warning("assign storage failed (cmd=0x%08x, "
332 "response=0x%04x, rn=0x%04x)\n", cmd,
333 sccb->header.response_code, rn);
334 rc = -EIO;
335 break;
337 out:
338 free_page((unsigned long) sccb);
339 return rc;
342 static int sclp_assign_storage(u16 rn)
344 return do_assign_storage(0x000d0001, rn);
347 static int sclp_unassign_storage(u16 rn)
349 return do_assign_storage(0x000c0001, rn);
352 struct attach_storage_sccb {
353 struct sccb_header header;
354 u16 :16;
355 u16 assigned;
356 u32 :32;
357 u32 entries[0];
358 } __packed;
360 static int sclp_attach_storage(u8 id)
362 struct attach_storage_sccb *sccb;
363 int rc;
364 int i;
366 sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
367 if (!sccb)
368 return -ENOMEM;
369 sccb->header.length = PAGE_SIZE;
370 rc = do_sync_request(0x00080001 | id << 8, sccb);
371 if (rc)
372 goto out;
373 switch (sccb->header.response_code) {
374 case 0x0020:
375 set_bit(id, sclp_storage_ids);
376 for (i = 0; i < sccb->assigned; i++)
377 sclp_unassign_storage(sccb->entries[i] >> 16);
378 break;
379 default:
380 rc = -EIO;
381 break;
383 out:
384 free_page((unsigned long) sccb);
385 return rc;
388 static int sclp_mem_change_state(unsigned long start, unsigned long size,
389 int online)
391 struct memory_increment *incr;
392 unsigned long long istart;
393 int rc = 0;
395 list_for_each_entry(incr, &sclp_mem_list, list) {
396 istart = rn2addr(incr->rn);
397 if (start + size - 1 < istart)
398 break;
399 if (start > istart + rzm - 1)
400 continue;
401 if (online) {
402 if (incr->usecount++)
403 continue;
405 * Don't break the loop if one assign fails. Loop may
406 * be walked again on CANCEL and we can't save
407 * information if state changed before or not.
408 * So continue and increase usecount for all increments.
410 rc |= sclp_assign_storage(incr->rn);
411 } else {
412 if (--incr->usecount)
413 continue;
414 sclp_unassign_storage(incr->rn);
417 return rc ? -EIO : 0;
420 static int sclp_mem_notifier(struct notifier_block *nb,
421 unsigned long action, void *data)
423 unsigned long start, size;
424 struct memory_notify *arg;
425 unsigned char id;
426 int rc = 0;
428 arg = data;
429 start = arg->start_pfn << PAGE_SHIFT;
430 size = arg->nr_pages << PAGE_SHIFT;
431 mutex_lock(&sclp_mem_mutex);
432 for (id = 0; id <= sclp_max_storage_id; id++)
433 if (!test_bit(id, sclp_storage_ids))
434 sclp_attach_storage(id);
435 switch (action) {
436 case MEM_ONLINE:
437 case MEM_GOING_OFFLINE:
438 case MEM_CANCEL_OFFLINE:
439 break;
440 case MEM_GOING_ONLINE:
441 rc = sclp_mem_change_state(start, size, 1);
442 break;
443 case MEM_CANCEL_ONLINE:
444 sclp_mem_change_state(start, size, 0);
445 break;
446 case MEM_OFFLINE:
447 sclp_mem_change_state(start, size, 0);
448 break;
449 default:
450 rc = -EINVAL;
451 break;
453 mutex_unlock(&sclp_mem_mutex);
454 return rc ? NOTIFY_BAD : NOTIFY_OK;
457 static struct notifier_block sclp_mem_nb = {
458 .notifier_call = sclp_mem_notifier,
461 static void __init add_memory_merged(u16 rn)
463 static u16 first_rn, num;
464 unsigned long long start, size;
466 if (rn && first_rn && (first_rn + num == rn)) {
467 num++;
468 return;
470 if (!first_rn)
471 goto skip_add;
472 start = rn2addr(first_rn);
473 size = (unsigned long long ) num * rzm;
474 if (start >= VMEM_MAX_PHYS)
475 goto skip_add;
476 if (start + size > VMEM_MAX_PHYS)
477 size = VMEM_MAX_PHYS - start;
478 if (memory_end_set && (start >= memory_end))
479 goto skip_add;
480 if (memory_end_set && (start + size > memory_end))
481 size = memory_end - start;
482 add_memory(0, start, size);
483 skip_add:
484 first_rn = rn;
485 num = 1;
488 static void __init sclp_add_standby_memory(void)
490 struct memory_increment *incr;
492 list_for_each_entry(incr, &sclp_mem_list, list)
493 if (incr->standby)
494 add_memory_merged(incr->rn);
495 add_memory_merged(0);
498 static void __init insert_increment(u16 rn, int standby, int assigned)
500 struct memory_increment *incr, *new_incr;
501 struct list_head *prev;
502 u16 last_rn;
504 new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
505 if (!new_incr)
506 return;
507 new_incr->rn = rn;
508 new_incr->standby = standby;
509 last_rn = 0;
510 prev = &sclp_mem_list;
511 list_for_each_entry(incr, &sclp_mem_list, list) {
512 if (assigned && incr->rn > rn)
513 break;
514 if (!assigned && incr->rn - last_rn > 1)
515 break;
516 last_rn = incr->rn;
517 prev = &incr->list;
519 if (!assigned)
520 new_incr->rn = last_rn + 1;
521 if (new_incr->rn > rnmax) {
522 kfree(new_incr);
523 return;
525 list_add(&new_incr->list, prev);
528 struct read_storage_sccb {
529 struct sccb_header header;
530 u16 max_id;
531 u16 assigned;
532 u16 standby;
533 u16 :16;
534 u32 entries[0];
535 } __packed;
537 static int __init sclp_detect_standby_memory(void)
539 struct read_storage_sccb *sccb;
540 int i, id, assigned, rc;
542 if (!early_read_info_sccb_valid)
543 return 0;
544 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
545 return 0;
546 rc = -ENOMEM;
547 sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
548 if (!sccb)
549 goto out;
550 assigned = 0;
551 for (id = 0; id <= sclp_max_storage_id; id++) {
552 memset(sccb, 0, PAGE_SIZE);
553 sccb->header.length = PAGE_SIZE;
554 rc = do_sync_request(0x00040001 | id << 8, sccb);
555 if (rc)
556 goto out;
557 switch (sccb->header.response_code) {
558 case 0x0010:
559 set_bit(id, sclp_storage_ids);
560 for (i = 0; i < sccb->assigned; i++) {
561 if (!sccb->entries[i])
562 continue;
563 assigned++;
564 insert_increment(sccb->entries[i] >> 16, 0, 1);
566 break;
567 case 0x0310:
568 break;
569 case 0x0410:
570 for (i = 0; i < sccb->assigned; i++) {
571 if (!sccb->entries[i])
572 continue;
573 assigned++;
574 insert_increment(sccb->entries[i] >> 16, 1, 1);
576 break;
577 default:
578 rc = -EIO;
579 break;
581 if (!rc)
582 sclp_max_storage_id = sccb->max_id;
584 if (rc || list_empty(&sclp_mem_list))
585 goto out;
586 for (i = 1; i <= rnmax - assigned; i++)
587 insert_increment(0, 1, 0);
588 rc = register_memory_notifier(&sclp_mem_nb);
589 if (rc)
590 goto out;
591 sclp_add_standby_memory();
592 out:
593 free_page((unsigned long) sccb);
594 return rc;
596 __initcall(sclp_detect_standby_memory);
598 #endif /* CONFIG_MEMORY_HOTPLUG */
601 * Channel path configuration related functions.
604 #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
605 #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
606 #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
608 struct chp_cfg_sccb {
609 struct sccb_header header;
610 u8 ccm;
611 u8 reserved[6];
612 u8 cssid;
613 } __attribute__((packed));
615 static int do_chp_configure(sclp_cmdw_t cmd)
617 struct chp_cfg_sccb *sccb;
618 int rc;
620 if (!SCLP_HAS_CHP_RECONFIG)
621 return -EOPNOTSUPP;
622 /* Prepare sccb. */
623 sccb = (struct chp_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
624 if (!sccb)
625 return -ENOMEM;
626 sccb->header.length = sizeof(*sccb);
627 rc = do_sync_request(cmd, sccb);
628 if (rc)
629 goto out;
630 switch (sccb->header.response_code) {
631 case 0x0020:
632 case 0x0120:
633 case 0x0440:
634 case 0x0450:
635 break;
636 default:
637 pr_warning("configure channel-path failed "
638 "(cmd=0x%08x, response=0x%04x)\n", cmd,
639 sccb->header.response_code);
640 rc = -EIO;
641 break;
643 out:
644 free_page((unsigned long) sccb);
645 return rc;
649 * sclp_chp_configure - perform configure channel-path sclp command
650 * @chpid: channel-path ID
652 * Perform configure channel-path command sclp command for specified chpid.
653 * Return 0 after command successfully finished, non-zero otherwise.
655 int sclp_chp_configure(struct chp_id chpid)
657 return do_chp_configure(SCLP_CMDW_CONFIGURE_CHPATH | chpid.id << 8);
661 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
662 * @chpid: channel-path ID
664 * Perform deconfigure channel-path command sclp command for specified chpid
665 * and wait for completion. On success return 0. Return non-zero otherwise.
667 int sclp_chp_deconfigure(struct chp_id chpid)
669 return do_chp_configure(SCLP_CMDW_DECONFIGURE_CHPATH | chpid.id << 8);
672 struct chp_info_sccb {
673 struct sccb_header header;
674 u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
675 u8 standby[SCLP_CHP_INFO_MASK_SIZE];
676 u8 configured[SCLP_CHP_INFO_MASK_SIZE];
677 u8 ccm;
678 u8 reserved[6];
679 u8 cssid;
680 } __attribute__((packed));
683 * sclp_chp_read_info - perform read channel-path information sclp command
684 * @info: resulting channel-path information data
686 * Perform read channel-path information sclp command and wait for completion.
687 * On success, store channel-path information in @info and return 0. Return
688 * non-zero otherwise.
690 int sclp_chp_read_info(struct sclp_chp_info *info)
692 struct chp_info_sccb *sccb;
693 int rc;
695 if (!SCLP_HAS_CHP_INFO)
696 return -EOPNOTSUPP;
697 /* Prepare sccb. */
698 sccb = (struct chp_info_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
699 if (!sccb)
700 return -ENOMEM;
701 sccb->header.length = sizeof(*sccb);
702 rc = do_sync_request(SCLP_CMDW_READ_CHPATH_INFORMATION, sccb);
703 if (rc)
704 goto out;
705 if (sccb->header.response_code != 0x0010) {
706 pr_warning("read channel-path info failed "
707 "(response=0x%04x)\n", sccb->header.response_code);
708 rc = -EIO;
709 goto out;
711 memcpy(info->recognized, sccb->recognized, SCLP_CHP_INFO_MASK_SIZE);
712 memcpy(info->standby, sccb->standby, SCLP_CHP_INFO_MASK_SIZE);
713 memcpy(info->configured, sccb->configured, SCLP_CHP_INFO_MASK_SIZE);
714 out:
715 free_page((unsigned long) sccb);
716 return rc;