lparcfg.c 21 KB

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