From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org,
Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Subject: [PATCH 10/18] ide: add warm-plug support for IDE devices
Date: Fri, 08 Feb 2008 01:45:30 +0100 [thread overview]
Message-ID: <20080208004530.17746.11984.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20080208004421.17746.32557.sendpatchset@localhost.localdomain>
* Add 'struct class ide_port_class' ('ide_port' class) and embedd 'struct
class_device classdev' ('ide_port' class device) in ide_hwif_t.
* Register 'ide_port' class in ide_init() and unregister it in
cleanup_module().
* Add class_to_ide_port() macro and ide_port_class_release().
* Register ->classdev in ide_register_port () and unregister it in
ide_unregister().
* Add "delete_devices" class device attribute for unregistering IDE devices
on a port and "scan" one for probing+registering IDE devices on a port.
* Add ide_sysfs_register_port() helper for registering "delete_devices"
and "scan" attributes with ->classdev. Call it in ide_device_add_all().
* Document IDE warm-plug support in Documentation/ide/warm-plug-howto.txt.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
+540 bytes (x86-32)
After seeing some 'class device' conversion patches from Greg I tried to
recast this patch to just use 'device' but I couldn't figure out how to
use class_device_create() with *static* objects...
Documentation/ide/warm-plug-howto.txt | 13 ++++++
drivers/ide/ide-probe.c | 70 +++++++++++++++++++++++++++++++++-
drivers/ide/ide.c | 22 ++++++++++
include/linux/ide.h | 7 ++-
4 files changed, 109 insertions(+), 3 deletions(-)
Index: b/Documentation/ide/warm-plug-howto.txt
===================================================================
--- /dev/null
+++ b/Documentation/ide/warm-plug-howto.txt
@@ -0,0 +1,13 @@
+
+IDE warm-plug HOWTO
+===================
+
+To warm-plug devices on a port 'idex':
+
+# echo -n "1" > /sys/class/ide_port/idex/delete_devices
+
+unplug old device(s) and plug new device(s)
+
+# echo -n "1" > /sys/class/ide_port/idex/scan
+
+done
Index: b/drivers/ide/ide-probe.c
===================================================================
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -623,7 +623,7 @@ static void hwif_release_dev (struct dev
complete(&hwif->gendev_rel_comp);
}
-static void ide_register_port(ide_hwif_t *hwif)
+static int ide_register_port(ide_hwif_t *hwif)
{
int ret;
@@ -639,9 +639,23 @@ static void ide_register_port(ide_hwif_t
}
hwif->gendev.release = hwif_release_dev;
ret = device_register(&hwif->gendev);
- if (ret < 0)
+ if (ret < 0) {
printk(KERN_WARNING "IDE: %s: device_register error: %d\n",
__FUNCTION__, ret);
+ goto out;
+ }
+
+ get_device(&hwif->gendev);
+
+ strlcpy(hwif->classdev.class_id, hwif->name, BUS_ID_SIZE);
+ hwif->classdev.dev = &hwif->gendev;
+ hwif->classdev.class = &ide_port_class;
+
+ ret = class_device_register(&hwif->classdev);
+ if (ret < 0)
+ device_unregister(&hwif->gendev);
+out:
+ return ret;
}
/**
@@ -1374,6 +1388,57 @@ static void ide_port_cable_detect(ide_hw
}
}
+static ssize_t store_delete_devices(struct class_device *class_dev,
+ const char *buf, size_t n)
+{
+ ide_hwif_t *hwif = class_to_ide_port(class_dev);
+
+ if (strncmp(buf, "1", n))
+ return -EINVAL;
+
+ ide_port_unregister_devices(hwif);
+
+ return n;
+};
+
+static CLASS_DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
+
+static ssize_t store_scan(struct class_device *class_dev, const char *buf,
+ size_t n)
+{
+ ide_hwif_t *hwif = class_to_ide_port(class_dev);
+
+ if (strncmp(buf, "1", n))
+ return -EINVAL;
+
+ ide_port_unregister_devices(hwif);
+ ide_port_scan(hwif);
+
+ return n;
+};
+
+static CLASS_DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
+
+static struct class_device_attribute *ide_port_attrs[] = {
+ &class_device_attr_delete_devices,
+ &class_device_attr_scan,
+ NULL
+};
+
+static int ide_sysfs_register_port(ide_hwif_t *hwif)
+{
+ int i, rc;
+
+ for (i = 0; ide_port_attrs[i]; i++) {
+ rc = class_device_create_file(&hwif->classdev,
+ ide_port_attrs[i]);
+ if (rc)
+ break;
+ }
+
+ return rc;
+}
+
int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
{
ide_hwif_t *hwif, *mate = NULL;
@@ -1470,6 +1535,7 @@ int ide_device_add_all(u8 *idx, const st
hwif = &ide_hwifs[idx[i]];
if (hwif->present) {
+ ide_sysfs_register_port(hwif);
ide_proc_register_port(hwif);
ide_proc_port_register_devices(hwif);
}
Index: b/drivers/ide/ide.c
===================================================================
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -596,6 +596,7 @@ void ide_unregister(unsigned int index,
ide_remove_port_from_hwgroup(hwif);
+ class_device_unregister(&hwif->classdev);
device_unregister(&hwif->gendev);
wait_for_completion(&hwif->gendev_rel_comp);
@@ -1613,6 +1614,16 @@ struct bus_type ide_bus_type = {
EXPORT_SYMBOL_GPL(ide_bus_type);
+static void ide_port_class_release(struct class_device *class_dev)
+{
+ put_device(&class_to_ide_port(class_dev)->gendev);
+}
+
+struct class ide_port_class = {
+ .name = "ide_port",
+ .release = ide_port_class_release,
+};
+
/*
* This is gets invoked once during initialization, to set *everything* up
*/
@@ -1633,11 +1644,20 @@ static int __init ide_init(void)
return ret;
}
+ ret = class_register(&ide_port_class);
+ if (ret)
+ goto out_port_class;
+
init_ide_data();
proc_ide_create();
return 0;
+
+out_port_class:
+ bus_unregister(&ide_bus_type);
+
+ return ret;
}
#ifdef MODULE
@@ -1674,6 +1694,8 @@ void __exit cleanup_module (void)
proc_ide_destroy();
+ class_unregister(&ide_port_class);
+
bus_unregister(&ide_bus_type);
}
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -581,7 +581,9 @@ typedef struct hwif_s {
unsigned mmio : 1; /* host uses MMIO */
unsigned straight8 : 1; /* Alan's straight 8 check */
- struct device gendev;
+ struct device gendev;
+ struct class_device classdev;
+
struct completion gendev_rel_comp; /* To deal with device release() */
void *hwif_data; /* extra hwif data */
@@ -593,6 +595,8 @@ typedef struct hwif_s {
#endif
} ____cacheline_internodealigned_in_smp ide_hwif_t;
+#define class_to_ide_port(dev) container_of(dev, ide_hwif_t, classdev)
+
/*
* internal ide interrupt handler type
*/
@@ -1275,6 +1279,7 @@ extern struct mutex ide_cfg_mtx;
#define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0)
extern struct bus_type ide_bus_type;
+extern struct class ide_port_class;
/* check if CACHE FLUSH (EXT) command is supported (bits defined in ATA-6) */
#define ide_id_has_flush_cache(id) ((id)->cfs_enable_2 & 0x3000)
next prev parent reply other threads:[~2008-02-08 0:31 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-08 0:44 [PATCH 00/18] ide: warm-plug support for IDE devices and other goodies Bartlomiej Zolnierkiewicz
2008-02-08 0:44 ` [PATCH 01/18] ide-generic: set hwif->chipset Bartlomiej Zolnierkiewicz
2008-02-08 0:44 ` [PATCH 02/18] ide: fix ide_find_port() Bartlomiej Zolnierkiewicz
2008-02-08 17:23 ` Sergei Shtylyov
2008-02-08 0:44 ` [PATCH 03/18] ide: use ide_find_port() instead of ide_deprecated_find_port() Bartlomiej Zolnierkiewicz
2008-02-08 0:44 ` [PATCH 04/18] ide-acpi: add missing drive->acpidata zeroing Bartlomiej Zolnierkiewicz
2008-02-08 0:44 ` [PATCH 05/18] ide: factor out cable detection from ide_init_port() Bartlomiej Zolnierkiewicz
2008-02-08 17:18 ` Sergei Shtylyov
2008-02-08 0:45 ` [PATCH 06/18] ide: factor out code unregistering devices from ide_unregister() Bartlomiej Zolnierkiewicz
2008-02-09 18:07 ` Sergei Shtylyov
2008-02-08 0:45 ` [PATCH 07/18] ide: factor out devices init from ide_init_port_data() Bartlomiej Zolnierkiewicz
2008-02-09 18:10 ` Sergei Shtylyov
2008-02-08 0:45 ` [PATCH 08/18] ide: move ide_port_setup_devices() call to ide_device_add_all() Bartlomiej Zolnierkiewicz
2008-02-08 17:20 ` Sergei Shtylyov
2008-02-08 0:45 ` [PATCH 09/18] ide: rework PowerMac media-bay support Bartlomiej Zolnierkiewicz
2008-02-13 7:29 ` Michael Ellerman
2008-02-13 12:26 ` Bartlomiej Zolnierkiewicz
2008-02-08 0:45 ` Bartlomiej Zolnierkiewicz [this message]
2008-02-08 0:45 ` [PATCH 11/18] ide-generic: add ide_generic class and attribute for adding new interfaces Bartlomiej Zolnierkiewicz
2008-02-08 0:45 ` [PATCH 12/18] ide: remove needless CONFIG_BLK_DEV_HD hack from init_hwif() Bartlomiej Zolnierkiewicz
2008-02-08 0:45 ` [PATCH 13/18] ide: remove CONFIG_BLK_DEV_HD_IDE config option Bartlomiej Zolnierkiewicz
2008-02-08 0:45 ` [PATCH 14/18] ide: remove obsoleted "idex=base[, ctl[, irq]]" kernel parameters Bartlomiej Zolnierkiewicz
2008-02-08 0:46 ` [PATCH 15/18] ide: remove broken/dangerous HDIO_[UNREGISTER, SCAN]_HWIF ioctls Bartlomiej Zolnierkiewicz
2008-03-27 17:38 ` Sergei Shtylyov
2008-03-28 19:14 ` Mark Lord
2008-03-29 16:10 ` Bartlomiej Zolnierkiewicz
2008-03-29 16:03 ` Bartlomiej Zolnierkiewicz
2008-02-08 0:46 ` [PATCH 16/18] ide: remove ->hold field from ide_hwif_t Bartlomiej Zolnierkiewicz
2008-02-08 0:46 ` [PATCH 17/18] ide: remove init_hwif_default() Bartlomiej Zolnierkiewicz
2008-02-08 0:46 ` [PATCH 18/18] ide: remove ide_init_hwif_ports() Bartlomiej Zolnierkiewicz
2008-02-08 8:40 ` [PATCH 00/18] ide: warm-plug support for IDE devices and other goodies Benjamin Herrenschmidt
2008-02-12 11:49 ` Gabriel Paubert
2008-02-12 12:30 ` Gabriel Paubert
2008-02-13 10:08 ` Gabriel Paubert
2008-02-12 20:59 ` Benjamin Herrenschmidt
2008-02-12 21:04 ` Benjamin Herrenschmidt
2008-02-12 21:41 ` Alan Cox
2008-02-12 22:00 ` Benjamin Herrenschmidt
2008-02-12 21:54 ` Bartlomiej Zolnierkiewicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080208004530.17746.11984.sendpatchset@localhost.localdomain \
--to=bzolnier@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).