32 #include <linux/module.h>
33 #include <linux/string.h>
34 #include <linux/types.h>
36 #include <linux/stat.h>
38 #include <linux/ctype.h>
39 #include <linux/slab.h>
41 #include <linux/device.h>
42 #include <linux/pci.h>
44 #include <linux/edd.h>
46 #define EDD_VERSION "0.16"
47 #define EDD_DATE "2004-Jun-25"
54 #define left (PAGE_SIZE - (p - buf) - 1)
70 static int edd_dev_is_type(
struct edd_device *edev,
const char *
type);
75 #define EDD_DEVICE_ATTR(_name,_mode,_show,_test) \
76 struct edd_attribute edd_attr_##_name = { \
77 .attr = {.name = __stringify(_name), .mode = _mode }, \
104 if (edd_has_mbr_signature(edev))
106 if (edd_has_edd_info(edev))
110 #define to_edd_attr(_attr) container_of(_attr,struct edd_attribute,attr)
111 #define to_edd_device(obj) container_of(obj,struct edd_device,kobj)
121 ret = edd_attr->
show(dev, buf);
125 static const struct sysfs_ops edd_attr_ops = {
126 .show = edd_attr_show,
138 info = edd_dev_get_info(edev);
142 for (i = 0; i < 4; i++) {
152 info->
params.interface_path.isa.base_address);
153 }
else if (!
strncmp(info->
params.host_bus_type,
"PCIX", 4) ||
157 "\t%02x:%02x.%d channel: %u\n",
158 info->
params.interface_path.pci.bus,
159 info->
params.interface_path.pci.slot,
160 info->
params.interface_path.pci.function,
161 info->
params.interface_path.pci.channel);
162 }
else if (!
strncmp(info->
params.host_bus_type,
"IBND", 4) ||
166 info->
params.interface_path.ibnd.reserved);
170 info->
params.interface_path.unknown.reserved);
176 edd_show_interface(
struct edd_device *edev,
char *buf)
184 info = edd_dev_get_info(edev);
188 for (i = 0; i < 8; i++) {
197 info->
params.device_path.atapi.device,
198 info->
params.device_path.atapi.lun);
199 }
else if (!
strncmp(info->
params.interface_type,
"ATA", 3)) {
201 info->
params.device_path.ata.device);
202 }
else if (!
strncmp(info->
params.interface_type,
"SCSI", 4)) {
204 info->
params.device_path.scsi.id,
205 info->
params.device_path.scsi.lun);
206 }
else if (!
strncmp(info->
params.interface_type,
"USB", 3)) {
208 info->
params.device_path.usb.serial_number);
209 }
else if (!
strncmp(info->
params.interface_type,
"1394", 4)) {
211 info->
params.device_path.i1394.eui);
212 }
else if (!
strncmp(info->
params.interface_type,
"FIBRE", 5)) {
214 info->
params.device_path.fibre.wwid,
215 info->
params.device_path.fibre.lun);
216 }
else if (!
strncmp(info->
params.interface_type,
"I2O", 3)) {
218 info->
params.device_path.i2o.identity_tag);
219 }
else if (!
strncmp(info->
params.interface_type,
"RAID", 4)) {
221 info->
params.device_path.raid.array_number);
222 }
else if (!
strncmp(info->
params.interface_type,
"SATA", 4)) {
224 info->
params.device_path.sata.device);
227 info->
params.device_path.unknown.reserved1,
228 info->
params.device_path.unknown.reserved2);
242 edd_show_raw_data(
struct edd_device *edev,
char *buf)
248 info = edd_dev_get_info(edev);
252 if (!(info->
params.key == 0xBEDD || info->
params.key == 0xDDBE))
253 len = info->
params.length;
256 if (len > (
sizeof(info->
params)))
257 len =
sizeof(info->
params);
264 edd_show_version(
struct edd_device *edev,
char *buf)
270 info = edd_dev_get_info(edev);
279 edd_show_mbr_signature(
struct edd_device *edev,
char *buf)
287 edd_show_extensions(
struct edd_device *edev,
char *buf)
293 info = edd_dev_get_info(edev);
313 edd_show_info_flags(
struct edd_device *edev,
char *buf)
319 info = edd_dev_get_info(edev);
343 edd_show_legacy_max_cylinder(
struct edd_device *edev,
char *buf)
349 info = edd_dev_get_info(edev);
358 edd_show_legacy_max_head(
struct edd_device *edev,
char *buf)
364 info = edd_dev_get_info(edev);
373 edd_show_legacy_sectors_per_track(
struct edd_device *edev,
char *buf)
379 info = edd_dev_get_info(edev);
388 edd_show_default_cylinders(
struct edd_device *edev,
char *buf)
394 info = edd_dev_get_info(edev);
403 edd_show_default_heads(
struct edd_device *edev,
char *buf)
409 info = edd_dev_get_info(edev);
418 edd_show_default_sectors_per_track(
struct edd_device *edev,
char *buf)
424 info = edd_dev_get_info(edev);
433 edd_show_sectors(
struct edd_device *edev,
char *buf)
439 info = edd_dev_get_info(edev);
459 edd_has_legacy_max_cylinder(
struct edd_device *edev)
464 info = edd_dev_get_info(edev);
471 edd_has_legacy_max_head(
struct edd_device *edev)
476 info = edd_dev_get_info(edev);
483 edd_has_legacy_sectors_per_track(
struct edd_device *edev)
488 info = edd_dev_get_info(edev);
495 edd_has_default_cylinders(
struct edd_device *edev)
500 info = edd_dev_get_info(edev);
503 return info->
params.num_default_cylinders > 0;
507 edd_has_default_heads(
struct edd_device *edev)
512 info = edd_dev_get_info(edev);
515 return info->
params.num_default_heads > 0;
519 edd_has_default_sectors_per_track(
struct edd_device *edev)
524 info = edd_dev_get_info(edev);
527 return info->
params.sectors_per_track > 0;
539 info = edd_dev_get_info(edev);
543 if (!(info->
params.key == 0xBEDD || info->
params.key == 0xDDBE)) {
549 if (info->
params.device_path_info_length != 44)
552 for (i = 30; i < info->
params.device_path_info_length + 30; i++)
553 csum += *(((
u8 *)&info->
params) + i);
562 static EDD_DEVICE_ATTR(raw_data, 0444, edd_show_raw_data, edd_has_edd_info);
568 edd_show_legacy_max_cylinder,
569 edd_has_legacy_max_cylinder);
571 edd_has_legacy_max_head);
573 edd_show_legacy_sectors_per_track,
574 edd_has_legacy_sectors_per_track);
575 static EDD_DEVICE_ATTR(default_cylinders, 0444, edd_show_default_cylinders,
576 edd_has_default_cylinders);
578 edd_has_default_heads);
580 edd_show_default_sectors_per_track,
581 edd_has_default_sectors_per_track);
583 static EDD_DEVICE_ATTR(host_bus, 0444, edd_show_host_bus, edd_has_edd30);
584 static EDD_DEVICE_ATTR(mbr_signature, 0444, edd_show_mbr_signature, edd_has_mbr_signature);
590 static struct attribute * def_attrs[] = {
598 &edd_attr_extensions,
599 &edd_attr_info_flags,
601 &edd_attr_legacy_max_cylinder,
602 &edd_attr_legacy_max_head,
603 &edd_attr_legacy_sectors_per_track,
604 &edd_attr_default_cylinders,
605 &edd_attr_default_heads,
606 &edd_attr_default_sectors_per_track,
609 &edd_attr_mbr_signature,
622 static void edd_release(
struct kobject * kobj)
629 .release = edd_release,
630 .sysfs_ops = &edd_attr_ops,
631 .default_attrs = def_attrs,
634 static struct kset *edd_kset;
650 info = edd_dev_get_info(edev);
669 struct edd_info *info = edd_dev_get_info(edev);
671 if (edd_dev_is_type(edev,
"PCI") || edd_dev_is_type(edev,
"XPRS")) {
674 info->
params.interface_path.pci.
681 edd_create_symlink_to_pcidev(
struct edd_device *edev)
694 edd_device_unregister(
struct edd_device *edev)
699 static void edd_populate_dir(
struct edd_device * edev)
705 for (i = 0; (attr = edd_attrs[
i]) && !error; i++) {
712 edd_create_symlink_to_pcidev(edev);
717 edd_device_register(
struct edd_device *edev,
int i)
723 edd_dev_set_info(edev, i);
724 edev->
kobj.kset = edd_kset;
726 "int13_dev%02x", 0x80 + i);
728 edd_populate_dir(edev);
734 static inline int edd_num_devices(
void)
736 return max_t(
unsigned char,
754 if (!edd_num_devices()) {
763 for (i = 0; i < edd_num_devices(); i++) {
770 rc = edd_device_register(edev, i);
775 edd_devices[
i] = edev;
782 edd_device_unregister(edd_devices[i]);
793 for (i = 0; i < edd_num_devices(); i++) {
794 if ((edev = edd_devices[i]))
795 edd_device_unregister(edev);