lparcfg.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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. #define MODULE_VERS "1.8"
  38. #define MODULE_NAME "lparcfg"
  39. /* #define LPARCFG_DEBUG */
  40. static struct proc_dir_entry *proc_ppc64_lparcfg;
  41. /*
  42. * Track sum of all purrs across all processors. This is used to further
  43. * calculate usage values by different applications
  44. */
  45. static unsigned long get_purr(void)
  46. {
  47. unsigned long sum_purr = 0;
  48. int cpu;
  49. for_each_possible_cpu(cpu) {
  50. if (firmware_has_feature(FW_FEATURE_ISERIES))
  51. sum_purr += lppaca[cpu].emulated_time_base;
  52. else {
  53. struct cpu_usage *cu;
  54. cu = &per_cpu(cpu_usage_array, cpu);
  55. sum_purr += cu->current_tb;
  56. }
  57. }
  58. return sum_purr;
  59. }
  60. #ifdef CONFIG_PPC_ISERIES
  61. /*
  62. * Methods used to fetch LPAR data when running on an iSeries platform.
  63. */
  64. static int iseries_lparcfg_data(struct seq_file *m, void *v)
  65. {
  66. unsigned long pool_id;
  67. int shared, entitled_capacity, max_entitled_capacity;
  68. int processors, max_processors;
  69. unsigned long purr = get_purr();
  70. shared = (int)(local_paca->lppaca_ptr->shared_proc);
  71. seq_printf(m, "system_active_processors=%d\n",
  72. (int)HvLpConfig_getSystemPhysicalProcessors());
  73. seq_printf(m, "system_potential_processors=%d\n",
  74. (int)HvLpConfig_getSystemPhysicalProcessors());
  75. processors = (int)HvLpConfig_getPhysicalProcessors();
  76. seq_printf(m, "partition_active_processors=%d\n", processors);
  77. max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
  78. seq_printf(m, "partition_potential_processors=%d\n", max_processors);
  79. if (shared) {
  80. entitled_capacity = HvLpConfig_getSharedProcUnits();
  81. max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
  82. } else {
  83. entitled_capacity = processors * 100;
  84. max_entitled_capacity = max_processors * 100;
  85. }
  86. seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
  87. seq_printf(m, "partition_max_entitled_capacity=%d\n",
  88. max_entitled_capacity);
  89. if (shared) {
  90. pool_id = HvLpConfig_getSharedPoolIndex();
  91. seq_printf(m, "pool=%d\n", (int)pool_id);
  92. seq_printf(m, "pool_capacity=%d\n",
  93. (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) *
  94. 100));
  95. seq_printf(m, "purr=%ld\n", purr);
  96. }
  97. seq_printf(m, "shared_processor_mode=%d\n", shared);
  98. return 0;
  99. }
  100. #else /* CONFIG_PPC_ISERIES */
  101. static int iseries_lparcfg_data(struct seq_file *m, void *v)
  102. {
  103. return 0;
  104. }
  105. #endif /* CONFIG_PPC_ISERIES */
  106. #ifdef CONFIG_PPC_PSERIES
  107. /*
  108. * Methods used to fetch LPAR data when running on a pSeries platform.
  109. */
  110. /**
  111. * h_get_mpp
  112. * H_GET_MPP hcall returns info in 7 parms
  113. */
  114. int h_get_mpp(struct hvcall_mpp_data *mpp_data)
  115. {
  116. int rc;
  117. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
  118. rc = plpar_hcall9(H_GET_MPP, retbuf);
  119. mpp_data->entitled_mem = retbuf[0];
  120. mpp_data->mapped_mem = retbuf[1];
  121. mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
  122. mpp_data->pool_num = retbuf[2] & 0xffff;
  123. mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff;
  124. mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff;
  125. mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffff;
  126. mpp_data->pool_size = retbuf[4];
  127. mpp_data->loan_request = retbuf[5];
  128. mpp_data->backing_mem = retbuf[6];
  129. return rc;
  130. }
  131. EXPORT_SYMBOL(h_get_mpp);
  132. struct hvcall_ppp_data {
  133. u64 entitlement;
  134. u64 unallocated_entitlement;
  135. u16 group_num;
  136. u16 pool_num;
  137. u8 capped;
  138. u8 weight;
  139. u8 unallocated_weight;
  140. u16 active_procs_in_pool;
  141. u16 active_system_procs;
  142. u16 phys_platform_procs;
  143. u32 max_proc_cap_avail;
  144. u32 entitled_proc_cap_avail;
  145. };
  146. /*
  147. * H_GET_PPP hcall returns info in 4 parms.
  148. * entitled_capacity,unallocated_capacity,
  149. * aggregation, resource_capability).
  150. *
  151. * R4 = Entitled Processor Capacity Percentage.
  152. * R5 = Unallocated Processor Capacity Percentage.
  153. * R6 (AABBCCDDEEFFGGHH).
  154. * XXXX - reserved (0)
  155. * XXXX - reserved (0)
  156. * XXXX - Group Number
  157. * XXXX - Pool Number.
  158. * R7 (IIJJKKLLMMNNOOPP).
  159. * XX - reserved. (0)
  160. * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
  161. * XX - variable processor Capacity Weight
  162. * XX - Unallocated Variable Processor Capacity Weight.
  163. * XXXX - Active processors in Physical Processor Pool.
  164. * XXXX - Processors active on platform.
  165. * R8 (QQQQRRRRRRSSSSSS). if ibm,partition-performance-parameters-level >= 1
  166. * XXXX - Physical platform procs allocated to virtualization.
  167. * XXXXXX - Max procs capacity % available to the partitions pool.
  168. * XXXXXX - Entitled procs capacity % available to the
  169. * partitions pool.
  170. */
  171. static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data)
  172. {
  173. unsigned long rc;
  174. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
  175. rc = plpar_hcall9(H_GET_PPP, retbuf);
  176. ppp_data->entitlement = retbuf[0];
  177. ppp_data->unallocated_entitlement = retbuf[1];
  178. ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
  179. ppp_data->pool_num = retbuf[2] & 0xffff;
  180. ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01;
  181. ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff;
  182. ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff;
  183. ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff;
  184. ppp_data->active_system_procs = retbuf[3] & 0xffff;
  185. ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8;
  186. ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff;
  187. ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff;
  188. return rc;
  189. }
  190. static unsigned h_pic(unsigned long *pool_idle_time,
  191. unsigned long *num_procs)
  192. {
  193. unsigned long rc;
  194. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  195. rc = plpar_hcall(H_PIC, retbuf);
  196. *pool_idle_time = retbuf[0];
  197. *num_procs = retbuf[1];
  198. return rc;
  199. }
  200. /*
  201. * parse_ppp_data
  202. * Parse out the data returned from h_get_ppp and h_pic
  203. */
  204. static void parse_ppp_data(struct seq_file *m)
  205. {
  206. struct hvcall_ppp_data ppp_data;
  207. struct device_node *root;
  208. const int *perf_level;
  209. int rc;
  210. rc = h_get_ppp(&ppp_data);
  211. if (rc)
  212. return;
  213. seq_printf(m, "partition_entitled_capacity=%lld\n",
  214. ppp_data.entitlement);
  215. seq_printf(m, "group=%d\n", ppp_data.group_num);
  216. seq_printf(m, "system_active_processors=%d\n",
  217. ppp_data.active_system_procs);
  218. /* pool related entries are apropriate for shared configs */
  219. if (lppaca[0].shared_proc) {
  220. unsigned long pool_idle_time, pool_procs;
  221. seq_printf(m, "pool=%d\n", ppp_data.pool_num);
  222. /* report pool_capacity in percentage */
  223. seq_printf(m, "pool_capacity=%d\n",
  224. ppp_data.active_procs_in_pool * 100);
  225. h_pic(&pool_idle_time, &pool_procs);
  226. seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
  227. seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
  228. }
  229. seq_printf(m, "unallocated_capacity_weight=%d\n",
  230. ppp_data.unallocated_weight);
  231. seq_printf(m, "capacity_weight=%d\n", ppp_data.weight);
  232. seq_printf(m, "capped=%d\n", ppp_data.capped);
  233. seq_printf(m, "unallocated_capacity=%lld\n",
  234. ppp_data.unallocated_entitlement);
  235. /* The last bits of information returned from h_get_ppp are only
  236. * valid if the ibm,partition-performance-parameters-level
  237. * property is >= 1.
  238. */
  239. root = of_find_node_by_path("/");
  240. if (root) {
  241. perf_level = of_get_property(root,
  242. "ibm,partition-performance-parameters-level",
  243. NULL);
  244. if (perf_level && (*perf_level >= 1)) {
  245. seq_printf(m,
  246. "physical_procs_allocated_to_virtualization=%d\n",
  247. ppp_data.phys_platform_procs);
  248. seq_printf(m, "max_proc_capacity_available=%d\n",
  249. ppp_data.max_proc_cap_avail);
  250. seq_printf(m, "entitled_proc_capacity_available=%d\n",
  251. ppp_data.entitled_proc_cap_avail);
  252. }
  253. of_node_put(root);
  254. }
  255. }
  256. /**
  257. * parse_mpp_data
  258. * Parse out data returned from h_get_mpp
  259. */
  260. static void parse_mpp_data(struct seq_file *m)
  261. {
  262. struct hvcall_mpp_data mpp_data;
  263. int rc;
  264. rc = h_get_mpp(&mpp_data);
  265. if (rc)
  266. return;
  267. seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
  268. if (mpp_data.mapped_mem != -1)
  269. seq_printf(m, "mapped_entitled_memory=%ld\n",
  270. mpp_data.mapped_mem);
  271. seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
  272. seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
  273. seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
  274. seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
  275. mpp_data.unallocated_mem_weight);
  276. seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
  277. mpp_data.unallocated_entitlement);
  278. if (mpp_data.pool_size != -1)
  279. seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
  280. mpp_data.pool_size);
  281. seq_printf(m, "entitled_memory_loan_request=%ld\n",
  282. mpp_data.loan_request);
  283. seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
  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[cpu].cmo_faults;
  390. cmo_fault_time += lppaca[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[cpu].yield_count;
  406. dispatch_dispersions += lppaca[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 int pseries_lparcfg_data(struct seq_file *m, void *v)
  412. {
  413. int partition_potential_processors;
  414. int partition_active_processors;
  415. struct device_node *rtas_node;
  416. const int *lrdrp = NULL;
  417. rtas_node = of_find_node_by_path("/rtas");
  418. if (rtas_node)
  419. lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
  420. if (lrdrp == NULL) {
  421. partition_potential_processors = vdso_data->processorCount;
  422. } else {
  423. partition_potential_processors = *(lrdrp + 4);
  424. }
  425. of_node_put(rtas_node);
  426. partition_active_processors = lparcfg_count_active_processors();
  427. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  428. /* this call handles the ibm,get-system-parameter contents */
  429. parse_system_parameter_string(m);
  430. parse_ppp_data(m);
  431. parse_mpp_data(m);
  432. pseries_cmo_data(m);
  433. splpar_dispatch_data(m);
  434. seq_printf(m, "purr=%ld\n", get_purr());
  435. } else { /* non SPLPAR case */
  436. seq_printf(m, "system_active_processors=%d\n",
  437. partition_potential_processors);
  438. seq_printf(m, "system_potential_processors=%d\n",
  439. partition_potential_processors);
  440. seq_printf(m, "partition_max_entitled_capacity=%d\n",
  441. partition_potential_processors * 100);
  442. seq_printf(m, "partition_entitled_capacity=%d\n",
  443. partition_active_processors * 100);
  444. }
  445. seq_printf(m, "partition_active_processors=%d\n",
  446. partition_active_processors);
  447. seq_printf(m, "partition_potential_processors=%d\n",
  448. partition_potential_processors);
  449. seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
  450. return 0;
  451. }
  452. static ssize_t update_ppp(u64 *entitlement, u8 *weight)
  453. {
  454. struct hvcall_ppp_data ppp_data;
  455. u8 new_weight;
  456. u64 new_entitled;
  457. ssize_t retval;
  458. /* Get our current parameters */
  459. retval = h_get_ppp(&ppp_data);
  460. if (retval)
  461. return retval;
  462. if (entitlement) {
  463. new_weight = ppp_data.weight;
  464. new_entitled = *entitlement;
  465. } else if (weight) {
  466. new_weight = *weight;
  467. new_entitled = ppp_data.entitlement;
  468. } else
  469. return -EINVAL;
  470. pr_debug("%s: current_entitled = %llu, current_weight = %u\n",
  471. __func__, ppp_data.entitlement, ppp_data.weight);
  472. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  473. __func__, new_entitled, new_weight);
  474. retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
  475. return retval;
  476. }
  477. /**
  478. * update_mpp
  479. *
  480. * Update the memory entitlement and weight for the partition. Caller must
  481. * specify either a new entitlement or weight, not both, to be updated
  482. * since the h_set_mpp call takes both entitlement and weight as parameters.
  483. */
  484. static ssize_t update_mpp(u64 *entitlement, u8 *weight)
  485. {
  486. struct hvcall_mpp_data mpp_data;
  487. u64 new_entitled;
  488. u8 new_weight;
  489. ssize_t rc;
  490. if (entitlement) {
  491. /* Check with vio to ensure the new memory entitlement
  492. * can be handled.
  493. */
  494. rc = vio_cmo_entitlement_update(*entitlement);
  495. if (rc)
  496. return rc;
  497. }
  498. rc = h_get_mpp(&mpp_data);
  499. if (rc)
  500. return rc;
  501. if (entitlement) {
  502. new_weight = mpp_data.mem_weight;
  503. new_entitled = *entitlement;
  504. } else if (weight) {
  505. new_weight = *weight;
  506. new_entitled = mpp_data.entitled_mem;
  507. } else
  508. return -EINVAL;
  509. pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
  510. __func__, mpp_data.entitled_mem, mpp_data.mem_weight);
  511. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  512. __func__, new_entitled, new_weight);
  513. rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
  514. return rc;
  515. }
  516. /*
  517. * Interface for changing system parameters (variable capacity weight
  518. * and entitled capacity). Format of input is "param_name=value";
  519. * anything after value is ignored. Valid parameters at this time are
  520. * "partition_entitled_capacity" and "capacity_weight". We use
  521. * H_SET_PPP to alter parameters.
  522. *
  523. * This function should be invoked only on systems with
  524. * FW_FEATURE_SPLPAR.
  525. */
  526. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  527. size_t count, loff_t * off)
  528. {
  529. int kbuf_sz = 64;
  530. char kbuf[kbuf_sz];
  531. char *tmp;
  532. u64 new_entitled, *new_entitled_ptr = &new_entitled;
  533. u8 new_weight, *new_weight_ptr = &new_weight;
  534. ssize_t retval;
  535. if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
  536. firmware_has_feature(FW_FEATURE_ISERIES))
  537. return -EINVAL;
  538. if (count > kbuf_sz)
  539. return -EINVAL;
  540. if (copy_from_user(kbuf, buf, count))
  541. return -EFAULT;
  542. kbuf[count - 1] = '\0';
  543. tmp = strchr(kbuf, '=');
  544. if (!tmp)
  545. return -EINVAL;
  546. *tmp++ = '\0';
  547. if (!strcmp(kbuf, "partition_entitled_capacity")) {
  548. char *endp;
  549. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  550. if (endp == tmp)
  551. return -EINVAL;
  552. retval = update_ppp(new_entitled_ptr, NULL);
  553. } else if (!strcmp(kbuf, "capacity_weight")) {
  554. char *endp;
  555. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  556. if (endp == tmp)
  557. return -EINVAL;
  558. retval = update_ppp(NULL, new_weight_ptr);
  559. } else if (!strcmp(kbuf, "entitled_memory")) {
  560. char *endp;
  561. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  562. if (endp == tmp)
  563. return -EINVAL;
  564. retval = update_mpp(new_entitled_ptr, NULL);
  565. } else if (!strcmp(kbuf, "entitled_memory_weight")) {
  566. char *endp;
  567. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  568. if (endp == tmp)
  569. return -EINVAL;
  570. retval = update_mpp(NULL, new_weight_ptr);
  571. } else
  572. return -EINVAL;
  573. if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
  574. retval = count;
  575. } else if (retval == H_BUSY) {
  576. retval = -EBUSY;
  577. } else if (retval == H_HARDWARE) {
  578. retval = -EIO;
  579. } else if (retval == H_PARAMETER) {
  580. retval = -EINVAL;
  581. }
  582. return retval;
  583. }
  584. #else /* CONFIG_PPC_PSERIES */
  585. static int pseries_lparcfg_data(struct seq_file *m, void *v)
  586. {
  587. return 0;
  588. }
  589. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  590. size_t count, loff_t * off)
  591. {
  592. return -EINVAL;
  593. }
  594. #endif /* CONFIG_PPC_PSERIES */
  595. static int lparcfg_data(struct seq_file *m, void *v)
  596. {
  597. struct device_node *rootdn;
  598. const char *model = "";
  599. const char *system_id = "";
  600. const char *tmp;
  601. const unsigned int *lp_index_ptr;
  602. unsigned int lp_index = 0;
  603. seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
  604. rootdn = of_find_node_by_path("/");
  605. if (rootdn) {
  606. tmp = of_get_property(rootdn, "model", NULL);
  607. if (tmp) {
  608. model = tmp;
  609. /* Skip "IBM," - see platforms/iseries/dt.c */
  610. if (firmware_has_feature(FW_FEATURE_ISERIES))
  611. model += 4;
  612. }
  613. tmp = of_get_property(rootdn, "system-id", NULL);
  614. if (tmp) {
  615. system_id = tmp;
  616. /* Skip "IBM," - see platforms/iseries/dt.c */
  617. if (firmware_has_feature(FW_FEATURE_ISERIES))
  618. system_id += 4;
  619. }
  620. lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
  621. NULL);
  622. if (lp_index_ptr)
  623. lp_index = *lp_index_ptr;
  624. of_node_put(rootdn);
  625. }
  626. seq_printf(m, "serial_number=%s\n", system_id);
  627. seq_printf(m, "system_type=%s\n", model);
  628. seq_printf(m, "partition_id=%d\n", (int)lp_index);
  629. if (firmware_has_feature(FW_FEATURE_ISERIES))
  630. return iseries_lparcfg_data(m, v);
  631. return pseries_lparcfg_data(m, v);
  632. }
  633. static int lparcfg_open(struct inode *inode, struct file *file)
  634. {
  635. return single_open(file, lparcfg_data, NULL);
  636. }
  637. static const struct file_operations lparcfg_fops = {
  638. .owner = THIS_MODULE,
  639. .read = seq_read,
  640. .write = lparcfg_write,
  641. .open = lparcfg_open,
  642. .release = single_release,
  643. };
  644. static int __init lparcfg_init(void)
  645. {
  646. struct proc_dir_entry *ent;
  647. mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
  648. /* Allow writing if we have FW_FEATURE_SPLPAR */
  649. if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
  650. !firmware_has_feature(FW_FEATURE_ISERIES))
  651. mode |= S_IWUSR;
  652. ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops);
  653. if (!ent) {
  654. printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
  655. return -EIO;
  656. }
  657. proc_ppc64_lparcfg = ent;
  658. return 0;
  659. }
  660. static void __exit lparcfg_cleanup(void)
  661. {
  662. if (proc_ppc64_lparcfg)
  663. remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
  664. }
  665. module_init(lparcfg_init);
  666. module_exit(lparcfg_cleanup);
  667. MODULE_DESCRIPTION("Interface for LPAR configuration data");
  668. MODULE_AUTHOR("Dave Engebretsen");
  669. MODULE_LICENSE("GPL");