lparcfg.c 19 KB

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