^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/drivers/firmware/edd.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2002, 2003, 2004 Dell Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * by Matt Domsch <Matt_Domsch@dell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * disk signature by Matt Domsch, Andrew Wilks, and Sandeep K. Shandilya
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * legacy CHS by Patrick J. LoPresti <patl@users.sourceforge.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * BIOS Enhanced Disk Drive Services (EDD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * conformant to T13 Committee www.t13.org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * projects 1572D, 1484D, 1386D, 1226DT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This code takes information provided by BIOS EDD calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * fn41 - Check Extensions Present and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * fn48 - Get Device Parameters with EDD extensions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * made in setup.S, copied to safe structures in setup.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * and presents it in sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Please see http://linux.dell.com/edd/results.html for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * the list of BIOSs which have been reported to implement EDD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/edd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define EDD_VERSION "0.16"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define EDD_DATE "2004-Jun-25"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) MODULE_AUTHOR("Matt Domsch <Matt_Domsch@Dell.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_DESCRIPTION("sysfs interface to BIOS EDD information");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MODULE_VERSION(EDD_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define left (PAGE_SIZE - (p - buf) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct edd_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int mbr_signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct kobject kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct edd_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ssize_t(*show) (struct edd_device * edev, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int (*test) (struct edd_device * edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* forward declarations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int edd_dev_is_type(struct edd_device *edev, const char *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct pci_dev *edd_get_pci_dev(struct edd_device *edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static struct edd_device *edd_devices[EDD_MBR_SIG_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define EDD_DEVICE_ATTR(_name,_mode,_show,_test) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct edd_attribute edd_attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .attr = {.name = __stringify(_name), .mode = _mode }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .show = _show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .test = _test, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) edd_has_mbr_signature(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return edev->index < min_t(unsigned char, edd.mbr_signature_nr, EDD_MBR_SIG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) edd_has_edd_info(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return edev->index < min_t(unsigned char, edd.edd_info_nr, EDDMAXNR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static inline struct edd_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) edd_dev_get_info(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return edev->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) edd_dev_set_info(struct edd_device *edev, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) edev->index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (edd_has_mbr_signature(edev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) edev->mbr_signature = edd.mbr_signature[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (edd_has_edd_info(edev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) edev->info = &edd.edd_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define to_edd_attr(_attr) container_of(_attr,struct edd_attribute,attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define to_edd_device(obj) container_of(obj,struct edd_device,kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct edd_device *dev = to_edd_device(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct edd_attribute *edd_attr = to_edd_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ssize_t ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (edd_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ret = edd_attr->show(dev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static const struct sysfs_ops edd_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .show = edd_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) edd_show_host_bus(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (isprint(info->params.host_bus_type[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) p += scnprintf(p, left, "%c", info->params.host_bus_type[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) p += scnprintf(p, left, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!strncmp(info->params.host_bus_type, "ISA", 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) p += scnprintf(p, left, "\tbase_address: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) info->params.interface_path.isa.base_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) } else if (!strncmp(info->params.host_bus_type, "PCIX", 4) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) !strncmp(info->params.host_bus_type, "PCI", 3) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) !strncmp(info->params.host_bus_type, "XPRS", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) p += scnprintf(p, left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "\t%02x:%02x.%d channel: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) info->params.interface_path.pci.bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) info->params.interface_path.pci.slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) info->params.interface_path.pci.function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) info->params.interface_path.pci.channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) } else if (!strncmp(info->params.host_bus_type, "IBND", 4) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) !strncmp(info->params.host_bus_type, "HTPT", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) p += scnprintf(p, left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) "\tTBD: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) info->params.interface_path.ibnd.reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) p += scnprintf(p, left, "\tunknown: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) info->params.interface_path.unknown.reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) edd_show_interface(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (isprint(info->params.interface_type[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) p += scnprintf(p, left, "%c", info->params.interface_type[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) p += scnprintf(p, left, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!strncmp(info->params.interface_type, "ATAPI", 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) p += scnprintf(p, left, "\tdevice: %u lun: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) info->params.device_path.atapi.device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) info->params.device_path.atapi.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } else if (!strncmp(info->params.interface_type, "ATA", 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) p += scnprintf(p, left, "\tdevice: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) info->params.device_path.ata.device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) } else if (!strncmp(info->params.interface_type, "SCSI", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) p += scnprintf(p, left, "\tid: %u lun: %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) info->params.device_path.scsi.id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) info->params.device_path.scsi.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else if (!strncmp(info->params.interface_type, "USB", 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) p += scnprintf(p, left, "\tserial_number: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) info->params.device_path.usb.serial_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) } else if (!strncmp(info->params.interface_type, "1394", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) p += scnprintf(p, left, "\teui: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) info->params.device_path.i1394.eui);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) } else if (!strncmp(info->params.interface_type, "FIBRE", 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) p += scnprintf(p, left, "\twwid: %llx lun: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) info->params.device_path.fibre.wwid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) info->params.device_path.fibre.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) } else if (!strncmp(info->params.interface_type, "I2O", 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) p += scnprintf(p, left, "\tidentity_tag: %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) info->params.device_path.i2o.identity_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) } else if (!strncmp(info->params.interface_type, "RAID", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) p += scnprintf(p, left, "\tidentity_tag: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) info->params.device_path.raid.array_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) } else if (!strncmp(info->params.interface_type, "SATA", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) p += scnprintf(p, left, "\tdevice: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) info->params.device_path.sata.device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) p += scnprintf(p, left, "\tunknown: %llx %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) info->params.device_path.unknown.reserved1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) info->params.device_path.unknown.reserved2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * edd_show_raw_data() - copies raw data to buffer for userspace to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @edev: target edd_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * @buf: output buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Returns: number of bytes written, or -EINVAL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) edd_show_raw_data(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ssize_t len = sizeof (info->params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) len = info->params.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* In case of buggy BIOSs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (len > (sizeof(info->params)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) len = sizeof(info->params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) memcpy(buf, &info->params, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) edd_show_version(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) p += scnprintf(p, left, "0x%02x\n", info->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) edd_show_mbr_signature(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) p += scnprintf(p, left, "0x%08x\n", edev->mbr_signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) edd_show_extensions(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (info->interface_support & EDD_EXT_FIXED_DISK_ACCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) p += scnprintf(p, left, "Fixed disk access\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (info->interface_support & EDD_EXT_DEVICE_LOCKING_AND_EJECTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) p += scnprintf(p, left, "Device locking and ejecting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (info->interface_support & EDD_EXT_ENHANCED_DISK_DRIVE_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) p += scnprintf(p, left, "Enhanced Disk Drive support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (info->interface_support & EDD_EXT_64BIT_EXTENSIONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) p += scnprintf(p, left, "64-bit extensions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) edd_show_info_flags(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (info->params.info_flags & EDD_INFO_DMA_BOUNDARY_ERROR_TRANSPARENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) p += scnprintf(p, left, "DMA boundary error transparent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (info->params.info_flags & EDD_INFO_GEOMETRY_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) p += scnprintf(p, left, "geometry valid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (info->params.info_flags & EDD_INFO_REMOVABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) p += scnprintf(p, left, "removable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (info->params.info_flags & EDD_INFO_WRITE_VERIFY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) p += scnprintf(p, left, "write verify\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (info->params.info_flags & EDD_INFO_MEDIA_CHANGE_NOTIFICATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) p += scnprintf(p, left, "media change notification\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (info->params.info_flags & EDD_INFO_LOCKABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) p += scnprintf(p, left, "lockable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (info->params.info_flags & EDD_INFO_NO_MEDIA_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) p += scnprintf(p, left, "no media present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (info->params.info_flags & EDD_INFO_USE_INT13_FN50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) p += scnprintf(p, left, "use int13 fn50\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) edd_show_legacy_max_cylinder(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) p += scnprintf(p, left, "%u\n", info->legacy_max_cylinder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) edd_show_legacy_max_head(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) p += scnprintf(p, left, "%u\n", info->legacy_max_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) edd_show_legacy_sectors_per_track(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) p += scnprintf(p, left, "%u\n", info->legacy_sectors_per_track);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) edd_show_default_cylinders(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) p += scnprintf(p, left, "%u\n", info->params.num_default_cylinders);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) edd_show_default_heads(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) p += scnprintf(p, left, "%u\n", info->params.num_default_heads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) edd_show_default_sectors_per_track(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) p += scnprintf(p, left, "%u\n", info->params.sectors_per_track);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) edd_show_sectors(struct edd_device *edev, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (!info || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) p += scnprintf(p, left, "%llu\n", info->params.number_of_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return (p - buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * Some device instances may not have all the above attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * or the attribute values may be meaningless (i.e. if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * the device is < EDD 3.0, it won't have host_bus and interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * information), so don't bother making files for them. Likewise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * if the default_{cylinders,heads,sectors_per_track} values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * are zero, the BIOS doesn't provide sane values, don't bother
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * creating files for them either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) edd_has_legacy_max_cylinder(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return info->legacy_max_cylinder > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) edd_has_legacy_max_head(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return info->legacy_max_head > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) edd_has_legacy_sectors_per_track(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return info->legacy_sectors_per_track > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) edd_has_default_cylinders(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return info->params.num_default_cylinders > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) edd_has_default_heads(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return info->params.num_default_heads > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) edd_has_default_sectors_per_track(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return info->params.sectors_per_track > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) edd_has_edd30(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) u8 csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* We support only T13 spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (info->params.device_path_info_length != 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) for (i = 30; i < info->params.device_path_info_length + 30; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) csum += *(((u8 *)&info->params) + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static EDD_DEVICE_ATTR(raw_data, 0444, edd_show_raw_data, edd_has_edd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static EDD_DEVICE_ATTR(version, 0444, edd_show_version, edd_has_edd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static EDD_DEVICE_ATTR(extensions, 0444, edd_show_extensions, edd_has_edd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static EDD_DEVICE_ATTR(info_flags, 0444, edd_show_info_flags, edd_has_edd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static EDD_DEVICE_ATTR(sectors, 0444, edd_show_sectors, edd_has_edd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static EDD_DEVICE_ATTR(legacy_max_cylinder, 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) edd_show_legacy_max_cylinder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) edd_has_legacy_max_cylinder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static EDD_DEVICE_ATTR(legacy_max_head, 0444, edd_show_legacy_max_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) edd_has_legacy_max_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static EDD_DEVICE_ATTR(legacy_sectors_per_track, 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) edd_show_legacy_sectors_per_track,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) edd_has_legacy_sectors_per_track);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static EDD_DEVICE_ATTR(default_cylinders, 0444, edd_show_default_cylinders,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) edd_has_default_cylinders);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static EDD_DEVICE_ATTR(default_heads, 0444, edd_show_default_heads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) edd_has_default_heads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static EDD_DEVICE_ATTR(default_sectors_per_track, 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) edd_show_default_sectors_per_track,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) edd_has_default_sectors_per_track);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static EDD_DEVICE_ATTR(interface, 0444, edd_show_interface, edd_has_edd30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static EDD_DEVICE_ATTR(host_bus, 0444, edd_show_host_bus, edd_has_edd30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static EDD_DEVICE_ATTR(mbr_signature, 0444, edd_show_mbr_signature, edd_has_mbr_signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* These are default attributes that are added for every edd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * device discovered. There are none.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static struct attribute * def_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* These attributes are conditional and only added for some devices. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static struct edd_attribute * edd_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) &edd_attr_raw_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) &edd_attr_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) &edd_attr_extensions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) &edd_attr_info_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) &edd_attr_sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) &edd_attr_legacy_max_cylinder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) &edd_attr_legacy_max_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) &edd_attr_legacy_sectors_per_track,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) &edd_attr_default_cylinders,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) &edd_attr_default_heads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) &edd_attr_default_sectors_per_track,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) &edd_attr_interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) &edd_attr_host_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) &edd_attr_mbr_signature,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * edd_release - free edd structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) * @kobj: kobject of edd structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * This is called when the refcount of the edd structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * reaches 0. This should happen right after we unregister,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * but just in case, we use the release callback anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static void edd_release(struct kobject * kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct edd_device * dev = to_edd_device(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static struct kobj_type edd_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) .release = edd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) .sysfs_ops = &edd_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .default_attrs = def_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static struct kset *edd_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * edd_dev_is_type() - is this EDD device a 'type' device?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * @edev: target edd_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * @type: a host bus or interface identifier string per the EDD spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * Returns 1 (TRUE) if it is a 'type' device, 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) edd_dev_is_type(struct edd_device *edev, const char *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct edd_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (type && info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!strncmp(info->params.host_bus_type, type, strlen(type)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) !strncmp(info->params.interface_type, type, strlen(type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * edd_get_pci_dev() - finds pci_dev that matches edev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * @edev: edd_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * Returns pci_dev if found, or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static struct pci_dev *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) edd_get_pci_dev(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct edd_info *info = edd_dev_get_info(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (edd_dev_is_type(edev, "PCI") || edd_dev_is_type(edev, "XPRS")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return pci_get_domain_bus_and_slot(0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) info->params.interface_path.pci.bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) PCI_DEVFN(info->params.interface_path.pci.slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) info->params.interface_path.pci.function));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) edd_create_symlink_to_pcidev(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct pci_dev *pci_dev = edd_get_pci_dev(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (!pci_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) ret = sysfs_create_link(&edev->kobj,&pci_dev->dev.kobj,"pci_dev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) pci_dev_put(pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) edd_device_unregister(struct edd_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) kobject_put(&edev->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) static void edd_populate_dir(struct edd_device * edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct edd_attribute * attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) for (i = 0; (attr = edd_attrs[i]) && !error; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (!attr->test ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) (attr->test && attr->test(edev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) error = sysfs_create_file(&edev->kobj,&attr->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) edd_create_symlink_to_pcidev(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) edd_device_register(struct edd_device *edev, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) edd_dev_set_info(edev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) edev->kobj.kset = edd_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) error = kobject_init_and_add(&edev->kobj, &edd_ktype, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) "int13_dev%02x", 0x80 + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) edd_populate_dir(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) kobject_uevent(&edev->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static inline int edd_num_devices(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) return max_t(unsigned char,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) min_t(unsigned char, EDD_MBR_SIG_MAX, edd.mbr_signature_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) min_t(unsigned char, EDDMAXNR, edd.edd_info_nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * edd_init() - creates sysfs tree of EDD data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) edd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) int rc=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct edd_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (!edd_num_devices())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) printk(KERN_INFO "BIOS EDD facility v%s %s, %d devices found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) EDD_VERSION, EDD_DATE, edd_num_devices());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) edd_kset = kset_create_and_add("edd", NULL, firmware_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (!edd_kset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) for (i = 0; i < edd_num_devices(); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) edev = kzalloc(sizeof (*edev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (!edev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) rc = edd_device_register(edev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) kfree(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) edd_devices[i] = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) edd_device_unregister(edd_devices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) kset_unregister(edd_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) edd_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct edd_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) for (i = 0; i < edd_num_devices(); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if ((edev = edd_devices[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) edd_device_unregister(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) kset_unregister(edd_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) late_initcall(edd_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) module_exit(edd_exit);