lparcfg.c 19 KB

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