sclp_cmd.c 19 KB

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