rtas-proc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2000 Tilmann Bitterberg
  4. * ([email protected])
  5. *
  6. * RTAS (Runtime Abstraction Services) stuff
  7. * Intention is to provide a clean user interface
  8. * to use the RTAS.
  9. *
  10. * TODO:
  11. * Split off a header file and maybe move it to a different
  12. * location. Write Documentation on what the /proc/rtas/ entries
  13. * actually do.
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/sched.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/stat.h>
  19. #include <linux/ctype.h>
  20. #include <linux/time.h>
  21. #include <linux/string.h>
  22. #include <linux/init.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/bitops.h>
  25. #include <linux/rtc.h>
  26. #include <linux/of.h>
  27. #include <linux/uaccess.h>
  28. #include <asm/processor.h>
  29. #include <asm/io.h>
  30. #include <asm/rtas.h>
  31. #include <asm/machdep.h> /* for ppc_md */
  32. #include <asm/time.h>
  33. /* Token for Sensors */
  34. #define KEY_SWITCH 0x0001
  35. #define ENCLOSURE_SWITCH 0x0002
  36. #define THERMAL_SENSOR 0x0003
  37. #define LID_STATUS 0x0004
  38. #define POWER_SOURCE 0x0005
  39. #define BATTERY_VOLTAGE 0x0006
  40. #define BATTERY_REMAINING 0x0007
  41. #define BATTERY_PERCENTAGE 0x0008
  42. #define EPOW_SENSOR 0x0009
  43. #define BATTERY_CYCLESTATE 0x000a
  44. #define BATTERY_CHARGING 0x000b
  45. /* IBM specific sensors */
  46. #define IBM_SURVEILLANCE 0x2328 /* 9000 */
  47. #define IBM_FANRPM 0x2329 /* 9001 */
  48. #define IBM_VOLTAGE 0x232a /* 9002 */
  49. #define IBM_DRCONNECTOR 0x232b /* 9003 */
  50. #define IBM_POWERSUPPLY 0x232c /* 9004 */
  51. /* Status return values */
  52. #define SENSOR_CRITICAL_HIGH 13
  53. #define SENSOR_WARNING_HIGH 12
  54. #define SENSOR_NORMAL 11
  55. #define SENSOR_WARNING_LOW 10
  56. #define SENSOR_CRITICAL_LOW 9
  57. #define SENSOR_SUCCESS 0
  58. #define SENSOR_HW_ERROR -1
  59. #define SENSOR_BUSY -2
  60. #define SENSOR_NOT_EXIST -3
  61. #define SENSOR_DR_ENTITY -9000
  62. /* Location Codes */
  63. #define LOC_SCSI_DEV_ADDR 'A'
  64. #define LOC_SCSI_DEV_LOC 'B'
  65. #define LOC_CPU 'C'
  66. #define LOC_DISKETTE 'D'
  67. #define LOC_ETHERNET 'E'
  68. #define LOC_FAN 'F'
  69. #define LOC_GRAPHICS 'G'
  70. /* reserved / not used 'H' */
  71. #define LOC_IO_ADAPTER 'I'
  72. /* reserved / not used 'J' */
  73. #define LOC_KEYBOARD 'K'
  74. #define LOC_LCD 'L'
  75. #define LOC_MEMORY 'M'
  76. #define LOC_NV_MEMORY 'N'
  77. #define LOC_MOUSE 'O'
  78. #define LOC_PLANAR 'P'
  79. #define LOC_OTHER_IO 'Q'
  80. #define LOC_PARALLEL 'R'
  81. #define LOC_SERIAL 'S'
  82. #define LOC_DEAD_RING 'T'
  83. #define LOC_RACKMOUNTED 'U' /* for _u_nit is rack mounted */
  84. #define LOC_VOLTAGE 'V'
  85. #define LOC_SWITCH_ADAPTER 'W'
  86. #define LOC_OTHER 'X'
  87. #define LOC_FIRMWARE 'Y'
  88. #define LOC_SCSI 'Z'
  89. /* Tokens for indicators */
  90. #define TONE_FREQUENCY 0x0001 /* 0 - 1000 (HZ)*/
  91. #define TONE_VOLUME 0x0002 /* 0 - 100 (%) */
  92. #define SYSTEM_POWER_STATE 0x0003
  93. #define WARNING_LIGHT 0x0004
  94. #define DISK_ACTIVITY_LIGHT 0x0005
  95. #define HEX_DISPLAY_UNIT 0x0006
  96. #define BATTERY_WARNING_TIME 0x0007
  97. #define CONDITION_CYCLE_REQUEST 0x0008
  98. #define SURVEILLANCE_INDICATOR 0x2328 /* 9000 */
  99. #define DR_ACTION 0x2329 /* 9001 */
  100. #define DR_INDICATOR 0x232a /* 9002 */
  101. /* 9003 - 9004: Vendor specific */
  102. /* 9006 - 9999: Vendor specific */
  103. /* other */
  104. #define MAX_SENSORS 17 /* I only know of 17 sensors */
  105. #define MAX_LINELENGTH 256
  106. #define SENSOR_PREFIX "ibm,sensor-"
  107. #define cel_to_fahr(x) ((x*9/5)+32)
  108. struct individual_sensor {
  109. unsigned int token;
  110. unsigned int quant;
  111. };
  112. struct rtas_sensors {
  113. struct individual_sensor sensor[MAX_SENSORS];
  114. unsigned int quant;
  115. };
  116. /* Globals */
  117. static struct rtas_sensors sensors;
  118. static struct device_node *rtas_node = NULL;
  119. static unsigned long power_on_time = 0; /* Save the time the user set */
  120. static char progress_led[MAX_LINELENGTH];
  121. static unsigned long rtas_tone_frequency = 1000;
  122. static unsigned long rtas_tone_volume = 0;
  123. /* ****************************************************************** */
  124. /* Declarations */
  125. static int ppc_rtas_sensors_show(struct seq_file *m, void *v);
  126. static int ppc_rtas_clock_show(struct seq_file *m, void *v);
  127. static ssize_t ppc_rtas_clock_write(struct file *file,
  128. const char __user *buf, size_t count, loff_t *ppos);
  129. static int ppc_rtas_progress_show(struct seq_file *m, void *v);
  130. static ssize_t ppc_rtas_progress_write(struct file *file,
  131. const char __user *buf, size_t count, loff_t *ppos);
  132. static int ppc_rtas_poweron_show(struct seq_file *m, void *v);
  133. static ssize_t ppc_rtas_poweron_write(struct file *file,
  134. const char __user *buf, size_t count, loff_t *ppos);
  135. static ssize_t ppc_rtas_tone_freq_write(struct file *file,
  136. const char __user *buf, size_t count, loff_t *ppos);
  137. static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v);
  138. static ssize_t ppc_rtas_tone_volume_write(struct file *file,
  139. const char __user *buf, size_t count, loff_t *ppos);
  140. static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v);
  141. static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v);
  142. static int poweron_open(struct inode *inode, struct file *file)
  143. {
  144. return single_open(file, ppc_rtas_poweron_show, NULL);
  145. }
  146. static const struct proc_ops ppc_rtas_poweron_proc_ops = {
  147. .proc_open = poweron_open,
  148. .proc_read = seq_read,
  149. .proc_lseek = seq_lseek,
  150. .proc_write = ppc_rtas_poweron_write,
  151. .proc_release = single_release,
  152. };
  153. static int progress_open(struct inode *inode, struct file *file)
  154. {
  155. return single_open(file, ppc_rtas_progress_show, NULL);
  156. }
  157. static const struct proc_ops ppc_rtas_progress_proc_ops = {
  158. .proc_open = progress_open,
  159. .proc_read = seq_read,
  160. .proc_lseek = seq_lseek,
  161. .proc_write = ppc_rtas_progress_write,
  162. .proc_release = single_release,
  163. };
  164. static int clock_open(struct inode *inode, struct file *file)
  165. {
  166. return single_open(file, ppc_rtas_clock_show, NULL);
  167. }
  168. static const struct proc_ops ppc_rtas_clock_proc_ops = {
  169. .proc_open = clock_open,
  170. .proc_read = seq_read,
  171. .proc_lseek = seq_lseek,
  172. .proc_write = ppc_rtas_clock_write,
  173. .proc_release = single_release,
  174. };
  175. static int tone_freq_open(struct inode *inode, struct file *file)
  176. {
  177. return single_open(file, ppc_rtas_tone_freq_show, NULL);
  178. }
  179. static const struct proc_ops ppc_rtas_tone_freq_proc_ops = {
  180. .proc_open = tone_freq_open,
  181. .proc_read = seq_read,
  182. .proc_lseek = seq_lseek,
  183. .proc_write = ppc_rtas_tone_freq_write,
  184. .proc_release = single_release,
  185. };
  186. static int tone_volume_open(struct inode *inode, struct file *file)
  187. {
  188. return single_open(file, ppc_rtas_tone_volume_show, NULL);
  189. }
  190. static const struct proc_ops ppc_rtas_tone_volume_proc_ops = {
  191. .proc_open = tone_volume_open,
  192. .proc_read = seq_read,
  193. .proc_lseek = seq_lseek,
  194. .proc_write = ppc_rtas_tone_volume_write,
  195. .proc_release = single_release,
  196. };
  197. static int ppc_rtas_find_all_sensors(void);
  198. static void ppc_rtas_process_sensor(struct seq_file *m,
  199. struct individual_sensor *s, int state, int error, const char *loc);
  200. static char *ppc_rtas_process_error(int error);
  201. static void get_location_code(struct seq_file *m,
  202. struct individual_sensor *s, const char *loc);
  203. static void check_location_string(struct seq_file *m, const char *c);
  204. static void check_location(struct seq_file *m, const char *c);
  205. static int __init proc_rtas_init(void)
  206. {
  207. if (!machine_is(pseries))
  208. return -ENODEV;
  209. rtas_node = of_find_node_by_name(NULL, "rtas");
  210. if (rtas_node == NULL)
  211. return -ENODEV;
  212. proc_create("powerpc/rtas/progress", 0644, NULL,
  213. &ppc_rtas_progress_proc_ops);
  214. proc_create("powerpc/rtas/clock", 0644, NULL,
  215. &ppc_rtas_clock_proc_ops);
  216. proc_create("powerpc/rtas/poweron", 0644, NULL,
  217. &ppc_rtas_poweron_proc_ops);
  218. proc_create_single("powerpc/rtas/sensors", 0444, NULL,
  219. ppc_rtas_sensors_show);
  220. proc_create("powerpc/rtas/frequency", 0644, NULL,
  221. &ppc_rtas_tone_freq_proc_ops);
  222. proc_create("powerpc/rtas/volume", 0644, NULL,
  223. &ppc_rtas_tone_volume_proc_ops);
  224. proc_create_single("powerpc/rtas/rmo_buffer", 0400, NULL,
  225. ppc_rtas_rmo_buf_show);
  226. return 0;
  227. }
  228. __initcall(proc_rtas_init);
  229. static int parse_number(const char __user *p, size_t count, u64 *val)
  230. {
  231. char buf[40];
  232. if (count > 39)
  233. return -EINVAL;
  234. if (copy_from_user(buf, p, count))
  235. return -EFAULT;
  236. buf[count] = 0;
  237. return kstrtoull(buf, 10, val);
  238. }
  239. /* ****************************************************************** */
  240. /* POWER-ON-TIME */
  241. /* ****************************************************************** */
  242. static ssize_t ppc_rtas_poweron_write(struct file *file,
  243. const char __user *buf, size_t count, loff_t *ppos)
  244. {
  245. struct rtc_time tm;
  246. time64_t nowtime;
  247. int error = parse_number(buf, count, &nowtime);
  248. if (error)
  249. return error;
  250. power_on_time = nowtime; /* save the time */
  251. rtc_time64_to_tm(nowtime, &tm);
  252. error = rtas_call(rtas_token("set-time-for-power-on"), 7, 1, NULL,
  253. tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
  254. tm.tm_hour, tm.tm_min, tm.tm_sec, 0 /* nano */);
  255. if (error)
  256. printk(KERN_WARNING "error: setting poweron time returned: %s\n",
  257. ppc_rtas_process_error(error));
  258. return count;
  259. }
  260. /* ****************************************************************** */
  261. static int ppc_rtas_poweron_show(struct seq_file *m, void *v)
  262. {
  263. if (power_on_time == 0)
  264. seq_printf(m, "Power on time not set\n");
  265. else
  266. seq_printf(m, "%lu\n",power_on_time);
  267. return 0;
  268. }
  269. /* ****************************************************************** */
  270. /* PROGRESS */
  271. /* ****************************************************************** */
  272. static ssize_t ppc_rtas_progress_write(struct file *file,
  273. const char __user *buf, size_t count, loff_t *ppos)
  274. {
  275. unsigned long hex;
  276. if (count >= MAX_LINELENGTH)
  277. count = MAX_LINELENGTH -1;
  278. if (copy_from_user(progress_led, buf, count)) { /* save the string */
  279. return -EFAULT;
  280. }
  281. progress_led[count] = 0;
  282. /* Lets see if the user passed hexdigits */
  283. hex = simple_strtoul(progress_led, NULL, 10);
  284. rtas_progress ((char *)progress_led, hex);
  285. return count;
  286. /* clear the line */
  287. /* rtas_progress(" ", 0xffff);*/
  288. }
  289. /* ****************************************************************** */
  290. static int ppc_rtas_progress_show(struct seq_file *m, void *v)
  291. {
  292. if (progress_led[0])
  293. seq_printf(m, "%s\n", progress_led);
  294. return 0;
  295. }
  296. /* ****************************************************************** */
  297. /* CLOCK */
  298. /* ****************************************************************** */
  299. static ssize_t ppc_rtas_clock_write(struct file *file,
  300. const char __user *buf, size_t count, loff_t *ppos)
  301. {
  302. struct rtc_time tm;
  303. time64_t nowtime;
  304. int error = parse_number(buf, count, &nowtime);
  305. if (error)
  306. return error;
  307. rtc_time64_to_tm(nowtime, &tm);
  308. error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL,
  309. tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
  310. tm.tm_hour, tm.tm_min, tm.tm_sec, 0);
  311. if (error)
  312. printk(KERN_WARNING "error: setting the clock returned: %s\n",
  313. ppc_rtas_process_error(error));
  314. return count;
  315. }
  316. /* ****************************************************************** */
  317. static int ppc_rtas_clock_show(struct seq_file *m, void *v)
  318. {
  319. int ret[8];
  320. int error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret);
  321. if (error) {
  322. printk(KERN_WARNING "error: reading the clock returned: %s\n",
  323. ppc_rtas_process_error(error));
  324. seq_printf(m, "0");
  325. } else {
  326. unsigned int year, mon, day, hour, min, sec;
  327. year = ret[0]; mon = ret[1]; day = ret[2];
  328. hour = ret[3]; min = ret[4]; sec = ret[5];
  329. seq_printf(m, "%lld\n",
  330. mktime64(year, mon, day, hour, min, sec));
  331. }
  332. return 0;
  333. }
  334. /* ****************************************************************** */
  335. /* SENSOR STUFF */
  336. /* ****************************************************************** */
  337. static int ppc_rtas_sensors_show(struct seq_file *m, void *v)
  338. {
  339. int i,j;
  340. int state, error;
  341. int get_sensor_state = rtas_token("get-sensor-state");
  342. seq_printf(m, "RTAS (RunTime Abstraction Services) Sensor Information\n");
  343. seq_printf(m, "Sensor\t\tValue\t\tCondition\tLocation\n");
  344. seq_printf(m, "********************************************************\n");
  345. if (ppc_rtas_find_all_sensors() != 0) {
  346. seq_printf(m, "\nNo sensors are available\n");
  347. return 0;
  348. }
  349. for (i=0; i<sensors.quant; i++) {
  350. struct individual_sensor *p = &sensors.sensor[i];
  351. char rstr[64];
  352. const char *loc;
  353. int llen, offs;
  354. sprintf (rstr, SENSOR_PREFIX"%04d", p->token);
  355. loc = of_get_property(rtas_node, rstr, &llen);
  356. /* A sensor may have multiple instances */
  357. for (j = 0, offs = 0; j <= p->quant; j++) {
  358. error = rtas_call(get_sensor_state, 2, 2, &state,
  359. p->token, j);
  360. ppc_rtas_process_sensor(m, p, state, error, loc);
  361. seq_putc(m, '\n');
  362. if (loc) {
  363. offs += strlen(loc) + 1;
  364. loc += strlen(loc) + 1;
  365. if (offs >= llen)
  366. loc = NULL;
  367. }
  368. }
  369. }
  370. return 0;
  371. }
  372. /* ****************************************************************** */
  373. static int ppc_rtas_find_all_sensors(void)
  374. {
  375. const unsigned int *utmp;
  376. int len, i;
  377. utmp = of_get_property(rtas_node, "rtas-sensors", &len);
  378. if (utmp == NULL) {
  379. printk (KERN_ERR "error: could not get rtas-sensors\n");
  380. return 1;
  381. }
  382. sensors.quant = len / 8; /* int + int */
  383. for (i=0; i<sensors.quant; i++) {
  384. sensors.sensor[i].token = *utmp++;
  385. sensors.sensor[i].quant = *utmp++;
  386. }
  387. return 0;
  388. }
  389. /* ****************************************************************** */
  390. /*
  391. * Builds a string of what rtas returned
  392. */
  393. static char *ppc_rtas_process_error(int error)
  394. {
  395. switch (error) {
  396. case SENSOR_CRITICAL_HIGH:
  397. return "(critical high)";
  398. case SENSOR_WARNING_HIGH:
  399. return "(warning high)";
  400. case SENSOR_NORMAL:
  401. return "(normal)";
  402. case SENSOR_WARNING_LOW:
  403. return "(warning low)";
  404. case SENSOR_CRITICAL_LOW:
  405. return "(critical low)";
  406. case SENSOR_SUCCESS:
  407. return "(read ok)";
  408. case SENSOR_HW_ERROR:
  409. return "(hardware error)";
  410. case SENSOR_BUSY:
  411. return "(busy)";
  412. case SENSOR_NOT_EXIST:
  413. return "(non existent)";
  414. case SENSOR_DR_ENTITY:
  415. return "(dr entity removed)";
  416. default:
  417. return "(UNKNOWN)";
  418. }
  419. }
  420. /* ****************************************************************** */
  421. /*
  422. * Builds a string out of what the sensor said
  423. */
  424. static void ppc_rtas_process_sensor(struct seq_file *m,
  425. struct individual_sensor *s, int state, int error, const char *loc)
  426. {
  427. /* Defined return vales */
  428. const char * key_switch[] = { "Off\t", "Normal\t", "Secure\t",
  429. "Maintenance" };
  430. const char * enclosure_switch[] = { "Closed", "Open" };
  431. const char * lid_status[] = { " ", "Open", "Closed" };
  432. const char * power_source[] = { "AC\t", "Battery",
  433. "AC & Battery" };
  434. const char * battery_remaining[] = { "Very Low", "Low", "Mid", "High" };
  435. const char * epow_sensor[] = {
  436. "EPOW Reset", "Cooling warning", "Power warning",
  437. "System shutdown", "System halt", "EPOW main enclosure",
  438. "EPOW power off" };
  439. const char * battery_cyclestate[] = { "None", "In progress",
  440. "Requested" };
  441. const char * battery_charging[] = { "Charging", "Discharging",
  442. "No current flow" };
  443. const char * ibm_drconnector[] = { "Empty", "Present", "Unusable",
  444. "Exchange" };
  445. int have_strings = 0;
  446. int num_states = 0;
  447. int temperature = 0;
  448. int unknown = 0;
  449. /* What kind of sensor do we have here? */
  450. switch (s->token) {
  451. case KEY_SWITCH:
  452. seq_printf(m, "Key switch:\t");
  453. num_states = sizeof(key_switch) / sizeof(char *);
  454. if (state < num_states) {
  455. seq_printf(m, "%s\t", key_switch[state]);
  456. have_strings = 1;
  457. }
  458. break;
  459. case ENCLOSURE_SWITCH:
  460. seq_printf(m, "Enclosure switch:\t");
  461. num_states = sizeof(enclosure_switch) / sizeof(char *);
  462. if (state < num_states) {
  463. seq_printf(m, "%s\t",
  464. enclosure_switch[state]);
  465. have_strings = 1;
  466. }
  467. break;
  468. case THERMAL_SENSOR:
  469. seq_printf(m, "Temp. (C/F):\t");
  470. temperature = 1;
  471. break;
  472. case LID_STATUS:
  473. seq_printf(m, "Lid status:\t");
  474. num_states = sizeof(lid_status) / sizeof(char *);
  475. if (state < num_states) {
  476. seq_printf(m, "%s\t", lid_status[state]);
  477. have_strings = 1;
  478. }
  479. break;
  480. case POWER_SOURCE:
  481. seq_printf(m, "Power source:\t");
  482. num_states = sizeof(power_source) / sizeof(char *);
  483. if (state < num_states) {
  484. seq_printf(m, "%s\t",
  485. power_source[state]);
  486. have_strings = 1;
  487. }
  488. break;
  489. case BATTERY_VOLTAGE:
  490. seq_printf(m, "Battery voltage:\t");
  491. break;
  492. case BATTERY_REMAINING:
  493. seq_printf(m, "Battery remaining:\t");
  494. num_states = sizeof(battery_remaining) / sizeof(char *);
  495. if (state < num_states)
  496. {
  497. seq_printf(m, "%s\t",
  498. battery_remaining[state]);
  499. have_strings = 1;
  500. }
  501. break;
  502. case BATTERY_PERCENTAGE:
  503. seq_printf(m, "Battery percentage:\t");
  504. break;
  505. case EPOW_SENSOR:
  506. seq_printf(m, "EPOW Sensor:\t");
  507. num_states = sizeof(epow_sensor) / sizeof(char *);
  508. if (state < num_states) {
  509. seq_printf(m, "%s\t", epow_sensor[state]);
  510. have_strings = 1;
  511. }
  512. break;
  513. case BATTERY_CYCLESTATE:
  514. seq_printf(m, "Battery cyclestate:\t");
  515. num_states = sizeof(battery_cyclestate) /
  516. sizeof(char *);
  517. if (state < num_states) {
  518. seq_printf(m, "%s\t",
  519. battery_cyclestate[state]);
  520. have_strings = 1;
  521. }
  522. break;
  523. case BATTERY_CHARGING:
  524. seq_printf(m, "Battery Charging:\t");
  525. num_states = sizeof(battery_charging) / sizeof(char *);
  526. if (state < num_states) {
  527. seq_printf(m, "%s\t",
  528. battery_charging[state]);
  529. have_strings = 1;
  530. }
  531. break;
  532. case IBM_SURVEILLANCE:
  533. seq_printf(m, "Surveillance:\t");
  534. break;
  535. case IBM_FANRPM:
  536. seq_printf(m, "Fan (rpm):\t");
  537. break;
  538. case IBM_VOLTAGE:
  539. seq_printf(m, "Voltage (mv):\t");
  540. break;
  541. case IBM_DRCONNECTOR:
  542. seq_printf(m, "DR connector:\t");
  543. num_states = sizeof(ibm_drconnector) / sizeof(char *);
  544. if (state < num_states) {
  545. seq_printf(m, "%s\t",
  546. ibm_drconnector[state]);
  547. have_strings = 1;
  548. }
  549. break;
  550. case IBM_POWERSUPPLY:
  551. seq_printf(m, "Powersupply:\t");
  552. break;
  553. default:
  554. seq_printf(m, "Unknown sensor (type %d), ignoring it\n",
  555. s->token);
  556. unknown = 1;
  557. have_strings = 1;
  558. break;
  559. }
  560. if (have_strings == 0) {
  561. if (temperature) {
  562. seq_printf(m, "%4d /%4d\t", state, cel_to_fahr(state));
  563. } else
  564. seq_printf(m, "%10d\t", state);
  565. }
  566. if (unknown == 0) {
  567. seq_printf(m, "%s\t", ppc_rtas_process_error(error));
  568. get_location_code(m, s, loc);
  569. }
  570. }
  571. /* ****************************************************************** */
  572. static void check_location(struct seq_file *m, const char *c)
  573. {
  574. switch (c[0]) {
  575. case LOC_PLANAR:
  576. seq_printf(m, "Planar #%c", c[1]);
  577. break;
  578. case LOC_CPU:
  579. seq_printf(m, "CPU #%c", c[1]);
  580. break;
  581. case LOC_FAN:
  582. seq_printf(m, "Fan #%c", c[1]);
  583. break;
  584. case LOC_RACKMOUNTED:
  585. seq_printf(m, "Rack #%c", c[1]);
  586. break;
  587. case LOC_VOLTAGE:
  588. seq_printf(m, "Voltage #%c", c[1]);
  589. break;
  590. case LOC_LCD:
  591. seq_printf(m, "LCD #%c", c[1]);
  592. break;
  593. case '.':
  594. seq_printf(m, "- %c", c[1]);
  595. break;
  596. default:
  597. seq_printf(m, "Unknown location");
  598. break;
  599. }
  600. }
  601. /* ****************************************************************** */
  602. /*
  603. * Format:
  604. * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ]
  605. * the '.' may be an abbreviation
  606. */
  607. static void check_location_string(struct seq_file *m, const char *c)
  608. {
  609. while (*c) {
  610. if (isalpha(*c) || *c == '.')
  611. check_location(m, c);
  612. else if (*c == '/' || *c == '-')
  613. seq_printf(m, " at ");
  614. c++;
  615. }
  616. }
  617. /* ****************************************************************** */
  618. static void get_location_code(struct seq_file *m, struct individual_sensor *s,
  619. const char *loc)
  620. {
  621. if (!loc || !*loc) {
  622. seq_printf(m, "---");/* does not have a location */
  623. } else {
  624. check_location_string(m, loc);
  625. }
  626. seq_putc(m, ' ');
  627. }
  628. /* ****************************************************************** */
  629. /* INDICATORS - Tone Frequency */
  630. /* ****************************************************************** */
  631. static ssize_t ppc_rtas_tone_freq_write(struct file *file,
  632. const char __user *buf, size_t count, loff_t *ppos)
  633. {
  634. u64 freq;
  635. int error = parse_number(buf, count, &freq);
  636. if (error)
  637. return error;
  638. rtas_tone_frequency = freq; /* save it for later */
  639. error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
  640. TONE_FREQUENCY, 0, freq);
  641. if (error)
  642. printk(KERN_WARNING "error: setting tone frequency returned: %s\n",
  643. ppc_rtas_process_error(error));
  644. return count;
  645. }
  646. /* ****************************************************************** */
  647. static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v)
  648. {
  649. seq_printf(m, "%lu\n", rtas_tone_frequency);
  650. return 0;
  651. }
  652. /* ****************************************************************** */
  653. /* INDICATORS - Tone Volume */
  654. /* ****************************************************************** */
  655. static ssize_t ppc_rtas_tone_volume_write(struct file *file,
  656. const char __user *buf, size_t count, loff_t *ppos)
  657. {
  658. u64 volume;
  659. int error = parse_number(buf, count, &volume);
  660. if (error)
  661. return error;
  662. if (volume > 100)
  663. volume = 100;
  664. rtas_tone_volume = volume; /* save it for later */
  665. error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
  666. TONE_VOLUME, 0, volume);
  667. if (error)
  668. printk(KERN_WARNING "error: setting tone volume returned: %s\n",
  669. ppc_rtas_process_error(error));
  670. return count;
  671. }
  672. /* ****************************************************************** */
  673. static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v)
  674. {
  675. seq_printf(m, "%lu\n", rtas_tone_volume);
  676. return 0;
  677. }
  678. /**
  679. * ppc_rtas_rmo_buf_show() - Describe RTAS-addressable region for user space.
  680. *
  681. * Base + size description of a range of RTAS-addressable memory set
  682. * aside for user space to use as work area(s) for certain RTAS
  683. * functions. User space accesses this region via /dev/mem. Apart from
  684. * security policies, the kernel does not arbitrate or serialize
  685. * access to this region, and user space must ensure that concurrent
  686. * users do not interfere with each other.
  687. */
  688. static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v)
  689. {
  690. seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_USER_REGION_SIZE);
  691. return 0;
  692. }