lparcfg.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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=%ld\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=%ld\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 int pseries_lparcfg_data(struct seq_file *m, void *v)
  367. {
  368. int partition_potential_processors;
  369. int partition_active_processors;
  370. struct device_node *rtas_node;
  371. const int *lrdrp = NULL;
  372. rtas_node = of_find_node_by_path("/rtas");
  373. if (rtas_node)
  374. lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
  375. if (lrdrp == NULL) {
  376. partition_potential_processors = vdso_data->processorCount;
  377. } else {
  378. partition_potential_processors = *(lrdrp + 4);
  379. }
  380. of_node_put(rtas_node);
  381. partition_active_processors = lparcfg_count_active_processors();
  382. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  383. /* this call handles the ibm,get-system-parameter contents */
  384. parse_system_parameter_string(m);
  385. parse_ppp_data(m);
  386. parse_mpp_data(m);
  387. pseries_cmo_data(m);
  388. seq_printf(m, "purr=%ld\n", get_purr());
  389. } else { /* non SPLPAR case */
  390. seq_printf(m, "system_active_processors=%d\n",
  391. partition_potential_processors);
  392. seq_printf(m, "system_potential_processors=%d\n",
  393. partition_potential_processors);
  394. seq_printf(m, "partition_max_entitled_capacity=%d\n",
  395. partition_potential_processors * 100);
  396. seq_printf(m, "partition_entitled_capacity=%d\n",
  397. partition_active_processors * 100);
  398. }
  399. seq_printf(m, "partition_active_processors=%d\n",
  400. partition_active_processors);
  401. seq_printf(m, "partition_potential_processors=%d\n",
  402. partition_potential_processors);
  403. seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
  404. return 0;
  405. }
  406. static ssize_t update_ppp(u64 *entitlement, u8 *weight)
  407. {
  408. struct hvcall_ppp_data ppp_data;
  409. u8 new_weight;
  410. u64 new_entitled;
  411. ssize_t retval;
  412. /* Get our current parameters */
  413. retval = h_get_ppp(&ppp_data);
  414. if (retval)
  415. return retval;
  416. if (entitlement) {
  417. new_weight = ppp_data.weight;
  418. new_entitled = *entitlement;
  419. } else if (weight) {
  420. new_weight = *weight;
  421. new_entitled = ppp_data.entitlement;
  422. } else
  423. return -EINVAL;
  424. pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
  425. __FUNCTION__, ppp_data.entitlement, ppp_data.weight);
  426. pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
  427. __FUNCTION__, new_entitled, new_weight);
  428. retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
  429. return retval;
  430. }
  431. /**
  432. * update_mpp
  433. *
  434. * Update the memory entitlement and weight for the partition. Caller must
  435. * specify either a new entitlement or weight, not both, to be updated
  436. * since the h_set_mpp call takes both entitlement and weight as parameters.
  437. */
  438. static ssize_t update_mpp(u64 *entitlement, u8 *weight)
  439. {
  440. struct hvcall_mpp_data mpp_data;
  441. u64 new_entitled;
  442. u8 new_weight;
  443. ssize_t rc;
  444. if (entitlement) {
  445. /* Check with vio to ensure the new memory entitlement
  446. * can be handled.
  447. */
  448. rc = vio_cmo_entitlement_update(*entitlement);
  449. if (rc)
  450. return rc;
  451. }
  452. rc = h_get_mpp(&mpp_data);
  453. if (rc)
  454. return rc;
  455. if (entitlement) {
  456. new_weight = mpp_data.mem_weight;
  457. new_entitled = *entitlement;
  458. } else if (weight) {
  459. new_weight = *weight;
  460. new_entitled = mpp_data.entitled_mem;
  461. } else
  462. return -EINVAL;
  463. pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
  464. __FUNCTION__, mpp_data.entitled_mem, mpp_data.mem_weight);
  465. pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
  466. __FUNCTION__, new_entitled, new_weight);
  467. rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
  468. return rc;
  469. }
  470. /*
  471. * Interface for changing system parameters (variable capacity weight
  472. * and entitled capacity). Format of input is "param_name=value";
  473. * anything after value is ignored. Valid parameters at this time are
  474. * "partition_entitled_capacity" and "capacity_weight". We use
  475. * H_SET_PPP to alter parameters.
  476. *
  477. * This function should be invoked only on systems with
  478. * FW_FEATURE_SPLPAR.
  479. */
  480. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  481. size_t count, loff_t * off)
  482. {
  483. int kbuf_sz = 64;
  484. char kbuf[kbuf_sz];
  485. char *tmp;
  486. u64 new_entitled, *new_entitled_ptr = &new_entitled;
  487. u8 new_weight, *new_weight_ptr = &new_weight;
  488. ssize_t retval;
  489. if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
  490. firmware_has_feature(FW_FEATURE_ISERIES))
  491. return -EINVAL;
  492. if (count > kbuf_sz)
  493. return -EINVAL;
  494. if (copy_from_user(kbuf, buf, count))
  495. return -EFAULT;
  496. kbuf[count - 1] = '\0';
  497. tmp = strchr(kbuf, '=');
  498. if (!tmp)
  499. return -EINVAL;
  500. *tmp++ = '\0';
  501. if (!strcmp(kbuf, "partition_entitled_capacity")) {
  502. char *endp;
  503. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  504. if (endp == tmp)
  505. return -EINVAL;
  506. retval = update_ppp(new_entitled_ptr, NULL);
  507. } else if (!strcmp(kbuf, "capacity_weight")) {
  508. char *endp;
  509. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  510. if (endp == tmp)
  511. return -EINVAL;
  512. retval = update_ppp(NULL, new_weight_ptr);
  513. } else if (!strcmp(kbuf, "entitled_memory")) {
  514. char *endp;
  515. *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
  516. if (endp == tmp)
  517. return -EINVAL;
  518. retval = update_mpp(new_entitled_ptr, NULL);
  519. } else if (!strcmp(kbuf, "entitled_memory_weight")) {
  520. char *endp;
  521. *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
  522. if (endp == tmp)
  523. return -EINVAL;
  524. retval = update_mpp(NULL, new_weight_ptr);
  525. } else
  526. return -EINVAL;
  527. if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
  528. retval = count;
  529. } else if (retval == H_BUSY) {
  530. retval = -EBUSY;
  531. } else if (retval == H_HARDWARE) {
  532. retval = -EIO;
  533. } else if (retval == H_PARAMETER) {
  534. retval = -EINVAL;
  535. }
  536. return retval;
  537. }
  538. #else /* CONFIG_PPC_PSERIES */
  539. static int pseries_lparcfg_data(struct seq_file *m, void *v)
  540. {
  541. return 0;
  542. }
  543. static ssize_t lparcfg_write(struct file *file, const char __user * buf,
  544. size_t count, loff_t * off)
  545. {
  546. return -EINVAL;
  547. }
  548. #endif /* CONFIG_PPC_PSERIES */
  549. static int lparcfg_data(struct seq_file *m, void *v)
  550. {
  551. struct device_node *rootdn;
  552. const char *model = "";
  553. const char *system_id = "";
  554. const char *tmp;
  555. const unsigned int *lp_index_ptr;
  556. unsigned int lp_index = 0;
  557. seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
  558. rootdn = of_find_node_by_path("/");
  559. if (rootdn) {
  560. tmp = of_get_property(rootdn, "model", NULL);
  561. if (tmp) {
  562. model = tmp;
  563. /* Skip "IBM," - see platforms/iseries/dt.c */
  564. if (firmware_has_feature(FW_FEATURE_ISERIES))
  565. model += 4;
  566. }
  567. tmp = of_get_property(rootdn, "system-id", NULL);
  568. if (tmp) {
  569. system_id = tmp;
  570. /* Skip "IBM," - see platforms/iseries/dt.c */
  571. if (firmware_has_feature(FW_FEATURE_ISERIES))
  572. system_id += 4;
  573. }
  574. lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
  575. NULL);
  576. if (lp_index_ptr)
  577. lp_index = *lp_index_ptr;
  578. of_node_put(rootdn);
  579. }
  580. seq_printf(m, "serial_number=%s\n", system_id);
  581. seq_printf(m, "system_type=%s\n", model);
  582. seq_printf(m, "partition_id=%d\n", (int)lp_index);
  583. if (firmware_has_feature(FW_FEATURE_ISERIES))
  584. return iseries_lparcfg_data(m, v);
  585. return pseries_lparcfg_data(m, v);
  586. }
  587. static int lparcfg_open(struct inode *inode, struct file *file)
  588. {
  589. return single_open(file, lparcfg_data, NULL);
  590. }
  591. static const struct file_operations lparcfg_fops = {
  592. .owner = THIS_MODULE,
  593. .read = seq_read,
  594. .write = lparcfg_write,
  595. .open = lparcfg_open,
  596. .release = single_release,
  597. };
  598. static int __init lparcfg_init(void)
  599. {
  600. struct proc_dir_entry *ent;
  601. mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
  602. /* Allow writing if we have FW_FEATURE_SPLPAR */
  603. if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
  604. !firmware_has_feature(FW_FEATURE_ISERIES))
  605. mode |= S_IWUSR;
  606. ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops);
  607. if (!ent) {
  608. printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
  609. return -EIO;
  610. }
  611. proc_ppc64_lparcfg = ent;
  612. return 0;
  613. }
  614. static void __exit lparcfg_cleanup(void)
  615. {
  616. if (proc_ppc64_lparcfg)
  617. remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
  618. }
  619. module_init(lparcfg_init);
  620. module_exit(lparcfg_cleanup);
  621. MODULE_DESCRIPTION("Interface for LPAR configuration data");
  622. MODULE_AUTHOR("Dave Engebretsen");
  623. MODULE_LICENSE("GPL");