diff options
Diffstat (limited to 'drivers/pcmcia/socket_sysfs.c')
-rw-r--r-- | drivers/pcmcia/socket_sysfs.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 8eed03938214..fd5a3b0557b3 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c | |||
@@ -187,6 +187,102 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf, | |||
187 | static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); | 187 | static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); |
188 | 188 | ||
189 | 189 | ||
190 | static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) | ||
191 | { | ||
192 | tuple_t tuple; | ||
193 | int status, i; | ||
194 | loff_t pointer = 0; | ||
195 | ssize_t ret = 0; | ||
196 | u_char *tuplebuffer; | ||
197 | u_char *tempbuffer; | ||
198 | |||
199 | tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); | ||
200 | if (!tuplebuffer) | ||
201 | return -ENOMEM; | ||
202 | |||
203 | tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); | ||
204 | if (!tempbuffer) { | ||
205 | ret = -ENOMEM; | ||
206 | goto free_tuple; | ||
207 | } | ||
208 | |||
209 | memset(&tuple, 0, sizeof(tuple_t)); | ||
210 | |||
211 | tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; | ||
212 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; | ||
213 | tuple.TupleOffset = 0; | ||
214 | |||
215 | status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); | ||
216 | while (!status) { | ||
217 | tuple.TupleData = tuplebuffer; | ||
218 | tuple.TupleDataMax = 255; | ||
219 | memset(tuplebuffer, 0, sizeof(u_char) * 255); | ||
220 | |||
221 | status = pccard_get_tuple_data(s, &tuple); | ||
222 | if (status) | ||
223 | break; | ||
224 | |||
225 | if (off < (pointer + 2 + tuple.TupleDataLen)) { | ||
226 | tempbuffer[0] = tuple.TupleCode & 0xff; | ||
227 | tempbuffer[1] = tuple.TupleLink & 0xff; | ||
228 | for (i = 0; i < tuple.TupleDataLen; i++) | ||
229 | tempbuffer[i + 2] = tuplebuffer[i] & 0xff; | ||
230 | |||
231 | for (i = 0; i < (2 + tuple.TupleDataLen); i++) { | ||
232 | if (((i + pointer) >= off) && | ||
233 | (i + pointer) < (off + count)) { | ||
234 | buf[ret] = tempbuffer[i]; | ||
235 | ret++; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | pointer += 2 + tuple.TupleDataLen; | ||
241 | |||
242 | if (pointer >= (off + count)) | ||
243 | break; | ||
244 | |||
245 | if (tuple.TupleCode == CISTPL_END) | ||
246 | break; | ||
247 | status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); | ||
248 | } | ||
249 | |||
250 | kfree(tempbuffer); | ||
251 | free_tuple: | ||
252 | kfree(tuplebuffer); | ||
253 | |||
254 | return (ret); | ||
255 | } | ||
256 | |||
257 | static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count) | ||
258 | { | ||
259 | unsigned int size = 0x200; | ||
260 | |||
261 | if (off >= size) | ||
262 | count = 0; | ||
263 | else { | ||
264 | struct pcmcia_socket *s; | ||
265 | cisinfo_t cisinfo; | ||
266 | |||
267 | if (off + count > size) | ||
268 | count = size - off; | ||
269 | |||
270 | s = to_socket(container_of(kobj, struct class_device, kobj)); | ||
271 | |||
272 | if (!(s->state & SOCKET_PRESENT)) | ||
273 | return -ENODEV; | ||
274 | if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo)) | ||
275 | return -EIO; | ||
276 | if (!cisinfo.Chains) | ||
277 | return -ENODATA; | ||
278 | |||
279 | count = pccard_extract_cis(s, buf, off, count); | ||
280 | } | ||
281 | |||
282 | return (count); | ||
283 | } | ||
284 | |||
285 | |||
190 | static struct class_device_attribute *pccard_socket_attributes[] = { | 286 | static struct class_device_attribute *pccard_socket_attributes[] = { |
191 | &class_device_attr_card_type, | 287 | &class_device_attr_card_type, |
192 | &class_device_attr_card_voltage, | 288 | &class_device_attr_card_voltage, |
@@ -199,6 +295,12 @@ static struct class_device_attribute *pccard_socket_attributes[] = { | |||
199 | NULL, | 295 | NULL, |
200 | }; | 296 | }; |
201 | 297 | ||
298 | static struct bin_attribute pccard_cis_attr = { | ||
299 | .attr = { .name = "cis", .mode = S_IRUGO, .owner = THIS_MODULE}, | ||
300 | .size = 0x200, | ||
301 | .read = pccard_show_cis, | ||
302 | }; | ||
303 | |||
202 | static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) | 304 | static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) |
203 | { | 305 | { |
204 | struct class_device_attribute **attr; | 306 | struct class_device_attribute **attr; |
@@ -209,6 +311,8 @@ static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) | |||
209 | if (ret) | 311 | if (ret) |
210 | break; | 312 | break; |
211 | } | 313 | } |
314 | if (!ret) | ||
315 | ret = sysfs_create_bin_file(&class_dev->kobj, &pccard_cis_attr); | ||
212 | 316 | ||
213 | return ret; | 317 | return ret; |
214 | } | 318 | } |
@@ -217,6 +321,7 @@ static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev) | |||
217 | { | 321 | { |
218 | struct class_device_attribute **attr; | 322 | struct class_device_attribute **attr; |
219 | 323 | ||
324 | sysfs_remove_bin_file(&class_dev->kobj, &pccard_cis_attr); | ||
220 | for (attr = pccard_socket_attributes; *attr; attr++) | 325 | for (attr = pccard_socket_attributes; *attr; attr++) |
221 | class_device_remove_file(class_dev, *attr); | 326 | class_device_remove_file(class_dev, *attr); |
222 | } | 327 | } |