lparcfg.c 19 KB

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