lparcfg.c 19 KB

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