8 #define KMSG_COMPONENT "sclp_cmd"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
20 #include <linux/module.h>
22 #include <asm/chpid.h>
24 #include <asm/setup.h>
29 #define SCLP_CMDW_READ_SCP_INFO 0x00020001
30 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
58 static unsigned long long rzm;
59 static unsigned long long rnmax;
79 static void __init sclp_read_info_early(
void)
87 sccb = &early_read_info_sccb;
90 memset(sccb, 0,
sizeof(*sccb));
91 sccb->
header.length =
sizeof(*sccb);
92 sccb->
header.function_code = 0x80;
93 sccb->
header.control_mask[2] = 0x80;
94 rc = sclp_cmd_sync_early(commands[i], sccb);
95 }
while (rc == -
EBUSY);
99 if (sccb->
header.response_code == 0x10) {
100 early_read_info_sccb_valid = 1;
103 if (sccb->
header.response_code != 0x1f0)
108 static void __init sclp_event_mask_early(
void)
110 struct init_sccb *sccb = &early_event_mask_sccb;
114 memset(sccb, 0,
sizeof(*sccb));
115 sccb->
header.length =
sizeof(*sccb);
118 }
while (rc == -
EBUSY);
125 sclp_read_info_early();
126 if (!early_read_info_sccb_valid)
129 sccb = &early_read_info_sccb;
131 sclp_fac84 = sccb->
fac84;
132 sclp_fac85 = sccb->
fac85;
137 sclp_event_mask_early();
142 struct init_sccb *sccb = &early_event_mask_sccb;
144 if (sccb->
header.response_code != 0x20)
153 struct init_sccb *sccb = &early_event_mask_sccb;
155 if (sccb->
header.response_code != 0x20)
186 if (!early_read_info_sccb_valid)
188 sccb = &early_read_info_sccb;
190 if (sccb->
flags & 0x2)
202 static int do_sync_request(
sclp_cmdw_t cmd,
void *sccb)
208 request = kzalloc(
sizeof(*request),
GFP_KERNEL);
214 request->
callback = sclp_sync_callback;
226 pr_warning(
"sync request failed (cmd=0x%08x, "
227 "status=0x%02x)\n", cmd, request->
status);
239 #define SCLP_CMDW_READ_CPU_INFO 0x00010001
240 #define SCLP_CMDW_CONFIGURE_CPU 0x00110001
241 #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001
257 memset(info, 0,
sizeof(*info));
276 sccb->
header.length =
sizeof(*sccb);
280 if (sccb->
header.response_code != 0x0010) {
281 pr_warning(
"readcpuinfo failed (response=0x%04x)\n",
282 sccb->
header.response_code);
286 sclp_fill_cpu_info(info, sccb);
310 sccb->
header.length =
sizeof(*sccb);
311 rc = do_sync_request(cmd, sccb);
314 switch (sccb->
header.response_code) {
319 pr_warning(
"configure cpu failed (cmd=0x%08x, "
320 "response=0x%04x)\n", cmd,
321 sccb->
header.response_code);
340 #ifdef CONFIG_MEMORY_HOTPLUG
344 static u8 sclp_max_storage_id;
346 static int sclp_mem_state_changed;
348 struct memory_increment {
355 struct assign_storage_sccb {
367 static unsigned long long rn2addr(
u16 rn)
369 return (
unsigned long long) (rn - 1) * rzm;
374 struct assign_storage_sccb *sccb;
382 rc = do_sync_request(cmd, sccb);
385 switch (sccb->header.response_code) {
390 pr_warning(
"assign storage failed (cmd=0x%08x, "
391 "response=0x%04x, rn=0x%04x)\n", cmd,
392 sccb->header.response_code, rn);
401 static int sclp_assign_storage(
u16 rn)
406 rc = do_assign_storage(0x000d0001, rn);
409 start = address = rn2addr(rn);
410 for (; address < start + rzm; address +=
PAGE_SIZE)
416 static int sclp_unassign_storage(
u16 rn)
418 return do_assign_storage(0x000c0001, rn);
421 struct attach_storage_sccb {
429 static int sclp_attach_storage(
u8 id)
431 struct attach_storage_sccb *sccb;
439 rc = do_sync_request(0x00080001 |
id << 8, sccb);
442 switch (sccb->header.response_code) {
445 for (i = 0; i < sccb->assigned; i++) {
446 if (sccb->entries[i])
447 sclp_unassign_storage(sccb->entries[i] >> 16);
459 static int sclp_mem_change_state(
unsigned long start,
unsigned long size,
462 struct memory_increment *incr;
463 unsigned long long istart;
467 istart = rn2addr(incr->rn);
468 if (start + size - 1 < istart)
470 if (start > istart + rzm - 1)
473 if (incr->usecount++)
481 rc |= sclp_assign_storage(incr->rn);
483 if (--incr->usecount)
485 sclp_unassign_storage(incr->rn);
488 return rc ? -
EIO : 0;
504 sclp_attach_storage(
id);
511 rc = sclp_mem_change_state(start, size, 1);
514 sclp_mem_change_state(start, size, 0);
517 sclp_mem_change_state(start, size, 0);
524 sclp_mem_state_changed = 1;
526 return rc ? NOTIFY_BAD : NOTIFY_OK;
533 static void __init add_memory_merged(
u16 rn)
538 if (rn && first_rn && (first_rn + num == rn)) {
544 start = rn2addr(first_rn);
545 size = (
unsigned long long ) num * rzm;
560 static void __init sclp_add_standby_memory(
void)
562 struct memory_increment *incr;
566 add_memory_merged(incr->rn);
567 add_memory_merged(0);
572 struct memory_increment *incr, *new_incr;
576 new_incr = kzalloc(
sizeof(*new_incr),
GFP_KERNEL);
582 new_incr->usecount = 1;
584 prev = &sclp_mem_list;
586 if (assigned && incr->rn > rn)
588 if (!assigned && incr->rn - last_rn > 1)
594 new_incr->rn = last_rn + 1;
595 if (new_incr->rn > rnmax) {
599 list_add(&new_incr->list, prev);
602 static int sclp_mem_freeze(
struct device *
dev)
604 if (!sclp_mem_state_changed)
606 pr_err(
"Memory hotplug state changed, suspend refused.\n");
610 struct read_storage_sccb {
619 static const struct dev_pm_ops sclp_mem_pm_ops = {
620 .
freeze = sclp_mem_freeze,
626 .pm = &sclp_mem_pm_ops,
630 static int __init sclp_detect_standby_memory(
void)
633 struct read_storage_sccb *sccb;
634 int i,
id, assigned,
rc;
636 if (!early_read_info_sccb_valid)
638 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
645 for (
id = 0;
id <= sclp_max_storage_id;
id++) {
648 rc = do_sync_request(0x00040001 |
id << 8, sccb);
651 switch (sccb->header.response_code) {
654 for (i = 0; i < sccb->assigned; i++) {
655 if (!sccb->entries[i])
658 insert_increment(sccb->entries[i] >> 16, 0, 1);
664 for (i = 0; i < sccb->assigned; i++) {
665 if (!sccb->entries[i])
668 insert_increment(sccb->entries[i] >> 16, 1, 1);
676 sclp_max_storage_id = sccb->max_id;
678 if (rc || list_empty(&sclp_mem_list))
680 for (i = 1; i <= rnmax - assigned; i++)
681 insert_increment(0, 1, 0);
688 sclp_pdev = platform_device_register_simple(
"sclp_mem", -1,
NULL, 0);
689 rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0;
692 sclp_add_standby_memory();
708 #define SCLP_CMDW_CONFIGURE_CHPATH 0x000f0001
709 #define SCLP_CMDW_DECONFIGURE_CHPATH 0x000e0001
710 #define SCLP_CMDW_READ_CHPATH_INFORMATION 0x00030001
730 sccb->
header.length =
sizeof(*sccb);
731 rc = do_sync_request(cmd, sccb);
734 switch (sccb->
header.response_code) {
742 "(cmd=0x%08x, response=0x%04x)\n", cmd,
743 sccb->
header.response_code);
805 sccb->
header.length =
sizeof(*sccb);
809 if (sccb->
header.response_code != 0x0010) {
811 "(response=0x%04x)\n", sccb->
header.response_code);