2 * arch/ppc64/kernel/rtas-proc.c
3 * Copyright (C) 2000 Tilmann Bitterberg
4 * (tilmann@bitterberg.de)
6 * RTAS (Runtime Abstraction Services) stuff
7 * Intention is to provide a clean user interface
11 * Split off a header file and maybe move it to a different
12 * location. Write Documentation on what the /proc/rtas/ entries
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/proc_fs.h>
19 #include <linux/stat.h>
20 #include <linux/ctype.h>
21 #include <linux/time.h>
22 #include <linux/string.h>
23 #include <linux/init.h>
25 #include <asm/uaccess.h>
26 #include <asm/bitops.h>
27 #include <asm/processor.h>
31 #include <asm/machdep.h> /* for ppc_md */
34 /* Token for Sensors */
35 #define KEY_SWITCH 0x0001
36 #define ENCLOSURE_SWITCH 0x0002
37 #define THERMAL_SENSOR 0x0003
38 #define LID_STATUS 0x0004
39 #define POWER_SOURCE 0x0005
40 #define BATTERY_VOLTAGE 0x0006
41 #define BATTERY_REMAINING 0x0007
42 #define BATTERY_PERCENTAGE 0x0008
43 #define EPOW_SENSOR 0x0009
44 #define BATTERY_CYCLESTATE 0x000a
45 #define BATTERY_CHARGING 0x000b
47 /* IBM specific sensors */
48 #define IBM_SURVEILLANCE 0x2328 /* 9000 */
49 #define IBM_FANRPM 0x2329 /* 9001 */
50 #define IBM_VOLTAGE 0x232a /* 9002 */
51 #define IBM_DRCONNECTOR 0x232b /* 9003 */
52 #define IBM_POWERSUPPLY 0x232c /* 9004 */
53 #define IBM_INTQUEUE 0x232d /* 9005 */
55 /* Status return values */
56 #define SENSOR_CRITICAL_HIGH 13
57 #define SENSOR_WARNING_HIGH 12
58 #define SENSOR_NORMAL 11
59 #define SENSOR_WARNING_LOW 10
60 #define SENSOR_CRITICAL_LOW 9
61 #define SENSOR_SUCCESS 0
62 #define SENSOR_HW_ERROR -1
63 #define SENSOR_BUSY -2
64 #define SENSOR_NOT_EXIST -3
65 #define SENSOR_DR_ENTITY -9000
68 #define LOC_SCSI_DEV_ADDR 'A'
69 #define LOC_SCSI_DEV_LOC 'B'
71 #define LOC_DISKETTE 'D'
72 #define LOC_ETHERNET 'E'
74 #define LOC_GRAPHICS 'G'
75 /* reserved / not used 'H' */
76 #define LOC_IO_ADAPTER 'I'
77 /* reserved / not used 'J' */
78 #define LOC_KEYBOARD 'K'
80 #define LOC_MEMORY 'M'
81 #define LOC_NV_MEMORY 'N'
83 #define LOC_PLANAR 'P'
84 #define LOC_OTHER_IO 'Q'
85 #define LOC_PARALLEL 'R'
86 #define LOC_SERIAL 'S'
87 #define LOC_DEAD_RING 'T'
88 #define LOC_RACKMOUNTED 'U' /* for _u_nit is rack mounted */
89 #define LOC_VOLTAGE 'V'
90 #define LOC_SWITCH_ADAPTER 'W'
92 #define LOC_FIRMWARE 'Y'
95 /* Tokens for indicators */
96 #define TONE_FREQUENCY 0x0001 /* 0 - 1000 (HZ)*/
97 #define TONE_VOLUME 0x0002 /* 0 - 100 (%) */
98 #define SYSTEM_POWER_STATE 0x0003
99 #define WARNING_LIGHT 0x0004
100 #define DISK_ACTIVITY_LIGHT 0x0005
101 #define HEX_DISPLAY_UNIT 0x0006
102 #define BATTERY_WARNING_TIME 0x0007
103 #define CONDITION_CYCLE_REQUEST 0x0008
104 #define SURVEILLANCE_INDICATOR 0x2328 /* 9000 */
105 #define DR_ACTION 0x2329 /* 9001 */
106 #define DR_INDICATOR 0x232a /* 9002 */
107 /* 9003 - 9004: Vendor specific */
108 #define GLOBAL_INTERRUPT_QUEUE 0x232d /* 9005 */
109 /* 9006 - 9999: Vendor specific */
112 #define MAX_SENSORS 17 /* I only know of 17 sensors */
113 #define MAX_LINELENGTH 256
114 #define SENSOR_PREFIX "ibm,sensor-"
115 #define cel_to_fahr(x) ((x*9/5)+32)
119 static struct rtas_sensors sensors;
120 static struct device_node *rtas_node = NULL;
121 static unsigned long power_on_time = 0; /* Save the time the user set */
122 static char progress_led[MAX_LINELENGTH];
124 static unsigned long rtas_tone_frequency = 1000;
125 static unsigned long rtas_tone_volume = 0;
127 /* ****************STRUCTS******************************************* */
128 struct individual_sensor {
133 struct rtas_sensors {
134 struct individual_sensor sensor[MAX_SENSORS];
138 /* ****************************************************************** */
140 static int ppc_rtas_sensor_read(char * buf, char ** start, off_t off,
141 int count, int *eof, void *data);
142 static ssize_t ppc_rtas_clock_read(struct file * file, char * buf,
143 size_t count, loff_t *ppos);
144 static ssize_t ppc_rtas_clock_write(struct file * file, const char * buf,
145 size_t count, loff_t *ppos);
146 static ssize_t ppc_rtas_progress_read(struct file * file, char * buf,
147 size_t count, loff_t *ppos);
148 static ssize_t ppc_rtas_progress_write(struct file * file, const char * buf,
149 size_t count, loff_t *ppos);
150 static ssize_t ppc_rtas_poweron_read(struct file * file, char * buf,
151 size_t count, loff_t *ppos);
152 static ssize_t ppc_rtas_poweron_write(struct file * file, const char * buf,
153 size_t count, loff_t *ppos);
155 static ssize_t ppc_rtas_tone_freq_write(struct file * file, const char * buf,
156 size_t count, loff_t *ppos);
157 static ssize_t ppc_rtas_tone_freq_read(struct file * file, char * buf,
158 size_t count, loff_t *ppos);
159 static ssize_t ppc_rtas_tone_volume_write(struct file * file, const char * buf,
160 size_t count, loff_t *ppos);
161 static ssize_t ppc_rtas_tone_volume_read(struct file * file, char * buf,
162 size_t count, loff_t *ppos);
163 static ssize_t ppc_rtas_rmo_buf_read(struct file *file, char *buf,
164 size_t count, loff_t *ppos);
166 struct file_operations ppc_rtas_poweron_operations = {
167 .read = ppc_rtas_poweron_read,
168 .write = ppc_rtas_poweron_write
170 struct file_operations ppc_rtas_progress_operations = {
171 .read = ppc_rtas_progress_read,
172 .write = ppc_rtas_progress_write
175 struct file_operations ppc_rtas_clock_operations = {
176 .read = ppc_rtas_clock_read,
177 .write = ppc_rtas_clock_write
180 struct file_operations ppc_rtas_tone_freq_operations = {
181 .read = ppc_rtas_tone_freq_read,
182 .write = ppc_rtas_tone_freq_write
184 struct file_operations ppc_rtas_tone_volume_operations = {
185 .read = ppc_rtas_tone_volume_read,
186 .write = ppc_rtas_tone_volume_write
189 static struct file_operations ppc_rtas_rmo_buf_ops = {
190 .read = ppc_rtas_rmo_buf_read,
193 int ppc_rtas_find_all_sensors (void);
194 int ppc_rtas_process_sensor(struct individual_sensor s, int state,
195 int error, char * buf);
196 char * ppc_rtas_process_error(int error);
197 int get_location_code(struct individual_sensor s, char * buf);
198 int check_location_string (char *c, char * buf);
199 int check_location (char *c, int idx, char * buf);
201 static int __init proc_rtas_init(void)
203 struct proc_dir_entry *entry;
205 if (!(systemcfg->platform & PLATFORM_PSERIES))
208 rtas_node = of_find_node_by_name(NULL, "rtas");
209 if (rtas_node == NULL)
212 entry = create_proc_entry("ppc64/rtas/progress", S_IRUGO|S_IWUSR, NULL);
214 entry->proc_fops = &ppc_rtas_progress_operations;
216 entry = create_proc_entry("ppc64/rtas/clock", S_IRUGO|S_IWUSR, NULL);
218 entry->proc_fops = &ppc_rtas_clock_operations;
220 entry = create_proc_entry("ppc64/rtas/poweron", S_IWUSR|S_IRUGO, NULL);
222 entry->proc_fops = &ppc_rtas_poweron_operations;
224 create_proc_read_entry("ppc64/rtas/sensors", S_IRUGO, NULL,
225 ppc_rtas_sensor_read, NULL);
227 entry = create_proc_entry("ppc64/rtas/frequency", S_IWUSR|S_IRUGO,
230 entry->proc_fops = &ppc_rtas_tone_freq_operations;
232 entry = create_proc_entry("ppc64/rtas/volume", S_IWUSR|S_IRUGO, NULL);
234 entry->proc_fops = &ppc_rtas_tone_volume_operations;
236 entry = create_proc_entry("ppc64/rtas/rmo_buffer", S_IRUSR, NULL);
238 entry->proc_fops = &ppc_rtas_rmo_buf_ops;
243 __initcall(proc_rtas_init);
245 /* ****************************************************************** */
247 /* ****************************************************************** */
248 static ssize_t ppc_rtas_poweron_write(struct file * file, const char * buf,
249 size_t count, loff_t *ppos)
251 char stkbuf[40]; /* its small, its on stack */
253 unsigned long nowtime;
257 if (39 < count) count = 39;
258 if (copy_from_user (stkbuf, buf, count)) {
262 nowtime = simple_strtoul(stkbuf, &dest, 10);
263 if (*dest != '\0' && *dest != '\n') {
264 printk("ppc_rtas_poweron_write: Invalid time\n");
267 power_on_time = nowtime; /* save the time */
271 error = rtas_call(rtas_token("set-time-for-power-on"), 7, 1, NULL,
272 tm.tm_year, tm.tm_mon, tm.tm_mday,
273 tm.tm_hour, tm.tm_min, tm.tm_sec, 0 /* nano */);
275 printk(KERN_WARNING "error: setting poweron time returned: %s\n",
276 ppc_rtas_process_error(error));
279 /* ****************************************************************** */
280 static ssize_t ppc_rtas_poweron_read(struct file * file, char * buf,
281 size_t count, loff_t *ppos)
283 char stkbuf[40]; /* its small, its on stack */
285 if (power_on_time == 0)
286 n = scnprintf(stkbuf,sizeof(stkbuf),"Power on time not set\n");
288 n = scnprintf(stkbuf,sizeof(stkbuf),"%lu\n",power_on_time);
290 sn = strlen (stkbuf) +1;
297 if (copy_to_user (buf, stkbuf + (*ppos), n)) {
304 /* ****************************************************************** */
306 /* ****************************************************************** */
307 static ssize_t ppc_rtas_progress_write(struct file * file, const char * buf,
308 size_t count, loff_t *ppos)
312 if (count >= MAX_LINELENGTH) count = MAX_LINELENGTH -1;
313 if (copy_from_user (progress_led, buf, count)) { /* save the string */
316 progress_led[count] = 0;
318 /* Lets see if the user passed hexdigits */
319 hex = simple_strtoul(progress_led, NULL, 10);
321 ppc_md.progress ((char *)progress_led, hex);
324 /* clear the line */ /* ppc_md.progress(" ", 0xffff);*/
326 /* ****************************************************************** */
327 static ssize_t ppc_rtas_progress_read(struct file * file, char * buf,
328 size_t count, loff_t *ppos)
333 if (progress_led == NULL) return 0;
335 tmpbuf = kmalloc (MAX_LINELENGTH, GFP_KERNEL);
337 printk(KERN_ERR "error: kmalloc failed\n");
340 n = sprintf (tmpbuf, "%s\n", progress_led);
342 sn = strlen (tmpbuf) +1;
351 if (copy_to_user (buf, tmpbuf + (*ppos), n)) {
360 /* ****************************************************************** */
362 /* ****************************************************************** */
363 static ssize_t ppc_rtas_clock_write(struct file * file, const char * buf,
364 size_t count, loff_t *ppos)
366 char stkbuf[40]; /* its small, its on stack */
368 unsigned long nowtime;
372 if (39 < count) count = 39;
373 if (copy_from_user (stkbuf, buf, count)) {
377 nowtime = simple_strtoul(stkbuf, &dest, 10);
378 if (*dest != '\0' && *dest != '\n') {
379 printk("ppc_rtas_clock_write: Invalid time\n");
384 error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL,
385 tm.tm_year, tm.tm_mon, tm.tm_mday,
386 tm.tm_hour, tm.tm_min, tm.tm_sec, 0);
388 printk(KERN_WARNING "error: setting the clock returned: %s\n",
389 ppc_rtas_process_error(error));
392 /* ****************************************************************** */
393 static ssize_t ppc_rtas_clock_read(struct file * file, char * buf,
394 size_t count, loff_t *ppos)
396 unsigned int year, mon, day, hour, min, sec;
399 char stkbuf[40]; /* its small, its on stack */
401 error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret);
403 year = ret[0]; mon = ret[1]; day = ret[2];
404 hour = ret[3]; min = ret[4]; sec = ret[5];
407 printk(KERN_WARNING "error: reading the clock returned: %s\n",
408 ppc_rtas_process_error(error));
409 n = scnprintf (stkbuf, sizeof(stkbuf), "0");
411 n = scnprintf (stkbuf, sizeof(stkbuf), "%lu\n",
412 mktime(year, mon, day, hour, min, sec));
415 sn = strlen (stkbuf) +1;
422 if (copy_to_user (buf, stkbuf + (*ppos), n)) {
429 /* ****************************************************************** */
431 /* ****************************************************************** */
432 static int ppc_rtas_sensor_read(char * buf, char ** start, off_t off,
433 int count, int *eof, void *data)
438 int get_sensor_state = rtas_token("get-sensor-state");
443 /* May not be enough */
444 buffer = kmalloc(MAX_LINELENGTH*MAX_SENSORS, GFP_KERNEL);
449 memset(buffer, 0, MAX_LINELENGTH*MAX_SENSORS);
451 n = sprintf ( buffer , "RTAS (RunTime Abstraction Services) Sensor Information\n");
452 n += sprintf ( buffer+n, "Sensor\t\tValue\t\tCondition\tLocation\n");
453 n += sprintf ( buffer+n, "********************************************************\n");
455 if (ppc_rtas_find_all_sensors() != 0) {
456 n += sprintf ( buffer+n, "\nNo sensors are available\n");
460 for (i=0; i<sensors.quant; i++) {
461 j = sensors.sensor[i].quant;
462 /* A sensor may have multiple instances */
465 error = rtas_call(get_sensor_state, 2, 2, &state,
466 sensors.sensor[i].token,
467 sensors.sensor[i].quant - j);
469 n += ppc_rtas_process_sensor(sensors.sensor[i], state,
471 n += sprintf (buffer+n, "\n");
477 if (off >= strlen(buffer)) {
482 if (n > strlen(buffer) - off)
483 n = strlen(buffer) - off;
489 memcpy(buf, buffer + off, n);
495 /* ****************************************************************** */
497 int ppc_rtas_find_all_sensors (void)
502 utmp = (unsigned int *) get_property(rtas_node, "rtas-sensors", &len);
504 printk (KERN_ERR "error: could not get rtas-sensors\n");
508 sensors.quant = len / 8; /* int + int */
510 for (i=0; i<sensors.quant; i++) {
511 sensors.sensor[i].token = *utmp++;
512 sensors.sensor[i].quant = *utmp++;
517 /* ****************************************************************** */
519 * Builds a string of what rtas returned
521 char * ppc_rtas_process_error(int error)
524 case SENSOR_CRITICAL_HIGH:
525 return "(critical high)";
526 case SENSOR_WARNING_HIGH:
527 return "(warning high)";
530 case SENSOR_WARNING_LOW:
531 return "(warning low)";
532 case SENSOR_CRITICAL_LOW:
533 return "(critical low)";
536 case SENSOR_HW_ERROR:
537 return "(hardware error)";
540 case SENSOR_NOT_EXIST:
541 return "(non existent)";
542 case SENSOR_DR_ENTITY:
543 return "(dr entity removed)";
549 /* ****************************************************************** */
551 * Builds a string out of what the sensor said
554 int ppc_rtas_process_sensor(struct individual_sensor s, int state,
555 int error, char * buf)
557 /* Defined return vales */
558 const char * key_switch[] = { "Off\t", "Normal\t", "Secure\t",
560 const char * enclosure_switch[] = { "Closed", "Open" };
561 const char * lid_status[] = { " ", "Open", "Closed" };
562 const char * power_source[] = { "AC\t", "Battery",
564 const char * battery_remaining[] = { "Very Low", "Low", "Mid", "High" };
565 const char * epow_sensor[] = {
566 "EPOW Reset", "Cooling warning", "Power warning",
567 "System shutdown", "System halt", "EPOW main enclosure",
569 const char * battery_cyclestate[] = { "None", "In progress",
571 const char * battery_charging[] = { "Charging", "Discharching",
573 const char * ibm_drconnector[] = { "Empty", "Present", "Unusable",
575 const char * ibm_intqueue[] = { "Disabled", "Enabled" };
577 int have_strings = 0;
583 /* What kind of sensor do we have here? */
587 n += sprintf(buf+n, "Key switch:\t");
588 num_states = sizeof(key_switch) / sizeof(char *);
589 if (state < num_states) {
590 n += sprintf(buf+n, "%s\t", key_switch[state]);
594 case ENCLOSURE_SWITCH:
595 n += sprintf(buf+n, "Enclosure switch:\t");
596 num_states = sizeof(enclosure_switch) / sizeof(char *);
597 if (state < num_states) {
598 n += sprintf(buf+n, "%s\t",
599 enclosure_switch[state]);
604 n += sprintf(buf+n, "Temp. (°C/°F):\t");
608 n += sprintf(buf+n, "Lid status:\t");
609 num_states = sizeof(lid_status) / sizeof(char *);
610 if (state < num_states) {
611 n += sprintf(buf+n, "%s\t", lid_status[state]);
616 n += sprintf(buf+n, "Power source:\t");
617 num_states = sizeof(power_source) / sizeof(char *);
618 if (state < num_states) {
619 n += sprintf(buf+n, "%s\t",
620 power_source[state]);
624 case BATTERY_VOLTAGE:
625 n += sprintf(buf+n, "Battery voltage:\t");
627 case BATTERY_REMAINING:
628 n += sprintf(buf+n, "Battery remaining:\t");
629 num_states = sizeof(battery_remaining) / sizeof(char *);
630 if (state < num_states)
632 n += sprintf(buf+n, "%s\t",
633 battery_remaining[state]);
637 case BATTERY_PERCENTAGE:
638 n += sprintf(buf+n, "Battery percentage:\t");
641 n += sprintf(buf+n, "EPOW Sensor:\t");
642 num_states = sizeof(epow_sensor) / sizeof(char *);
643 if (state < num_states) {
644 n += sprintf(buf+n, "%s\t", epow_sensor[state]);
648 case BATTERY_CYCLESTATE:
649 n += sprintf(buf+n, "Battery cyclestate:\t");
650 num_states = sizeof(battery_cyclestate) /
652 if (state < num_states) {
653 n += sprintf(buf+n, "%s\t",
654 battery_cyclestate[state]);
658 case BATTERY_CHARGING:
659 n += sprintf(buf+n, "Battery Charging:\t");
660 num_states = sizeof(battery_charging) / sizeof(char *);
661 if (state < num_states) {
662 n += sprintf(buf+n, "%s\t",
663 battery_charging[state]);
667 case IBM_SURVEILLANCE:
668 n += sprintf(buf+n, "Surveillance:\t");
671 n += sprintf(buf+n, "Fan (rpm):\t");
674 n += sprintf(buf+n, "Voltage (mv):\t");
676 case IBM_DRCONNECTOR:
677 n += sprintf(buf+n, "DR connector:\t");
678 num_states = sizeof(ibm_drconnector) / sizeof(char *);
679 if (state < num_states) {
680 n += sprintf(buf+n, "%s\t",
681 ibm_drconnector[state]);
685 case IBM_POWERSUPPLY:
686 n += sprintf(buf+n, "Powersupply:\t");
689 n += sprintf(buf+n, "Interrupt queue:\t");
690 num_states = sizeof(ibm_intqueue) / sizeof(char *);
691 if (state < num_states) {
692 n += sprintf(buf+n, "%s\t",
693 ibm_intqueue[state]);
698 n += sprintf(buf+n, "Unknown sensor (type %d), ignoring it\n",
704 if (have_strings == 0) {
706 n += sprintf(buf+n, "%4d /%4d\t", state, cel_to_fahr(state));
708 n += sprintf(buf+n, "%10d\t", state);
711 n += sprintf ( buf+n, "%s\t", ppc_rtas_process_error(error));
712 n += get_location_code(s, buf+n);
717 /* ****************************************************************** */
719 int check_location (char *c, int idx, char * buf)
725 n += sprintf ( buf, "Planar #%c", *(c+idx+1));
728 n += sprintf ( buf, "CPU #%c", *(c+idx+1));
731 n += sprintf ( buf, "Fan #%c", *(c+idx+1));
733 case LOC_RACKMOUNTED:
734 n += sprintf ( buf, "Rack #%c", *(c+idx+1));
737 n += sprintf ( buf, "Voltage #%c", *(c+idx+1));
740 n += sprintf ( buf, "LCD #%c", *(c+idx+1));
743 n += sprintf ( buf, "- %c", *(c+idx+1));
745 n += sprintf ( buf, "Unknown location");
752 /* ****************************************************************** */
755 * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ]
756 * the '.' may be an abbrevation
758 int check_location_string (char *c, char *buf)
763 if (isalpha(c[i]) || c[i] == '.') {
764 n += check_location(c, i, buf+n);
766 else if (c[i] == '/' || c[i] == '-')
767 n += sprintf(buf+n, " at ");
774 /* ****************************************************************** */
776 int get_location_code(struct individual_sensor s, char * buffer)
778 char rstr[512], tmp[10], tmp2[10];
779 int n=0, i=0, llen, len;
780 /* char *buf = kmalloc(MAX_LINELENGTH, GFP_KERNEL); */
783 static int pos = 0; /* remember position where buffer was */
785 /* construct the sensor number like 0003 */
786 /* fill with zeros */
787 n = sprintf(tmp, "%d", s.token);
789 while (strlen(tmp) < 4)
790 n += sprintf (tmp+n, "0");
792 /* invert the string */
795 tmp2[4-len+i] = tmp[i];
802 sprintf (rstr, SENSOR_PREFIX"%s", tmp2);
804 ret = (char *) get_property(rtas_node, rstr, &llen);
807 if (ret == NULL || ret[0] == '\0') {
808 n += sprintf ( buffer+n, "--- ");/* does not have a location */
813 n += check_location_string(ret, buffer + n);
814 n += sprintf ( buffer+n, " ");
815 /* see how many characters we have printed */
816 scnprintf(t, sizeof(t), "%s ", ret);
819 if (pos >= llen) pos=0;
823 /* ****************************************************************** */
824 /* INDICATORS - Tone Frequency */
825 /* ****************************************************************** */
826 static ssize_t ppc_rtas_tone_freq_write(struct file * file, const char * buf,
827 size_t count, loff_t *ppos)
829 char stkbuf[40]; /* its small, its on stack */
834 if (39 < count) count = 39;
835 if (copy_from_user (stkbuf, buf, count)) {
839 freq = simple_strtoul(stkbuf, &dest, 10);
840 if (*dest != '\0' && *dest != '\n') {
841 printk("ppc_rtas_tone_freq_write: Invalid tone freqency\n");
844 if (freq < 0) freq = 0;
845 rtas_tone_frequency = freq; /* save it for later */
846 error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
847 TONE_FREQUENCY, 0, freq);
849 printk(KERN_WARNING "error: setting tone frequency returned: %s\n",
850 ppc_rtas_process_error(error));
853 /* ****************************************************************** */
854 static ssize_t ppc_rtas_tone_freq_read(struct file * file, char * buf,
855 size_t count, loff_t *ppos)
858 char stkbuf[40]; /* its small, its on stack */
860 n = scnprintf(stkbuf, 40, "%lu\n", rtas_tone_frequency);
862 sn = strlen (stkbuf) +1;
869 if (copy_to_user (buf, stkbuf + (*ppos), n)) {
875 /* ****************************************************************** */
876 /* INDICATORS - Tone Volume */
877 /* ****************************************************************** */
878 static ssize_t ppc_rtas_tone_volume_write(struct file * file, const char * buf,
879 size_t count, loff_t *ppos)
881 char stkbuf[40]; /* its small, its on stack */
882 unsigned long volume;
886 if (39 < count) count = 39;
887 if (copy_from_user (stkbuf, buf, count)) {
891 volume = simple_strtoul(stkbuf, &dest, 10);
892 if (*dest != '\0' && *dest != '\n') {
893 printk("ppc_rtas_tone_volume_write: Invalid tone volume\n");
896 if (volume < 0) volume = 0;
897 if (volume > 100) volume = 100;
899 rtas_tone_volume = volume; /* save it for later */
900 error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
901 TONE_VOLUME, 0, volume);
903 printk(KERN_WARNING "error: setting tone volume returned: %s\n",
904 ppc_rtas_process_error(error));
907 /* ****************************************************************** */
908 static ssize_t ppc_rtas_tone_volume_read(struct file * file, char * buf,
909 size_t count, loff_t *ppos)
912 char stkbuf[40]; /* its small, its on stack */
914 n = scnprintf(stkbuf, 40, "%lu\n", rtas_tone_volume);
916 sn = strlen (stkbuf) +1;
923 if (copy_to_user (buf, stkbuf + (*ppos), n)) {
930 #define RMO_READ_BUF_MAX 30
932 /* RTAS Userspace access */
933 static ssize_t ppc_rtas_rmo_buf_read(struct file *file, char __user *buf,
934 size_t count, loff_t *ppos)
936 char kbuf[RMO_READ_BUF_MAX];
939 n = sprintf(kbuf, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX);
943 if (ppos && *ppos != 0)
946 if (copy_to_user(buf, kbuf, n))