sclp_cmd.c 19 KB

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