lparcfg.c 22 KB

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