lparcfg.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PowerPC64 LPAR Configuration Information Driver
  4. *
  5. * Dave Engebretsen [email protected]
  6. * Copyright (c) 2003 Dave Engebretsen
  7. * Will Schmidt [email protected]
  8. * SPLPAR updates, Copyright (c) 2003 Will Schmidt IBM Corporation.
  9. * seq_file updates, Copyright (c) 2004 Will Schmidt IBM Corporation.
  10. * Nathan Lynch [email protected]
  11. * Added lparcfg_write, Copyright (C) 2004 Nathan Lynch IBM Corporation.
  12. *
  13. * This driver creates a proc file at /proc/ppc64/lparcfg which contains
  14. * keyword - value pairs that specify the configuration of the partition.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <linux/errno.h>
  19. #include <linux/proc_fs.h>
  20. #include <linux/init.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/slab.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/hugetlb.h>
  25. #include <asm/lppaca.h>
  26. #include <asm/hvcall.h>
  27. #include <asm/firmware.h>
  28. #include <asm/rtas.h>
  29. #include <asm/time.h>
  30. #include <asm/vdso_datapage.h>
  31. #include <asm/vio.h>
  32. #include <asm/mmu.h>
  33. #include <asm/machdep.h>
  34. #include <asm/drmem.h>
  35. #include "pseries.h"
  36. #include "vas.h" /* pseries_vas_dlpar_cpu() */
  37. /*
  38. * This isn't a module but we expose that to userspace
  39. * via /proc so leave the definitions here
  40. */
  41. #define MODULE_VERS "1.9"
  42. #define MODULE_NAME "lparcfg"
  43. /* #define LPARCFG_DEBUG */
  44. /*
  45. * Track sum of all purrs across all processors. This is used to further
  46. * calculate usage values by different applications
  47. */
  48. static void cpu_get_purr(void *arg)
  49. {
  50. atomic64_t *sum = arg;
  51. atomic64_add(mfspr(SPRN_PURR), sum);
  52. }
  53. static unsigned long get_purr(void)
  54. {
  55. atomic64_t purr = ATOMIC64_INIT(0);
  56. on_each_cpu(cpu_get_purr, &purr, 1);
  57. return atomic64_read(&purr);
  58. }
  59. /*
  60. * Methods used to fetch LPAR data when running on a pSeries platform.
  61. */
  62. struct hvcall_ppp_data {
  63. u64 entitlement;
  64. u64 unallocated_entitlement;
  65. u16 group_num;
  66. u16 pool_num;
  67. u8 capped;
  68. u8 weight;
  69. u8 unallocated_weight;
  70. u16 active_procs_in_pool;
  71. u16 active_system_procs;
  72. u16 phys_platform_procs;
  73. u32 max_proc_cap_avail;
  74. u32 entitled_proc_cap_avail;
  75. };
  76. /*
  77. * H_GET_PPP hcall returns info in 4 parms.
  78. * entitled_capacity,unallocated_capacity,
  79. * aggregation, resource_capability).
  80. *
  81. * R4 = Entitled Processor Capacity Percentage.
  82. * R5 = Unallocated Processor Capacity Percentage.
  83. * R6 (AABBCCDDEEFFGGHH).
  84. * XXXX - reserved (0)
  85. * XXXX - reserved (0)
  86. * XXXX - Group Number
  87. * XXXX - Pool Number.
  88. * R7 (IIJJKKLLMMNNOOPP).
  89. * XX - reserved. (0)
  90. * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
  91. * XX - variable processor Capacity Weight
  92. * XX - Unallocated Variable Processor Capacity Weight.
  93. * XXXX - Active processors in Physical Processor Pool.
  94. * XXXX - Processors active on platform.
  95. * R8 (QQQQRRRRRRSSSSSS). if ibm,partition-performance-parameters-level >= 1
  96. * XXXX - Physical platform procs allocated to virtualization.
  97. * XXXXXX - Max procs capacity % available to the partitions pool.
  98. * XXXXXX - Entitled procs capacity % available to the
  99. * partitions pool.
  100. */
  101. static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data)
  102. {
  103. unsigned long rc;
  104. unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
  105. rc = plpar_hcall9(H_GET_PPP, retbuf);
  106. ppp_data->entitlement = retbuf[0];
  107. ppp_data->unallocated_entitlement = retbuf[1];
  108. ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
  109. ppp_data->pool_num = retbuf[2] & 0xffff;
  110. ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01;
  111. ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff;
  112. ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff;
  113. ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff;
  114. ppp_data->active_system_procs = retbuf[3] & 0xffff;
  115. ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8;
  116. ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff;
  117. ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff;
  118. return rc;
  119. }
  120. static void show_gpci_data(struct seq_file *m)
  121. {
  122. struct hv_gpci_request_buffer *buf;
  123. unsigned int affinity_score;
  124. long ret;
  125. buf = kmalloc(sizeof(*buf), GFP_KERNEL);
  126. if (buf == NULL)
  127. return;
  128. /*
  129. * Show the local LPAR's affinity score.
  130. *
  131. * 0xB1 selects the Affinity_Domain_Info_By_Partition subcall.
  132. * The score is at byte 0xB in the output buffer.
  133. */
  134. memset(&buf->params, 0, sizeof(buf->params));
  135. buf->params.counter_request = cpu_to_be32(0xB1);
  136. buf->params.starting_index = cpu_to_be32(-1); /* local LPAR */
  137. buf->params.counter_info_version_in = 0x5; /* v5+ for score */
  138. ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO, virt_to_phys(buf),
  139. sizeof(*buf));
  140. if (ret != H_SUCCESS) {
  141. pr_debug("hcall failed: H_GET_PERF_COUNTER_INFO: %ld, %x\n",
  142. ret, be32_to_cpu(buf->params.detail_rc));
  143. goto out;
  144. }
  145. affinity_score = buf->bytes[0xB];
  146. seq_printf(m, "partition_affinity_score=%u\n", affinity_score);
  147. out:
  148. kfree(buf);
  149. }
  150. static unsigned h_pic(unsigned long *pool_idle_time,
  151. unsigned long *num_procs)
  152. {
  153. unsigned long rc;
  154. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  155. rc = plpar_hcall(H_PIC, retbuf);
  156. *pool_idle_time = retbuf[0];
  157. *num_procs = retbuf[1];
  158. return rc;
  159. }
  160. /*
  161. * parse_ppp_data
  162. * Parse out the data returned from h_get_ppp and h_pic
  163. */
  164. static void parse_ppp_data(struct seq_file *m)
  165. {
  166. struct hvcall_ppp_data ppp_data;
  167. struct device_node *root;
  168. const __be32 *perf_level;
  169. int rc;
  170. rc = h_get_ppp(&ppp_data);
  171. if (rc)
  172. return;
  173. seq_printf(m, "partition_entitled_capacity=%lld\n",
  174. ppp_data.entitlement);
  175. seq_printf(m, "group=%d\n", ppp_data.group_num);
  176. seq_printf(m, "system_active_processors=%d\n",
  177. ppp_data.active_system_procs);
  178. /* pool related entries are appropriate for shared configs */
  179. if (lppaca_shared_proc()) {
  180. unsigned long pool_idle_time, pool_procs;
  181. seq_printf(m, "pool=%d\n", ppp_data.pool_num);
  182. /* report pool_capacity in percentage */
  183. seq_printf(m, "pool_capacity=%d\n",
  184. ppp_data.active_procs_in_pool * 100);
  185. h_pic(&pool_idle_time, &pool_procs);
  186. seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
  187. seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
  188. }
  189. seq_printf(m, "unallocated_capacity_weight=%d\n",
  190. ppp_data.unallocated_weight);
  191. seq_printf(m, "capacity_weight=%d\n", ppp_data.weight);
  192. seq_printf(m, "capped=%d\n", ppp_data.capped);
  193. seq_printf(m, "unallocated_capacity=%lld\n",
  194. ppp_data.unallocated_entitlement);
  195. /* The last bits of information returned from h_get_ppp are only
  196. * valid if the ibm,partition-performance-parameters-level
  197. * property is >= 1.
  198. */
  199. root = of_find_node_by_path("/");
  200. if (root) {
  201. perf_level = of_get_property(root,
  202. "ibm,partition-performance-parameters-level",
  203. NULL);
  204. if (perf_level && (be32_to_cpup(perf_level) >= 1)) {
  205. seq_printf(m,
  206. "physical_procs_allocated_to_virtualization=%d\n",
  207. ppp_data.phys_platform_procs);
  208. seq_printf(m, "max_proc_capacity_available=%d\n",
  209. ppp_data.max_proc_cap_avail);
  210. seq_printf(m, "entitled_proc_capacity_available=%d\n",
  211. ppp_data.entitled_proc_cap_avail);
  212. }
  213. of_node_put(root);
  214. }
  215. }
  216. /**
  217. * parse_mpp_data
  218. * Parse out data returned from h_get_mpp
  219. */
  220. static void parse_mpp_data(struct seq_file *m)
  221. {
  222. struct hvcall_mpp_data mpp_data;
  223. int rc;
  224. rc = h_get_mpp(&mpp_data);
  225. if (rc)
  226. return;
  227. seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
  228. if (mpp_data.mapped_mem != -1)
  229. seq_printf(m, "mapped_entitled_memory=%ld\n",
  230. mpp_data.mapped_mem);
  231. seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
  232. seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
  233. seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
  234. seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
  235. mpp_data.unallocated_mem_weight);
  236. seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
  237. mpp_data.unallocated_entitlement);
  238. if (mpp_data.pool_size != -1)
  239. seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
  240. mpp_data.pool_size);
  241. seq_printf(m, "entitled_memory_loan_request=%ld\n",
  242. mpp_data.loan_request);
  243. seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
  244. }
  245. /**
  246. * parse_mpp_x_data
  247. * Parse out data returned from h_get_mpp_x
  248. */
  249. static void parse_mpp_x_data(struct seq_file *m)
  250. {
  251. struct hvcall_mpp_x_data mpp_x_data;
  252. if (!firmware_has_feature(FW_FEATURE_XCMO))
  253. return;
  254. if (h_get_mpp_x(&mpp_x_data))
  255. return;
  256. seq_printf(m, "coalesced_bytes=%ld\n", mpp_x_data.coalesced_bytes);
  257. if (mpp_x_data.pool_coalesced_bytes)
  258. seq_printf(m, "pool_coalesced_bytes=%ld\n",
  259. mpp_x_data.pool_coalesced_bytes);
  260. if (mpp_x_data.pool_purr_cycles)
  261. seq_printf(m, "coalesce_pool_purr=%ld\n", mpp_x_data.pool_purr_cycles);
  262. if (mpp_x_data.pool_spurr_cycles)
  263. seq_printf(m, "coalesce_pool_spurr=%ld\n", mpp_x_data.pool_spurr_cycles);
  264. }
  265. /*
  266. * PAPR defines, in section "7.3.16 System Parameters Option", the token 55 to
  267. * read the LPAR name, and the largest output data to 4000 + 2 bytes length.
  268. */
  269. #define SPLPAR_LPAR_NAME_TOKEN 55
  270. #define GET_SYS_PARM_BUF_SIZE 4002
  271. #if GET_SYS_PARM_BUF_SIZE > RTAS_DATA_BUF_SIZE
  272. #error "GET_SYS_PARM_BUF_SIZE is larger than RTAS_DATA_BUF_SIZE"
  273. #endif
  274. /*
  275. * Read the lpar name using the RTAS ibm,get-system-parameter call.
  276. *
  277. * The name read through this call is updated if changes are made by the end
  278. * user on the hypervisor side.
  279. *
  280. * Some hypervisor (like Qemu) may not provide this value. In that case, a non
  281. * null value is returned.
  282. */
  283. static int read_rtas_lpar_name(struct seq_file *m)
  284. {
  285. int rc, len, token;
  286. union {
  287. char raw_buffer[GET_SYS_PARM_BUF_SIZE];
  288. struct {
  289. __be16 len;
  290. char name[GET_SYS_PARM_BUF_SIZE-2];
  291. };
  292. } *local_buffer;
  293. token = rtas_token("ibm,get-system-parameter");
  294. if (token == RTAS_UNKNOWN_SERVICE)
  295. return -EINVAL;
  296. local_buffer = kmalloc(sizeof(*local_buffer), GFP_KERNEL);
  297. if (!local_buffer)
  298. return -ENOMEM;
  299. do {
  300. spin_lock(&rtas_data_buf_lock);
  301. memset(rtas_data_buf, 0, sizeof(*local_buffer));
  302. rc = rtas_call(token, 3, 1, NULL, SPLPAR_LPAR_NAME_TOKEN,
  303. __pa(rtas_data_buf), sizeof(*local_buffer));
  304. if (!rc)
  305. memcpy(local_buffer->raw_buffer, rtas_data_buf,
  306. sizeof(local_buffer->raw_buffer));
  307. spin_unlock(&rtas_data_buf_lock);
  308. } while (rtas_busy_delay(rc));
  309. if (!rc) {
  310. /* Force end of string */
  311. len = min((int) be16_to_cpu(local_buffer->len),
  312. (int) sizeof(local_buffer->name)-1);
  313. local_buffer->name[len] = '\0';
  314. seq_printf(m, "partition_name=%s\n", local_buffer->name);
  315. } else
  316. rc = -ENODATA;
  317. kfree(local_buffer);
  318. return rc;
  319. }
  320. /*
  321. * Read the LPAR name from the Device Tree.
  322. *
  323. * The value read in the DT is not updated if the end-user is touching the LPAR
  324. * name on the hypervisor side.
  325. */
  326. static int read_dt_lpar_name(struct seq_file *m)
  327. {
  328. const char *name;
  329. if (of_property_read_string(of_root, "ibm,partition-name", &name))
  330. return -ENOENT;
  331. seq_printf(m, "partition_name=%s\n", name);
  332. return 0;
  333. }
  334. static void read_lpar_name(struct seq_file *m)
  335. {
  336. if (read_rtas_lpar_name(m) && read_dt_lpar_name(m))
  337. pr_err_once("Error can't get the LPAR name");
  338. }
  339. #define SPLPAR_CHARACTERISTICS_TOKEN 20
  340. #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
  341. /*
  342. * parse_system_parameter_string()
  343. * Retrieve the potential_processors, max_entitled_capacity and friends
  344. * through the get-system-parameter rtas call. Replace keyword strings as
  345. * necessary.
  346. */
  347. static void parse_system_parameter_string(struct seq_file *m)
  348. {
  349. int call_status;
  350. unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
  351. if (!local_buffer) {
  352. printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
  353. __FILE__, __func__, __LINE__);
  354. return;
  355. }
  356. spin_lock(&rtas_data_buf_lock);
  357. memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
  358. call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
  359. NULL,
  360. SPLPAR_CHARACTERISTICS_TOKEN,
  361. __pa(rtas_data_buf),
  362. RTAS_DATA_BUF_SIZE);
  363. memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
  364. local_buffer[SPLPAR_MAXLENGTH - 1] = '\0';
  365. spin_unlock(&rtas_data_buf_lock);
  366. if (call_status != 0) {
  367. printk(KERN_INFO
  368. "%s %s Error calling get-system-parameter (0x%x)\n",
  369. __FILE__, __func__, call_status);
  370. } else {
  371. int splpar_strlen;
  372. int idx, w_idx;
  373. char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
  374. if (!workbuffer) {
  375. printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
  376. __FILE__, __func__, __LINE__);
  377. kfree(local_buffer);
  378. return;
  379. }
  380. #ifdef LPARCFG_DEBUG
  381. printk(KERN_INFO "success calling get-system-parameter\n");
  382. #endif
  383. splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
  384. local_buffer += 2; /* step over strlen value */
  385. w_idx = 0;
  386. idx = 0;
  387. while ((*local_buffer) && (idx < splpar_strlen)) {
  388. workbuffer[w_idx++] = local_buffer[idx++];
  389. if ((local_buffer[idx] == ',')
  390. || (local_buffer[idx] == '\0')) {
  391. workbuffer[w_idx] = '\0';
  392. if (w_idx) {
  393. /* avoid the empty string */
  394. seq_printf(m, "%s\n", workbuffer);
  395. }
  396. memset(workbuffer, 0, SPLPAR_MAXLENGTH);
  397. idx++; /* skip the comma */
  398. w_idx = 0;
  399. } else if (local_buffer[idx] == '=') {
  400. /* code here to replace workbuffer contents
  401. with different keyword strings */
  402. if (0 == strcmp(workbuffer, "MaxEntCap")) {
  403. strcpy(workbuffer,
  404. "partition_max_entitled_capacity");
  405. w_idx = strlen(workbuffer);
  406. }
  407. if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
  408. strcpy(workbuffer,
  409. "system_potential_processors");
  410. w_idx = strlen(workbuffer);
  411. }
  412. }
  413. }
  414. kfree(workbuffer);
  415. local_buffer -= 2; /* back up over strlen value */
  416. }
  417. kfree(local_buffer);
  418. }
  419. /* Return the number of processors in the system.
  420. * This function reads through the device tree and counts
  421. * the virtual processors, this does not include threads.
  422. */
  423. static int lparcfg_count_active_processors(void)
  424. {
  425. struct device_node *cpus_dn;
  426. int count = 0;
  427. for_each_node_by_type(cpus_dn, "cpu") {
  428. #ifdef LPARCFG_DEBUG
  429. printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
  430. #endif
  431. count++;
  432. }
  433. return count;
  434. }
  435. static void pseries_cmo_data(struct seq_file *m)
  436. {
  437. int cpu;
  438. unsigned long cmo_faults = 0;
  439. unsigned long cmo_fault_time = 0;
  440. seq_printf(m, "cmo_enabled=%d\n", firmware_has_feature(FW_FEATURE_CMO));
  441. if (!firmware_has_feature(FW_FEATURE_CMO))
  442. return;
  443. for_each_possible_cpu(cpu) {
  444. cmo_faults += be64_to_cpu(lppaca_of(cpu).cmo_faults);
  445. cmo_fault_time += be64_to_cpu(lppaca_of(cpu).cmo_fault_time);
  446. }
  447. seq_printf(m, "cmo_faults=%lu\n", cmo_faults);
  448. seq_printf(m, "cmo_fault_time_usec=%lu\n",
  449. cmo_fault_time / tb_ticks_per_usec);
  450. seq_printf(m, "cmo_primary_psp=%d\n", cmo_get_primary_psp());
  451. seq_printf(m, "cmo_secondary_psp=%d\n", cmo_get_secondary_psp());
  452. seq_printf(m, "cmo_page_size=%lu\n", cmo_get_page_size());
  453. }
  454. static void splpar_dispatch_data(struct seq_file *m)
  455. {
  456. int cpu;
  457. unsigned long dispatches = 0;
  458. unsigned long dispatch_dispersions = 0;
  459. for_each_possible_cpu(cpu) {
  460. dispatches += be32_to_cpu(lppaca_of(cpu).yield_count);
  461. dispatch_dispersions +=
  462. be32_to_cpu(lppaca_of(cpu).dispersion_count);
  463. }
  464. seq_printf(m, "dispatches=%lu\n", dispatches);
  465. seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions);
  466. }
  467. static void parse_em_data(struct seq_file *m)
  468. {
  469. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  470. if (firmware_has_feature(FW_FEATURE_LPAR) &&
  471. plpar_hcall(H_GET_EM_PARMS, retbuf) == H_SUCCESS)
  472. seq_printf(m, "power_mode_data=%016lx\n", retbuf[0]);
  473. }
  474. static void maxmem_data(struct seq_file *m)
  475. {
  476. unsigned long maxmem = 0;
  477. maxmem += (unsigned long)drmem_info->n_lmbs * drmem_info->lmb_size;
  478. maxmem += hugetlb_total_pages() * PAGE_SIZE;
  479. seq_printf(m, "MaxMem=%lu\n", maxmem);
  480. }
  481. static int pseries_lparcfg_data(struct seq_file *m, void *v)
  482. {
  483. int partition_potential_processors;
  484. int partition_active_processors;
  485. struct device_node *rtas_node;
  486. const __be32 *lrdrp = NULL;
  487. rtas_node = of_find_node_by_path("/rtas");
  488. if (rtas_node)
  489. lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
  490. if (lrdrp == NULL) {
  491. partition_potential_processors = vdso_data->processorCount;
  492. } else {
  493. partition_potential_processors = be32_to_cpup(lrdrp + 4);
  494. }
  495. of_node_put(rtas_node);
  496. partition_active_processors = lparcfg_count_active_processors();
  497. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  498. /* this call handles the ibm,get-system-parameter contents */
  499. read_lpar_name(m);
  500. parse_system_parameter_string(m);
  501. parse_ppp_data(m);
  502. parse_mpp_data(m);
  503. parse_mpp_x_data(m);
  504. pseries_cmo_data(m);
  505. splpar_dispatch_data(m);
  506. seq_printf(m, "purr=%ld\n", get_purr());
  507. seq_printf(m, "tbr=%ld\n", mftb());
  508. } else { /* non SPLPAR case */
  509. seq_printf(m, "system_active_processors=%d\n",
  510. partition_potential_processors);
  511. seq_printf(m, "system_potential_processors=%d\n",
  512. partition_potential_processors);
  513. seq_printf(m, "partition_max_entitled_capacity=%d\n",
  514. partition_potential_processors * 100);
  515. seq_printf(m, "partition_entitled_capacity=%d\n",
  516. partition_active_processors * 100);
  517. }
  518. show_gpci_data(m);
  519. seq_printf(m, "partition_active_processors=%d\n",
  520. partition_active_processors);
  521. seq_printf(m, "partition_potential_processors=%d\n",
  522. partition_potential_processors);
  523. seq_printf(m, "shared_processor_mode=%d\n",
  524. lppaca_shared_proc());
  525. #ifdef CONFIG_PPC_64S_HASH_MMU
  526. if (!radix_enabled())
  527. seq_printf(m, "slb_size=%d\n", mmu_slb_size);
  528. #endif
  529. parse_em_data(m);
  530. maxmem_data(m);
  531. seq_printf(m, "security_flavor=%u\n", pseries_security_flavor);
  532. return 0;
  533. }
  534. static ssize_t update_ppp(u64 *entitlement, u8 *weight)
  535. {
  536. struct hvcall_ppp_data ppp_data;
  537. u8 new_weight;
  538. u64 new_entitled;
  539. ssize_t retval;
  540. /* Get our current parameters */
  541. retval = h_get_ppp(&ppp_data);
  542. if (retval)
  543. return retval;
  544. if (entitlement) {
  545. new_weight = ppp_data.weight;
  546. new_entitled = *entitlement;
  547. } else if (weight) {
  548. new_weight = *weight;
  549. new_entitled = ppp_data.entitlement;
  550. } else
  551. return -EINVAL;
  552. pr_debug("%s: current_entitled = %llu, current_weight = %u\n",
  553. __func__, ppp_data.entitlement, ppp_data.weight);
  554. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  555. __func__, new_entitled, new_weight);
  556. retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
  557. return retval;
  558. }
  559. /**
  560. * update_mpp
  561. *
  562. * Update the memory entitlement and weight for the partition. Caller must
  563. * specify either a new entitlement or weight, not both, to be updated
  564. * since the h_set_mpp call takes both entitlement and weight as parameters.
  565. */
  566. static ssize_t update_mpp(u64 *entitlement, u8 *weight)
  567. {
  568. struct hvcall_mpp_data mpp_data;
  569. u64 new_entitled;
  570. u8 new_weight;
  571. ssize_t rc;
  572. if (entitlement) {
  573. /* Check with vio to ensure the new memory entitlement
  574. * can be handled.
  575. */
  576. rc = vio_cmo_entitlement_update(*entitlement);
  577. if (rc)
  578. return rc;
  579. }
  580. rc = h_get_mpp(&mpp_data);
  581. if (rc)
  582. return rc;
  583. if (entitlement) {
  584. new_weight = mpp_data.mem_weight;
  585. new_entitled = *entitlement;
  586. } else if (weight) {
  587. new_weight = *weight;
  588. new_entitled = mpp_data.entitled_mem;
  589. } else
  590. return -EINVAL;
  591. pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
  592. __func__, mpp_data.entitled_mem, mpp_data.mem_weight);
  593. pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
  594. __func__, new_entitled, new_weight);
  595. rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
  596. return rc;
  597. }
  598. /*
  599. * Interface for changing system parameters (variable capacity weight
  600. * and entitled capacity). Format of input is "param_name=value";
  601. * anything after value is ignored. Valid parameters at this time are
  602. * "partition_entitled_capacity" and "capacity_weight". We use
  603. * H_SET_PPP to alter parameters.
  604. *
  605. * This function should be invoked only on systems with
  606. * FW_FEATURE_SPLPAR.
  607. */
  608. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  609. size_t count, loff_t * off)
  610. {
  611. char kbuf[64];
  612. char *tmp;
  613. u64 new_entitled, *new_entitled_ptr = &new_entitled;
  614. u8 new_weight, *new_weight_ptr = &new_weight;
  615. ssize_t retval;
  616. if (!firmware_has_feature(FW_FEATURE_SPLPAR))
  617. return -EINVAL;
  618. if (count > sizeof(kbuf))
  619. return -EINVAL;
  620. if (copy_from_user(kbuf, buf, count))
  621. return -EFAULT;
  622. kbuf[count - 1] = '\0';
  623. tmp = strchr(kbuf, '=');
  624. if (!tmp)
  625. return -EINVAL;
  626. *tmp++ = '\0';
  627. if (!strcmp(kbuf, "partition_entitled_capacity")) {
  628. char *endp;
  629. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  630. if (endp == tmp)
  631. return -EINVAL;
  632. retval = update_ppp(new_entitled_ptr, NULL);
  633. if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
  634. /*
  635. * The hypervisor assigns VAS resources based
  636. * on entitled capacity for shared mode.
  637. * Reconfig VAS windows based on DLPAR CPU events.
  638. */
  639. if (pseries_vas_dlpar_cpu() != 0)
  640. retval = H_HARDWARE;
  641. }
  642. } else if (!strcmp(kbuf, "capacity_weight")) {
  643. char *endp;
  644. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  645. if (endp == tmp)
  646. return -EINVAL;
  647. retval = update_ppp(NULL, new_weight_ptr);
  648. } else if (!strcmp(kbuf, "entitled_memory")) {
  649. char *endp;
  650. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  651. if (endp == tmp)
  652. return -EINVAL;
  653. retval = update_mpp(new_entitled_ptr, NULL);
  654. } else if (!strcmp(kbuf, "entitled_memory_weight")) {
  655. char *endp;
  656. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  657. if (endp == tmp)
  658. return -EINVAL;
  659. retval = update_mpp(NULL, new_weight_ptr);
  660. } else
  661. return -EINVAL;
  662. if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
  663. retval = count;
  664. } else if (retval == H_BUSY) {
  665. retval = -EBUSY;
  666. } else if (retval == H_HARDWARE) {
  667. retval = -EIO;
  668. } else if (retval == H_PARAMETER) {
  669. retval = -EINVAL;
  670. }
  671. return retval;
  672. }
  673. static int lparcfg_data(struct seq_file *m, void *v)
  674. {
  675. struct device_node *rootdn;
  676. const char *model = "";
  677. const char *system_id = "";
  678. const char *tmp;
  679. const __be32 *lp_index_ptr;
  680. unsigned int lp_index = 0;
  681. seq_printf(m, "%s %s\n", MODULE_NAME, MODULE_VERS);
  682. rootdn = of_find_node_by_path("/");
  683. if (rootdn) {
  684. tmp = of_get_property(rootdn, "model", NULL);
  685. if (tmp)
  686. model = tmp;
  687. tmp = of_get_property(rootdn, "system-id", NULL);
  688. if (tmp)
  689. system_id = tmp;
  690. lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
  691. NULL);
  692. if (lp_index_ptr)
  693. lp_index = be32_to_cpup(lp_index_ptr);
  694. of_node_put(rootdn);
  695. }
  696. seq_printf(m, "serial_number=%s\n", system_id);
  697. seq_printf(m, "system_type=%s\n", model);
  698. seq_printf(m, "partition_id=%d\n", (int)lp_index);
  699. return pseries_lparcfg_data(m, v);
  700. }
  701. static int lparcfg_open(struct inode *inode, struct file *file)
  702. {
  703. return single_open(file, lparcfg_data, NULL);
  704. }
  705. static const struct proc_ops lparcfg_proc_ops = {
  706. .proc_read = seq_read,
  707. .proc_write = lparcfg_write,
  708. .proc_open = lparcfg_open,
  709. .proc_release = single_release,
  710. .proc_lseek = seq_lseek,
  711. };
  712. static int __init lparcfg_init(void)
  713. {
  714. umode_t mode = 0444;
  715. /* Allow writing if we have FW_FEATURE_SPLPAR */
  716. if (firmware_has_feature(FW_FEATURE_SPLPAR))
  717. mode |= 0200;
  718. if (!proc_create("powerpc/lparcfg", mode, NULL, &lparcfg_proc_ops)) {
  719. printk(KERN_ERR "Failed to create powerpc/lparcfg\n");
  720. return -EIO;
  721. }
  722. return 0;
  723. }
  724. machine_device_initcall(pseries, lparcfg_init);