lparcfg.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * PowerPC64 LPAR Configuration Information Driver
  3. *
  4. * Dave Engebretsen engebret@us.ibm.com
  5. * Copyright (c) 2003 Dave Engebretsen
  6. * Will Schmidt willschm@us.ibm.com
  7. * SPLPAR updates, Copyright (c) 2003 Will Schmidt IBM Corporation.
  8. * seq_file updates, Copyright (c) 2004 Will Schmidt IBM Corporation.
  9. * Nathan Lynch nathanl@austin.ibm.com
  10. * Added lparcfg_write, Copyright (C) 2004 Nathan Lynch IBM Corporation.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. * This driver creates a proc file at /proc/ppc64/lparcfg which contains
  18. * keyword - value pairs that specify the configuration of the partition.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/errno.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/init.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/slab.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/lppaca.h>
  29. #include <asm/hvcall.h>
  30. #include <asm/firmware.h>
  31. #include <asm/rtas.h>
  32. #include <asm/time.h>
  33. #include <asm/prom.h>
  34. #include <asm/vdso_datapage.h>
  35. #include <asm/vio.h>
  36. #include <asm/mmu.h>
  37. #include <asm/machdep.h>
  38. /*
  39. * This isn't a module but we expose that to userspace
  40. * via /proc so leave the definitions here
  41. */
  42. #define MODULE_VERS "1.9"
  43. #define MODULE_NAME "lparcfg"
  44. /* #define LPARCFG_DEBUG */
  45. /*
  46. * Track sum of all purrs across all processors. This is used to further
  47. * calculate usage values by different applications
  48. */
  49. static unsigned long get_purr(void)
  50. {
  51. unsigned long sum_purr = 0;
  52. int cpu;
  53. for_each_possible_cpu(cpu) {
  54. struct cpu_usage *cu;
  55. cu = &per_cpu(cpu_usage_array, cpu);
  56. sum_purr += cu->current_tb;
  57. }
  58. return sum_purr;
  59. }
  60. /*
  61. * Methods used to fetch LPAR data when running on a pSeries platform.
  62. */
  63. struct hvcall_ppp_data {
  64. u64 entitlement;
  65. u64 unallocated_entitlement;
  66. u16 group_num;
  67. u16 pool_num;
  68. u8 capped;
  69. u8 weight;
  70. u8 unallocated_weight;
  71. u16 active_procs_in_pool;
  72. u16 active_system_procs;
  73. u16 phys_platform_procs;
  74. u32 max_proc_cap_avail;
  75. u32 entitled_proc_cap_avail;
  76. };
  77. /*
  78. * H_GET_PPP hcall returns info in 4 parms.
  79. * entitled_capacity,unallocated_capacity,
  80. * aggregation, resource_capability).
  81. *
  82. * R4 = Entitled Processor Capacity Percentage.
  83. * R5 = Unallocated Processor Capacity Percentage.
  84. * R6 (AABBCCDDEEFFGGHH).
  85. * XXXX - reserved (0)
  86. * XXXX - reserved (0)
  87. * XXXX - Group Number
  88. * XXXX - Pool Number.
  89. * R7 (IIJJKKLLMMNNOOPP).
  90. * XX - reserved. (0)
  91. * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
  92. * XX - variable processor Capacity Weight
  93. * XX - Unallocated Variable Processor Capacity Weight.
  94. * XXXX - Active processors in Physical Processor Pool.
  95. * XXXX - Processors active on platform.
  96. * R8 (QQQQRRRRRRSSSSSS). if ibm,partition-performance-parameters-level >= 1
  97. * XXXX - Physical platform procs allocated to virtualization.
  98. * XXXXXX - Max procs capacity % available to the partitions pool.
  99. * XXXXXX - Entitled procs capacity % available to the
  100. * partitions pool.
  101. */
  102. static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data)
  103. {
  104. unsigned long rc;
  105. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
  106. rc = plpar_hcall9(H_GET_PPP, retbuf);
  107. ppp_data->entitlement = retbuf[0];
  108. ppp_data->unallocated_entitlement = retbuf[1];
  109. ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
  110. ppp_data->pool_num = retbuf[2] & 0xffff;
  111. ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01;
  112. ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff;
  113. ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff;
  114. ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff;
  115. ppp_data->active_system_procs = retbuf[3] & 0xffff;
  116. ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8;
  117. ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff;
  118. ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff;
  119. return rc;
  120. }
  121. static unsigned h_pic(unsigned long *pool_idle_time,
  122. unsigned long *num_procs)
  123. {
  124. unsigned long rc;
  125. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  126. rc = plpar_hcall(H_PIC, retbuf);
  127. *pool_idle_time = retbuf[0];
  128. *num_procs = retbuf[1];
  129. return rc;
  130. }
  131. /*
  132. * parse_ppp_data
  133. * Parse out the data returned from h_get_ppp and h_pic
  134. */
  135. static void parse_ppp_data(struct seq_file *m)
  136. {
  137. struct hvcall_ppp_data ppp_data;
  138. struct device_node *root;
  139. const __be32 *perf_level;
  140. int rc;
  141. rc = h_get_ppp(&ppp_data);
  142. if (rc)
  143. return;
  144. seq_printf(m, "partition_entitled_capacity=%lld\n",
  145. ppp_data.entitlement);
  146. seq_printf(m, "group=%d\n", ppp_data.group_num);
  147. seq_printf(m, "system_active_processors=%d\n",
  148. ppp_data.active_system_procs);
  149. /* pool related entries are appropriate for shared configs */
  150. if (lppaca_shared_proc(get_lppaca())) {
  151. unsigned long pool_idle_time, pool_procs;
  152. seq_printf(m, "pool=%d\n", ppp_data.pool_num);
  153. /* report pool_capacity in percentage */
  154. seq_printf(m, "pool_capacity=%d\n",
  155. ppp_data.active_procs_in_pool * 100);
  156. h_pic(&pool_idle_time, &pool_procs);
  157. seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
  158. seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
  159. }
  160. seq_printf(m, "unallocated_capacity_weight=%d\n",
  161. ppp_data.unallocated_weight);
  162. seq_printf(m, "capacity_weight=%d\n", ppp_data.weight);
  163. seq_printf(m, "capped=%d\n", ppp_data.capped);
  164. seq_printf(m, "unallocated_capacity=%lld\n",
  165. ppp_data.unallocated_entitlement);
  166. /* The last bits of information returned from h_get_ppp are only
  167. * valid if the ibm,partition-performance-parameters-level
  168. * property is >= 1.
  169. */
  170. root = of_find_node_by_path("/");
  171. if (root) {
  172. perf_level = of_get_property(root,
  173. "ibm,partition-performance-parameters-level",
  174. NULL);
  175. if (perf_level && (be32_to_cpup(perf_level) >= 1)) {
  176. seq_printf(m,
  177. "physical_procs_allocated_to_virtualization=%d\n",
  178. ppp_data.phys_platform_procs);
  179. seq_printf(m, "max_proc_capacity_available=%d\n",
  180. ppp_data.max_proc_cap_avail);
  181. seq_printf(m, "entitled_proc_capacity_available=%d\n",
  182. ppp_data.entitled_proc_cap_avail);
  183. }
  184. of_node_put(root);
  185. }
  186. }
  187. /**
  188. * parse_mpp_data
  189. * Parse out data returned from h_get_mpp
  190. */
  191. static void parse_mpp_data(struct seq_file *m)
  192. {
  193. struct hvcall_mpp_data mpp_data;
  194. int rc;
  195. rc = h_get_mpp(&mpp_data);
  196. if (rc)
  197. return;
  198. seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
  199. if (mpp_data.mapped_mem != -1)
  200. seq_printf(m, "mapped_entitled_memory=%ld\n",
  201. mpp_data.mapped_mem);
  202. seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
  203. seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
  204. seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
  205. seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
  206. mpp_data.unallocated_mem_weight);
  207. seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
  208. mpp_data.unallocated_entitlement);
  209. if (mpp_data.pool_size != -1)
  210. seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
  211. mpp_data.pool_size);
  212. seq_printf(m, "entitled_memory_loan_request=%ld\n",
  213. mpp_data.loan_request);
  214. seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
  215. }
  216. /**
  217. * parse_mpp_x_data
  218. * Parse out data returned from h_get_mpp_x
  219. */
  220. static void parse_mpp_x_data(struct seq_file *m)
  221. {
  222. struct hvcall_mpp_x_data mpp_x_data;
  223. if (!firmware_has_feature(FW_FEATURE_XCMO))
  224. return;
  225. if (h_get_mpp_x(&mpp_x_data))
  226. return;
  227. seq_printf(m, "coalesced_bytes=%ld\n", mpp_x_data.coalesced_bytes);
  228. if (mpp_x_data.pool_coalesced_bytes)
  229. seq_printf(m, "pool_coalesced_bytes=%ld\n",
  230. mpp_x_data.pool_coalesced_bytes);
  231. if (mpp_x_data.pool_purr_cycles)
  232. seq_printf(m, "coalesce_pool_purr=%ld\n", mpp_x_data.pool_purr_cycles);
  233. if (mpp_x_data.pool_spurr_cycles)
  234. seq_printf(m, "coalesce_pool_spurr=%ld\n", mpp_x_data.pool_spurr_cycles);
  235. }
  236. #define SPLPAR_CHARACTERISTICS_TOKEN 20
  237. #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
  238. /*
  239. * parse_system_parameter_string()
  240. * Retrieve the potential_processors, max_entitled_capacity and friends
  241. * through the get-system-parameter rtas call. Replace keyword strings as
  242. * necessary.
  243. */
  244. static void parse_system_parameter_string(struct seq_file *m)
  245. {
  246. int call_status;
  247. unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
  248. if (!local_buffer) {
  249. printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
  250. __FILE__, __func__, __LINE__);
  251. return;
  252. }
  253. spin_lock(&rtas_data_buf_lock);
  254. memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
  255. call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
  256. NULL,
  257. SPLPAR_CHARACTERISTICS_TOKEN,
  258. __pa(rtas_data_buf),
  259. RTAS_DATA_BUF_SIZE);
  260. memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
  261. local_buffer[SPLPAR_MAXLENGTH - 1] = '\0';
  262. spin_unlock(&rtas_data_buf_lock);
  263. if (call_status != 0) {
  264. printk(KERN_INFO
  265. "%s %s Error calling get-system-parameter (0x%x)\n",
  266. __FILE__, __func__, call_status);
  267. } else {
  268. int splpar_strlen;
  269. int idx, w_idx;
  270. char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
  271. if (!workbuffer) {
  272. printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
  273. __FILE__, __func__, __LINE__);
  274. kfree(local_buffer);
  275. return;
  276. }
  277. #ifdef LPARCFG_DEBUG
  278. printk(KERN_INFO "success calling get-system-parameter\n");
  279. #endif
  280. splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
  281. local_buffer += 2; /* step over strlen value */
  282. w_idx = 0;
  283. idx = 0;
  284. while ((*local_buffer) && (idx < splpar_strlen)) {
  285. workbuffer[w_idx++] = local_buffer[idx++];
  286. if ((local_buffer[idx] == ',')
  287. || (local_buffer[idx] == '\0')) {
  288. workbuffer[w_idx] = '\0';
  289. if (w_idx) {
  290. /* avoid the empty string */
  291. seq_printf(m, "%s\n", workbuffer);
  292. }
  293. memset(workbuffer, 0, SPLPAR_MAXLENGTH);
  294. idx++; /* skip the comma */
  295. w_idx = 0;
  296. } else if (local_buffer[idx] == '=') {
  297. /* code here to replace workbuffer contents
  298. with different keyword strings */
  299. if (0 == strcmp(workbuffer, "MaxEntCap")) {
  300. strcpy(workbuffer,
  301. "partition_max_entitled_capacity");
  302. w_idx = strlen(workbuffer);
  303. }
  304. if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
  305. strcpy(workbuffer,
  306. "system_potential_processors");
  307. w_idx = strlen(workbuffer);
  308. }
  309. }
  310. }
  311. kfree(workbuffer);
  312. local_buffer -= 2; /* back up over strlen value */
  313. }
  314. kfree(local_buffer);
  315. }
  316. /* Return the number of processors in the system.
  317. * This function reads through the device tree and counts
  318. * the virtual processors, this does not include threads.
  319. */
  320. static int lparcfg_count_active_processors(void)
  321. {
  322. struct device_node *cpus_dn = NULL;
  323. int count = 0;
  324. while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
  325. #ifdef LPARCFG_DEBUG
  326. printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
  327. #endif
  328. count++;
  329. }
  330. return count;
  331. }
  332. static void pseries_cmo_data(struct seq_file *m)
  333. {
  334. int cpu;
  335. unsigned long cmo_faults = 0;
  336. unsigned long cmo_fault_time = 0;
  337. seq_printf(m, "cmo_enabled=%d\n", firmware_has_feature(FW_FEATURE_CMO));
  338. if (!firmware_has_feature(FW_FEATURE_CMO))
  339. return;
  340. for_each_possible_cpu(cpu) {
  341. cmo_faults += be64_to_cpu(lppaca_of(cpu).cmo_faults);
  342. cmo_fault_time += be64_to_cpu(lppaca_of(cpu).cmo_fault_time);
  343. }
  344. seq_printf(m, "cmo_faults=%lu\n", cmo_faults);
  345. seq_printf(m, "cmo_fault_time_usec=%lu\n",
  346. cmo_fault_time / tb_ticks_per_usec);
  347. seq_printf(m, "cmo_primary_psp=%d\n", cmo_get_primary_psp());
  348. seq_printf(m, "cmo_secondary_psp=%d\n", cmo_get_secondary_psp());
  349. seq_printf(m, "cmo_page_size=%lu\n", cmo_get_page_size());
  350. }
  351. static void splpar_dispatch_data(struct seq_file *m)
  352. {
  353. int cpu;
  354. unsigned long dispatches = 0;
  355. unsigned long dispatch_dispersions = 0;
  356. for_each_possible_cpu(cpu) {
  357. dispatches += be32_to_cpu(lppaca_of(cpu).yield_count);
  358. dispatch_dispersions +=
  359. be32_to_cpu(lppaca_of(cpu).dispersion_count);
  360. }
  361. seq_printf(m, "dispatches=%lu\n", dispatches);
  362. seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions);
  363. }
  364. static void parse_em_data(struct seq_file *m)
  365. {
  366. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  367. if (firmware_has_feature(FW_FEATURE_LPAR) &&
  368. plpar_hcall(H_GET_EM_PARMS, retbuf) == H_SUCCESS)
  369. seq_printf(m, "power_mode_data=%016lx\n", retbuf[0]);
  370. }
  371. static int pseries_lparcfg_data(struct seq_file *m, void *v)
  372. {
  373. int partition_potential_processors;
  374. int partition_active_processors;
  375. struct device_node *rtas_node;
  376. const __be32 *lrdrp = NULL;
  377. rtas_node = of_find_node_by_path("/rtas");
  378. if (rtas_node)
  379. lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
  380. if (lrdrp == NULL) {
  381. partition_potential_processors = vdso_data->processorCount;
  382. } else {
  383. partition_potential_processors = be32_to_cpup(lrdrp + 4);
  384. }
  385. of_node_put(rtas_node);
  386. partition_active_processors = lparcfg_count_active_processors();
  387. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  388. /* this call handles the ibm,get-system-parameter contents */
  389. parse_system_parameter_string(m);
  390. parse_ppp_data(m);
  391. parse_mpp_data(m);
  392. parse_mpp_x_data(m);
  393. pseries_cmo_data(m);
  394. splpar_dispatch_data(m);
  395. seq_printf(m, "purr=%ld\n", get_purr());
  396. } else { /* non SPLPAR case */
  397. seq_printf(m, "system_active_processors=%d\n",
  398. partition_potential_processors);
  399. seq_printf(m, "system_potential_processors=%d\n",
  400. partition_potential_processors);
  401. seq_printf(m, "partition_max_entitled_capacity=%d\n",
  402. partition_potential_processors * 100);
  403. seq_printf(m, "partition_entitled_capacity=%d\n",
  404. partition_active_processors * 100);
  405. }
  406. seq_printf(m, "partition_active_processors=%d\n",
  407. partition_active_processors);
  408. seq_printf(m, "partition_potential_processors=%d\n",
  409. partition_potential_processors);
  410. seq_printf(m, "shared_processor_mode=%d\n",
  411. lppaca_shared_proc(get_lppaca()));
  412. #ifdef CONFIG_PPC_STD_MMU_64
  413. seq_printf(m, "slb_size=%d\n", mmu_slb_size);
  414. #endif
  415. parse_em_data(m);
  416. return 0;
  417. }
  418. static ssize_t update_ppp(u64 *entitlement, u8 *weight)
  419. {
  420. struct hvcall_ppp_data ppp_data;
  421. u8 new_weight;
  422. u64 new_entitled;
  423. ssize_t retval;
  424. /* Get our current parameters */
  425. retval = h_get_ppp(&ppp_data);
  426. if (retval)
  427. return retval;
  428. if (entitlement) {
  429. new_weight = ppp_data.weight;
  430. new_entitled = *entitlement;
  431. } else if (weight) {
  432. new_weight = *weight;
  433. new_entitled = ppp_data.entitlement;
  434. } else
  435. return -EINVAL;
  436. pr_debug("%s: current_entitled = %llu, current_weight = %u\n",
  437. __func__, ppp_data.entitlement, ppp_data.weight);
  438. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  439. __func__, new_entitled, new_weight);
  440. retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
  441. return retval;
  442. }
  443. /**
  444. * update_mpp
  445. *
  446. * Update the memory entitlement and weight for the partition. Caller must
  447. * specify either a new entitlement or weight, not both, to be updated
  448. * since the h_set_mpp call takes both entitlement and weight as parameters.
  449. */
  450. static ssize_t update_mpp(u64 *entitlement, u8 *weight)
  451. {
  452. struct hvcall_mpp_data mpp_data;
  453. u64 new_entitled;
  454. u8 new_weight;
  455. ssize_t rc;
  456. if (entitlement) {
  457. /* Check with vio to ensure the new memory entitlement
  458. * can be handled.
  459. */
  460. rc = vio_cmo_entitlement_update(*entitlement);
  461. if (rc)
  462. return rc;
  463. }
  464. rc = h_get_mpp(&mpp_data);
  465. if (rc)
  466. return rc;
  467. if (entitlement) {
  468. new_weight = mpp_data.mem_weight;
  469. new_entitled = *entitlement;
  470. } else if (weight) {
  471. new_weight = *weight;
  472. new_entitled = mpp_data.entitled_mem;
  473. } else
  474. return -EINVAL;
  475. pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
  476. __func__, mpp_data.entitled_mem, mpp_data.mem_weight);
  477. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  478. __func__, new_entitled, new_weight);
  479. rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
  480. return rc;
  481. }
  482. /*
  483. * Interface for changing system parameters (variable capacity weight
  484. * and entitled capacity). Format of input is "param_name=value";
  485. * anything after value is ignored. Valid parameters at this time are
  486. * "partition_entitled_capacity" and "capacity_weight". We use
  487. * H_SET_PPP to alter parameters.
  488. *
  489. * This function should be invoked only on systems with
  490. * FW_FEATURE_SPLPAR.
  491. */
  492. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  493. size_t count, loff_t * off)
  494. {
  495. int kbuf_sz = 64;
  496. char kbuf[kbuf_sz];
  497. char *tmp;
  498. u64 new_entitled, *new_entitled_ptr = &new_entitled;
  499. u8 new_weight, *new_weight_ptr = &new_weight;
  500. ssize_t retval;
  501. if (!firmware_has_feature(FW_FEATURE_SPLPAR))
  502. return -EINVAL;
  503. if (count > kbuf_sz)
  504. return -EINVAL;
  505. if (copy_from_user(kbuf, buf, count))
  506. return -EFAULT;
  507. kbuf[count - 1] = '\0';
  508. tmp = strchr(kbuf, '=');
  509. if (!tmp)
  510. return -EINVAL;
  511. *tmp++ = '\0';
  512. if (!strcmp(kbuf, "partition_entitled_capacity")) {
  513. char *endp;
  514. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  515. if (endp == tmp)
  516. return -EINVAL;
  517. retval = update_ppp(new_entitled_ptr, NULL);
  518. } else if (!strcmp(kbuf, "capacity_weight")) {
  519. char *endp;
  520. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  521. if (endp == tmp)
  522. return -EINVAL;
  523. retval = update_ppp(NULL, new_weight_ptr);
  524. } else if (!strcmp(kbuf, "entitled_memory")) {
  525. char *endp;
  526. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  527. if (endp == tmp)
  528. return -EINVAL;
  529. retval = update_mpp(new_entitled_ptr, NULL);
  530. } else if (!strcmp(kbuf, "entitled_memory_weight")) {
  531. char *endp;
  532. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  533. if (endp == tmp)
  534. return -EINVAL;
  535. retval = update_mpp(NULL, new_weight_ptr);
  536. } else
  537. return -EINVAL;
  538. if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
  539. retval = count;
  540. } else if (retval == H_BUSY) {
  541. retval = -EBUSY;
  542. } else if (retval == H_HARDWARE) {
  543. retval = -EIO;
  544. } else if (retval == H_PARAMETER) {
  545. retval = -EINVAL;
  546. }
  547. return retval;
  548. }
  549. static int lparcfg_data(struct seq_file *m, void *v)
  550. {
  551. struct device_node *rootdn;
  552. const char *model = "";
  553. const char *system_id = "";
  554. const char *tmp;
  555. const __be32 *lp_index_ptr;
  556. unsigned int lp_index = 0;
  557. seq_printf(m, "%s %s\n", MODULE_NAME, MODULE_VERS);
  558. rootdn = of_find_node_by_path("/");
  559. if (rootdn) {
  560. tmp = of_get_property(rootdn, "model", NULL);
  561. if (tmp)
  562. model = tmp;
  563. tmp = of_get_property(rootdn, "system-id", NULL);
  564. if (tmp)
  565. system_id = tmp;
  566. lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
  567. NULL);
  568. if (lp_index_ptr)
  569. lp_index = be32_to_cpup(lp_index_ptr);
  570. of_node_put(rootdn);
  571. }
  572. seq_printf(m, "serial_number=%s\n", system_id);
  573. seq_printf(m, "system_type=%s\n", model);
  574. seq_printf(m, "partition_id=%d\n", (int)lp_index);
  575. return pseries_lparcfg_data(m, v);
  576. }
  577. static int lparcfg_open(struct inode *inode, struct file *file)
  578. {
  579. return single_open(file, lparcfg_data, NULL);
  580. }
  581. static const struct file_operations lparcfg_fops = {
  582. .read = seq_read,
  583. .write = lparcfg_write,
  584. .open = lparcfg_open,
  585. .release = single_release,
  586. .llseek = seq_lseek,
  587. };
  588. static int __init lparcfg_init(void)
  589. {
  590. umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
  591. /* Allow writing if we have FW_FEATURE_SPLPAR */
  592. if (firmware_has_feature(FW_FEATURE_SPLPAR))
  593. mode |= S_IWUSR;
  594. if (!proc_create("powerpc/lparcfg", mode, NULL, &lparcfg_fops)) {
  595. printk(KERN_ERR "Failed to create powerpc/lparcfg\n");
  596. return -EIO;
  597. }
  598. return 0;
  599. }
  600. machine_device_initcall(pseries, lparcfg_init);