2 * linux/arch/i386/kernel/edd.c
3 * Copyright (C) 2002, 2003 Dell, Inc.
4 * by Matt Domsch <Matt_Domsch@dell.com>
5 * disk80 signature by Matt Domsch, Andrew Wilks, and Sandeep K. Shandilya
7 * BIOS Enhanced Disk Drive Services (EDD)
8 * conformant to T13 Committee www.t13.org
9 * projects 1572D, 1484D, 1386D, 1226DT
11 * This code takes information provided by BIOS EDD calls
12 * fn41 - Check Extensions Present and
13 * fn48 - Get Device Parametes with EDD extensions
14 * made in setup.S, copied to safe structures in setup.c,
15 * and presents it in /proc.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License v2.0 as published by
19 * the Free Software Foundation
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
30 * - move edd.[ch] to better locations if/when one is decided
33 #include <linux/module.h>
34 #include <linux/string.h>
35 #include <linux/types.h>
36 #include <linux/init.h>
37 #include <linux/stat.h>
38 #include <linux/ctype.h>
39 #include <linux/slab.h>
40 #include <linux/limits.h>
41 #include <linux/pci.h>
42 #include <linux/proc_fs.h>
45 MODULE_AUTHOR("Matt Domsch <Matt_Domsch@Dell.com>");
46 MODULE_DESCRIPTION("proc interface to BIOS EDD information");
47 MODULE_LICENSE("GPL");
49 #define EDD_VERSION "0.11 2004-Jun-21"
50 #define EDD_DEVICE_NAME_SIZE 16
52 #define left (count - (p - page) - 1)
54 static struct proc_dir_entry *bios_dir;
57 struct proc_dir_entry *entry;
58 struct list_head node;
62 char name[EDD_DEVICE_NAME_SIZE];
63 struct edd_info *info;
64 struct proc_dir_entry *dir;
65 struct list_head attr_list;
68 static struct edd_device *edd_devices[EDDMAXNR];
70 struct edd_attribute {
72 int (*show)(char *page, char **start, off_t off,
73 int count, int *eof, void *data);
74 int (*test) (struct edd_device * edev);
77 #define EDD_DEVICE_ATTR(_name,_show,_test) \
78 struct edd_attribute edd_attr_##_name = { \
79 .name = __stringify(_name), \
84 static inline struct edd_info *
85 edd_dev_get_info(struct edd_device *edev)
91 edd_dev_set_info(struct edd_device *edev, struct edd_info *info)
97 proc_calc_metrics(char *page, char **start, off_t off,
98 int count, int *eof, int len)
100 if (len <= off+count) *eof = 1;
103 if (len>count) len = count;
109 edd_dump_raw_data(char *b, int count, void *data, int length)
112 char hexbuf[80], ascbuf[20], *h, *a, c;
113 unsigned char *p = data;
114 unsigned long column = 0;
115 int length_printed = 0, d;
116 const char maxcolumn = 16;
117 while (length_printed < length && count > 0) {
121 column < maxcolumn && length_printed < length; column++) {
122 h += sprintf(h, "%02x ", (unsigned char) *p);
127 a += sprintf(a, "%c", c);
131 /* pad out the line */
132 for (; column < maxcolumn; column++) {
133 h += sprintf(h, " ");
134 a += sprintf(a, " ");
136 d = snprintf(b, count, "%s\t%s\n", hexbuf, ascbuf);
144 edd_show_host_bus(char *page, char **start, off_t off, int count, int *eof, void *data)
146 struct edd_info *info = data;
150 if (!info || !page || off) {
151 return proc_calc_metrics(page, start, off, count, eof, 0);
154 for (i = 0; i < 4; i++) {
155 if (isprint(info->params.host_bus_type[i])) {
156 p += snprintf(p, left, "%c", info->params.host_bus_type[i]);
158 p += snprintf(p, left, " ");
162 if (!strncmp(info->params.host_bus_type, "ISA", 3)) {
163 p += snprintf(p, left, "\tbase_address: %x\n",
164 info->params.interface_path.isa.base_address);
165 } else if (!strncmp(info->params.host_bus_type, "PCIX", 4) ||
166 !strncmp(info->params.host_bus_type, "PCI", 3)) {
167 p += snprintf(p, left,
168 "\t%02x:%02x.%d channel: %u\n",
169 info->params.interface_path.pci.bus,
170 info->params.interface_path.pci.slot,
171 info->params.interface_path.pci.function,
172 info->params.interface_path.pci.channel);
173 } else if (!strncmp(info->params.host_bus_type, "IBND", 4) ||
174 !strncmp(info->params.host_bus_type, "XPRS", 4) ||
175 !strncmp(info->params.host_bus_type, "HTPT", 4)) {
176 p += snprintf(p, left,
178 info->params.interface_path.ibnd.reserved);
181 p += snprintf(p, left, "\tunknown: %llx\n",
182 info->params.interface_path.unknown.reserved);
184 return proc_calc_metrics(page, start, off, count, eof, (p - page));
188 edd_show_interface(char *page, char **start, off_t off, int count, int *eof, void *data)
190 struct edd_info *info = data;
194 if (!info || !page || off) {
195 return proc_calc_metrics(page, start, off, count, eof, 0);
198 for (i = 0; i < 8; i++) {
199 if (isprint(info->params.interface_type[i])) {
200 p += snprintf(p, left, "%c", info->params.interface_type[i]);
202 p += snprintf(p, left, " ");
205 if (!strncmp(info->params.interface_type, "ATAPI", 5)) {
206 p += snprintf(p, left, "\tdevice: %u lun: %u\n",
207 info->params.device_path.atapi.device,
208 info->params.device_path.atapi.lun);
209 } else if (!strncmp(info->params.interface_type, "ATA", 3)) {
210 p += snprintf(p, left, "\tdevice: %u\n",
211 info->params.device_path.ata.device);
212 } else if (!strncmp(info->params.interface_type, "SCSI", 4)) {
213 p += snprintf(p, left, "\tid: %u lun: %llu\n",
214 info->params.device_path.scsi.id,
215 info->params.device_path.scsi.lun);
216 } else if (!strncmp(info->params.interface_type, "USB", 3)) {
217 p += snprintf(p, left, "\tserial_number: %llx\n",
218 info->params.device_path.usb.serial_number);
219 } else if (!strncmp(info->params.interface_type, "1394", 4)) {
220 p += snprintf(p, left, "\teui: %llx\n",
221 info->params.device_path.i1394.eui);
222 } else if (!strncmp(info->params.interface_type, "FIBRE", 5)) {
223 p += snprintf(p, left, "\twwid: %llx lun: %llx\n",
224 info->params.device_path.fibre.wwid,
225 info->params.device_path.fibre.lun);
226 } else if (!strncmp(info->params.interface_type, "I2O", 3)) {
227 p += snprintf(p, left, "\tidentity_tag: %llx\n",
228 info->params.device_path.i2o.identity_tag);
229 } else if (!strncmp(info->params.interface_type, "RAID", 4)) {
230 p += snprintf(p, left, "\tidentity_tag: %x\n",
231 info->params.device_path.raid.array_number);
232 } else if (!strncmp(info->params.interface_type, "SATA", 4)) {
233 p += snprintf(p, left, "\tdevice: %u\n",
234 info->params.device_path.sata.device);
236 p += snprintf(p, left, "\tunknown: %llx %llx\n",
237 info->params.device_path.unknown.reserved1,
238 info->params.device_path.unknown.reserved2);
241 return proc_calc_metrics(page, start, off, count, eof, (p - page));
245 * edd_show_raw_data() - unparses EDD information, returned to user-space
247 * Returns: number of bytes written, or 0 on failure
250 edd_show_raw_data(char *page, char **start, off_t off, int count, int *eof, void *data)
252 struct edd_info *info = data;
254 int i, warn_padding = 0, nonzero_path = 0,
255 len = sizeof (*info) - 4;
256 uint8_t checksum = 0, c = 0;
257 if (!info || !page || off) {
258 return proc_calc_metrics(page, start, off, count, eof, 0);
261 if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE))
262 len = info->params.length;
264 p += snprintf(p, left, "int13 fn48 returned data:\n\n");
265 p += edd_dump_raw_data(p, left, ((char *) info) + 4, len);
267 /* Spec violation. Adaptec AIC7899 returns 0xDDBE
268 here, when it should be 0xBEDD.
270 p += snprintf(p, left, "\n");
271 if (info->params.key == 0xDDBE) {
272 p += snprintf(p, left,
273 "Warning: Spec violation. Key should be 0xBEDD, is 0xDDBE\n");
276 if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE)) {
280 for (i = 30; i <= 73; i++) {
281 c = *(((uint8_t *) info) + i + 4);
288 p += snprintf(p, left,
289 "Warning: Spec violation. Device Path checksum invalid.\n");
293 p += snprintf(p, left, "Error: Spec violation. Empty device path.\n");
297 for (i = 0; i < 4; i++) {
298 if (!isprint(info->params.host_bus_type[i])) {
302 for (i = 0; i < 8; i++) {
303 if (!isprint(info->params.interface_type[i])) {
309 p += snprintf(p, left,
310 "Warning: Spec violation. Padding should be 0x20.\n");
314 return proc_calc_metrics(page, start, off, count, eof, (p - page));
318 edd_show_version(char *page, char **start, off_t off, int count, int *eof, void *data)
320 struct edd_info *info = data;
322 if (!info || !page || off) {
323 return proc_calc_metrics(page, start, off, count, eof, 0);
326 p += snprintf(p, left, "0x%02x\n", info->version);
327 return proc_calc_metrics(page, start, off, count, eof, (p - page));
331 edd_show_disk80_sig(char *page, char **start, off_t off, int count, int *eof, void *data)
335 return proc_calc_metrics(page, start, off, count, eof, 0);
338 p += snprintf(p, left, "0x%08x\n", edd_disk80_sig);
339 return proc_calc_metrics(page, start, off, count, eof, (p - page));
343 edd_show_extensions(char *page, char **start, off_t off, int count, int *eof, void *data)
345 struct edd_info *info = data;
347 if (!info || !page || off) {
348 return proc_calc_metrics(page, start, off, count, eof, 0);
351 if (info->interface_support & EDD_EXT_FIXED_DISK_ACCESS) {
352 p += snprintf(p, left, "Fixed disk access\n");
354 if (info->interface_support & EDD_EXT_DEVICE_LOCKING_AND_EJECTING) {
355 p += snprintf(p, left, "Device locking and ejecting\n");
357 if (info->interface_support & EDD_EXT_ENHANCED_DISK_DRIVE_SUPPORT) {
358 p += snprintf(p, left, "Enhanced Disk Drive support\n");
360 if (info->interface_support & EDD_EXT_64BIT_EXTENSIONS) {
361 p += snprintf(p, left, "64-bit extensions\n");
363 return proc_calc_metrics(page, start, off, count, eof, (p - page));
367 edd_show_info_flags(char *page, char **start, off_t off, int count, int *eof, void *data)
369 struct edd_info *info = data;
371 if (!info || !page || off) {
372 return proc_calc_metrics(page, start, off, count, eof, 0);
375 if (info->params.info_flags & EDD_INFO_DMA_BOUNDRY_ERROR_TRANSPARENT)
376 p += snprintf(p, left, "DMA boundry error transparent\n");
377 if (info->params.info_flags & EDD_INFO_GEOMETRY_VALID)
378 p += snprintf(p, left, "geometry valid\n");
379 if (info->params.info_flags & EDD_INFO_REMOVABLE)
380 p += snprintf(p, left, "removable\n");
381 if (info->params.info_flags & EDD_INFO_WRITE_VERIFY)
382 p += snprintf(p, left, "write verify\n");
383 if (info->params.info_flags & EDD_INFO_MEDIA_CHANGE_NOTIFICATION)
384 p += snprintf(p, left, "media change notification\n");
385 if (info->params.info_flags & EDD_INFO_LOCKABLE)
386 p += snprintf(p, left, "lockable\n");
387 if (info->params.info_flags & EDD_INFO_NO_MEDIA_PRESENT)
388 p += snprintf(p, left, "no media present\n");
389 if (info->params.info_flags & EDD_INFO_USE_INT13_FN50)
390 p += snprintf(p, left, "use int13 fn50\n");
391 return proc_calc_metrics(page, start, off, count, eof, (p - page));
395 edd_show_default_cylinders(char *page, char **start, off_t off, int count, int *eof, void *data)
397 struct edd_info *info = data;
399 if (!info || !page || off) {
400 return proc_calc_metrics(page, start, off, count, eof, 0);
403 p += snprintf(p, left, "%u\n", info->params.num_default_cylinders);
404 return proc_calc_metrics(page, start, off, count, eof, (p - page));
408 edd_show_default_heads(char *page, char **start, off_t off, int count, int *eof, void *data)
410 struct edd_info *info = data;
412 if (!info || !page || off) {
413 return proc_calc_metrics(page, start, off, count, eof, 0);
416 p += snprintf(p, left, "%u\n", info->params.num_default_heads);
417 return proc_calc_metrics(page, start, off, count, eof, (p - page));
421 edd_show_default_sectors_per_track(char *page, char **start, off_t off, int count, int *eof, void *data)
423 struct edd_info *info = data;
425 if (!info || !page || off) {
426 return proc_calc_metrics(page, start, off, count, eof, 0);
429 p += snprintf(p, left, "%u\n", info->params.sectors_per_track);
430 return proc_calc_metrics(page, start, off, count, eof, (p - page));
434 edd_show_sectors(char *page, char **start, off_t off, int count, int *eof, void *data)
436 struct edd_info *info = data;
438 if (!info || !page || off) {
439 return proc_calc_metrics(page, start, off, count, eof, 0);
442 p += snprintf(p, left, "%llu\n", info->params.number_of_sectors);
443 return proc_calc_metrics(page, start, off, count, eof, (p - page));
447 edd_has_default_cylinders(struct edd_device *edev)
449 struct edd_info *info = edd_dev_get_info(edev);
452 return info->params.num_default_cylinders > 0;
456 edd_has_default_heads(struct edd_device *edev)
458 struct edd_info *info = edd_dev_get_info(edev);
461 return info->params.num_default_heads > 0;
465 edd_has_default_sectors_per_track(struct edd_device *edev)
467 struct edd_info *info = edd_dev_get_info(edev);
470 return info->params.sectors_per_track > 0;
474 edd_has_edd30(struct edd_device *edev)
476 struct edd_info *info = edd_dev_get_info(edev);
477 int i, nonzero_path = 0;
483 if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE)) {
487 for (i = 30; i <= 73; i++) {
488 c = *(((uint8_t *) info) + i + 4);
502 edd_has_disk80_sig(struct edd_device *edev)
504 struct edd_info *info = edd_dev_get_info(edev);
507 return info->device == 0x80;
510 static EDD_DEVICE_ATTR(raw_data, edd_show_raw_data, NULL);
511 static EDD_DEVICE_ATTR(version, edd_show_version, NULL);
512 static EDD_DEVICE_ATTR(extensions, edd_show_extensions, NULL);
513 static EDD_DEVICE_ATTR(info_flags, edd_show_info_flags, NULL);
514 static EDD_DEVICE_ATTR(sectors, edd_show_sectors, NULL);
515 static EDD_DEVICE_ATTR(default_cylinders, edd_show_default_cylinders,
516 edd_has_default_cylinders);
517 static EDD_DEVICE_ATTR(default_heads, edd_show_default_heads,
518 edd_has_default_heads);
519 static EDD_DEVICE_ATTR(default_sectors_per_track,
520 edd_show_default_sectors_per_track,
521 edd_has_default_sectors_per_track);
522 static EDD_DEVICE_ATTR(interface, edd_show_interface,edd_has_edd30);
523 static EDD_DEVICE_ATTR(host_bus, edd_show_host_bus, edd_has_edd30);
524 static EDD_DEVICE_ATTR(mbr_signature, edd_show_disk80_sig, edd_has_disk80_sig);
526 static struct edd_attribute *def_attrs[] = {
529 &edd_attr_extensions,
530 &edd_attr_info_flags,
532 &edd_attr_default_cylinders,
533 &edd_attr_default_heads,
534 &edd_attr_default_sectors_per_track,
537 &edd_attr_mbr_signature,
542 edd_device_unregister(struct edd_device *edev)
544 struct list_head *pos, *next;
545 struct attr_entry *ae;
547 list_for_each_safe(pos, next, &edev->attr_list) {
548 ae = list_entry(pos, struct attr_entry, node);
549 remove_proc_entry(ae->entry->name, edev->dir);
554 remove_proc_entry(edev->dir->name, bios_dir);
558 edd_populate_dir(struct edd_device *edev)
560 struct edd_attribute *attr;
561 struct attr_entry *ae;
565 for (i = 0; (attr=def_attrs[i]); i++) {
566 if (!attr->test || (attr->test && attr->test(edev))) {
567 ae = kmalloc(sizeof (*ae), GFP_KERNEL);
572 INIT_LIST_HEAD(&ae->node);
574 create_proc_read_entry(attr->name, 0444,
575 edev->dir, attr->show,
576 edd_dev_get_info(edev));
577 if (ae->entry == NULL) {
581 list_add(&ae->node, &edev->attr_list);
592 edd_make_dir(struct edd_device *edev)
596 edev->dir = proc_mkdir(edev->name, bios_dir);
597 if (edev->dir != NULL) {
598 edev->dir->mode = (S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
599 error = edd_populate_dir(edev);
605 edd_device_register(struct edd_device *edev, int i)
611 memset(edev, 0, sizeof (*edev));
612 INIT_LIST_HEAD(&edev->attr_list);
613 edd_dev_set_info(edev, &edd[i]);
614 snprintf(edev->name, EDD_DEVICE_NAME_SIZE, "int13_dev%02x",
616 error = edd_make_dir(edev);
621 * edd_init() - creates /proc/bios tree of EDD data
623 * This assumes that eddnr and edd were
624 * assigned in setup.c already.
631 struct edd_device *edev;
633 printk(KERN_INFO "BIOS EDD facility v%s, %d devices found\n",
637 printk(KERN_INFO "EDD information not available.\n");
641 bios_dir = proc_mkdir("bios", NULL);
642 if (bios_dir == NULL)
645 for (i = 0; i < eddnr && i < EDDMAXNR && !rc; i++) {
646 edev = kmalloc(sizeof (*edev), GFP_KERNEL);
652 rc = edd_device_register(edev, i);
656 edd_devices[i] = edev;
660 for (i = 0; i < eddnr && i < EDDMAXNR; i++) {
661 if ((edev = edd_devices[i])) {
662 edd_device_unregister(edev);
667 remove_proc_entry(bios_dir->name, NULL);
677 struct edd_device *edev;
679 for (i = 0; i < eddnr && i < EDDMAXNR; i++) {
680 if ((edev = edd_devices[i])) {
681 edd_device_unregister(edev);
686 remove_proc_entry(bios_dir->name, NULL);
689 module_init(edd_init);
690 module_exit(edd_exit);