lparcfg.c 22 KB

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