forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-slow-down-manager-0.3-kernel-3.10-1.patch
205 lines (192 loc) · 6.53 KB
/
easy-slow-down-manager-0.3-kernel-3.10-1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
diff --git a/easy_slow_down_manager.c b/easy_slow_down_manager.c
index 7b2d1e9..1336557 100644
--- a/easy_slow_down_manager.c
+++ b/easy_slow_down_manager.c
@@ -4,6 +4,7 @@
#include <linux/proc_fs.h>
#include <linux/pci.h>
#include <linux/delay.h>
+#include <linux/version.h>
#include <asm/uaccess.h>
#include <linux/dmi.h>
@@ -101,7 +102,7 @@ MODULE_PARM_DESC(debug, "Verbose output");
int sabi_exec_command(u8 command, u8 data, struct sabi_retval *sretval)
{
int retval = 0;
-
+
mutex_lock(&sabi_mutex);
/* enable memory to be able to write to it */
@@ -141,22 +142,25 @@ int sabi_exec_command(u8 command, u8 data, struct sabi_retval *sretval)
return retval;
}
-int easy_slow_down_read(char *page, char **start, off_t off,
- int count, int *eof, void *data) {
+ssize_t easy_slow_down_read(struct file *filp, char __user *buffer,
+ size_t length, loff_t *off) {
struct sabi_retval sretval;
-
- if (off > 0) {
- *eof = 1;
- }
- else if (!sabi_exec_command(SABI_GET_ETIQUETTE_MODE, 0, &sretval)) {
- page[0] = sretval.retval[0] + '0';
+
+ if (*off > 0)
+ return 0;
+
+ if (!sabi_exec_command(SABI_GET_ETIQUETTE_MODE, 0, &sretval)) {
+ char mode = sretval.retval[0] + '0';
+ if (copy_to_user(buffer, &mode, 1))
+ return -EFAULT;
+ (*off)++;
return 1;
}
return 0;
}
-int easy_slow_down_write(struct file *file, const char __user *buffer,
- unsigned long count, void *data) {
+ssize_t easy_slow_down_write(struct file *filp, const char __user *buffer,
+ size_t count, loff_t *off) {
char mode = '0';
if (copy_from_user(&mode, buffer, 1)) {
return -EFAULT;
@@ -167,22 +171,25 @@ int easy_slow_down_write(struct file *file, const char __user *buffer,
return count;
}
-int easy_backlight_read(char *page, char **start, off_t off,
- int count, int *eof, void *data) {
+ssize_t easy_backlight_read(struct file *filp, char __user *buffer,
+ size_t length, loff_t *off) {
struct sabi_retval sretval;
-
- if (off > 0) {
- *eof = 1;
- }
- else if (!sabi_exec_command(SABI_GET_BACKLIGHT, 0, &sretval)) {
- page[0] = sretval.retval[0] + '0';
+
+ if (*off > 0)
+ return 0;
+
+ if (!sabi_exec_command(SABI_GET_BACKLIGHT, 0, &sretval)) {
+ char mode = sretval.retval[0] + '0';
+ if (copy_to_user(buffer, &mode, 1))
+ return -EFAULT;
+ (*off)++;
return 1;
}
return 0;
}
-int easy_backlight_write(struct file *file, const char __user *buffer,
- unsigned long count, void *data) {
+ssize_t easy_backlight_write(struct file *file, const char __user *buffer,
+ size_t count, loff_t *off) {
char mode = '0';
if (copy_from_user(&mode, buffer, 1)) {
return -EFAULT;
@@ -193,22 +200,25 @@ int easy_backlight_write(struct file *file, const char __user *buffer,
return count;
}
-int easy_wifi_kill_read(char *page, char **start, off_t off,
- int count, int *eof, void *data) {
+ssize_t easy_wifi_kill_read(struct file *filp, char __user *buffer,
+ size_t length, loff_t *off) {
struct sabi_retval sretval;
-
- if (off > 0) {
- *eof = 1;
- }
- else if (!sabi_exec_command(SABI_GET_WIRELESS_BUTTON, 0, &sretval)) {
- page[0] = sretval.retval[0] + '0';
+
+ if (*off > 0)
+ return 0;
+
+ if (!sabi_exec_command(SABI_GET_WIRELESS_BUTTON, 0, &sretval)) {
+ char mode = sretval.retval[0] + '0';
+ if (copy_to_user(buffer, &mode, 1))
+ return -EFAULT;
+ (*off)++;
return 1;
}
return 0;
}
-int easy_wifi_kill_write(struct file *file, const char __user *buffer,
- unsigned long count, void *data) {
+ssize_t easy_wifi_kill_write(struct file *file, const char __user *buffer,
+ size_t count, loff_t *off) {
char mode = '0';
if (copy_from_user(&mode, buffer, 1)) {
return -EFAULT;
@@ -219,8 +229,26 @@ int easy_wifi_kill_write(struct file *file, const char __user *buffer,
return count;
}
+static const struct file_operations proc_fops_slow_down = {
+ .owner = THIS_MODULE,
+ .read = easy_slow_down_read,
+ .write = easy_slow_down_write
+};
+
+static const struct file_operations proc_fops_wifi_kill = {
+ .owner = THIS_MODULE,
+ .read = easy_wifi_kill_read,
+ .write = easy_wifi_kill_write
+};
+
+static const struct file_operations proc_fops_backlight = {
+ .owner = THIS_MODULE,
+ .read = easy_backlight_read,
+ .write = easy_backlight_write
+};
+
int __init easy_slow_down_init(void) {
-
+
const char *test_str = "SwSmi@";
int pos;
int index = 0;
@@ -290,19 +318,15 @@ int __init easy_slow_down_init(void) {
}
- proc_entry_slow_down = create_proc_entry("easy_slow_down_manager", 0666, NULL);
+ proc_entry_slow_down = proc_create("easy_slow_down_manager", 0666, NULL, &proc_fops_slow_down);
if (proc_entry_slow_down == NULL) {
printk(KERN_INFO "Easy slow down manager: Couldn't create proc entry\n");
iounmap(sabi_iface);
iounmap(f0000_segment);
return -ENOMEM;
}
- else {
- proc_entry_slow_down->read_proc = easy_slow_down_read;
- proc_entry_slow_down->write_proc = easy_slow_down_write;
- }
- proc_entry_wifi_kill = create_proc_entry("easy_wifi_kill", 0666, NULL);
+ proc_entry_wifi_kill = proc_create("easy_wifi_kill", 0666, NULL, &proc_fops_wifi_kill);
if (proc_entry_wifi_kill == NULL) {
printk(KERN_INFO "Easy slow down manager: Couldn't create proc entry\n");
remove_proc_entry("easy_slow_down_manager", NULL);
@@ -310,12 +334,8 @@ int __init easy_slow_down_init(void) {
iounmap(f0000_segment);
return -ENOMEM;
}
- else {
- proc_entry_wifi_kill->read_proc = easy_wifi_kill_read;
- proc_entry_wifi_kill->write_proc = easy_wifi_kill_write;
- }
-
- proc_entry_backlight = create_proc_entry("easy_backlight", 0666, NULL);
+
+ proc_entry_backlight = proc_create("easy_backlight", 0666, NULL, &proc_fops_backlight);
if (proc_entry_backlight == NULL) {
printk(KERN_INFO "Easy slow down manager: Couldn't create proc entry\n");
remove_proc_entry("easy_slow_down_manager", NULL);
@@ -324,10 +344,6 @@ int __init easy_slow_down_init(void) {
iounmap(f0000_segment);
return -ENOMEM;
}
- else {
- proc_entry_backlight->read_proc = easy_backlight_read;
- proc_entry_backlight->write_proc = easy_backlight_write;
- }
return 0;
}