lparcfg.c 20 KB

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