linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 04/22] ide: add ide_deprecated_find_port() helper
Date: Thu, 17 Jan 2008 00:26:24 +0100	[thread overview]
Message-ID: <20080116232624.9166.73929.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20080116232556.9166.13457.sendpatchset@localhost.localdomain>

* Factor out code for finding ide_hwifs[] slot from ide_register_hw()
  to ide_deprecated_find_port().

* Convert bast-ide, ide-cs and delkin_cb host drivers to use ide_device_add()
  instead of ide_register_hw() (while at it drop doing "ide_unregister()" loop
  which tries to unregister _all_ IDE interfaces if useable ide_hwifs[] slot
  cannot be find).

This patch leaves us with only two ide_register_hw() users:
- drivers/macintosh/mediabay.c
- drivers/ide/ide.c

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/arm/bast-ide.c  |   20 +++++++++++++++++++-
 drivers/ide/ide.c           |   41 +++++++++++++++++++++++++++++------------
 drivers/ide/legacy/ide-cs.c |   25 ++++++++++++++++++++++++-
 drivers/ide/pci/delkin_cb.c |   33 +++++++++++++++++++++++++++------
 include/linux/ide.h         |    1 +
 5 files changed, 100 insertions(+), 20 deletions(-)

Index: b/drivers/ide/arm/bast-ide.c
===================================================================
--- a/drivers/ide/arm/bast-ide.c
+++ b/drivers/ide/arm/bast-ide.c
@@ -28,8 +28,10 @@ static int __init
 bastide_register(unsigned int base, unsigned int aux, int irq,
 		 ide_hwif_t **hwif)
 {
+	ide_hwif_t *hwif;
 	hw_regs_t hw;
 	int i;
+	u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
 	memset(&hw, 0, sizeof(hw));
 
@@ -44,8 +46,24 @@ bastide_register(unsigned int base, unsi
 	hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20);
 	hw.irq = irq;
 
-	ide_register_hw(&hw, NULL, hwif);
+	hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+	if (hwif == NULL)
+		goto out;
 
+	i = hwif->index;
+
+	if (hwif->present)
+		ide_unregister(i, 0, 1);
+	else if (!hwif->hold)
+		ide_init_port_data(hwif, i);
+
+	ide_init_port_hw(hwif, &hw);
+	hwif->quirkproc = NULL;
+
+	idx[0] = i;
+
+	ide_device_add(idx, NULL);
+out:
 	return 0;
 }
 
Index: b/drivers/ide/ide.c
===================================================================
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -683,6 +683,31 @@ void ide_init_port_hw(ide_hwif_t *hwif, 
 }
 EXPORT_SYMBOL_GPL(ide_init_port_hw);
 
+ide_hwif_t *ide_deprecated_find_port(unsigned long base)
+{
+	ide_hwif_t *hwif;
+	int i;
+
+	for (i = 0; i < MAX_HWIFS; i++) {
+		hwif = &ide_hwifs[i];
+		if (hwif->io_ports[IDE_DATA_OFFSET] == base)
+			goto found;
+	}
+
+	for (i = 0; i < MAX_HWIFS; i++) {
+		hwif = &ide_hwifs[i];
+		if (hwif->hold)
+			continue;
+		if (!hwif->present && hwif->mate == NULL)
+			goto found;
+	}
+
+	hwif = NULL;
+found:
+	return hwif;
+}
+EXPORT_SYMBOL_GPL(ide_deprecated_find_port);
+
 /**
  *	ide_register_hw		-	register IDE interface
  *	@hw: hardware registers
@@ -702,18 +727,10 @@ int ide_register_hw(hw_regs_t *hw, void 
 	u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
 	do {
-		for (index = 0; index < MAX_HWIFS; ++index) {
-			hwif = &ide_hwifs[index];
-			if (hwif->io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
-				goto found;
-		}
-		for (index = 0; index < MAX_HWIFS; ++index) {
-			hwif = &ide_hwifs[index];
-			if (hwif->hold)
-				continue;
-			if (!hwif->present && hwif->mate == NULL)
-				goto found;
-		}
+		hwif = ide_deprecated_find_port(hw->io_ports[IDE_DATA_OFFSET]);
+		index = hwif->index;
+		if (hwif)
+			goto found;
 		for (index = 0; index < MAX_HWIFS; index++)
 			ide_unregister(index, 1, 1);
 	} while (retry--);
Index: b/drivers/ide/legacy/ide-cs.c
===================================================================
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -145,13 +145,36 @@ static void ide_detach(struct pcmcia_dev
 
 static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle)
 {
+    ide_hwif_t *hwif;
     hw_regs_t hw;
+    int i;
+    u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+
     memset(&hw, 0, sizeof(hw));
     ide_init_hwif_ports(&hw, io, ctl, NULL);
     hw.irq = irq;
     hw.chipset = ide_pci;
     hw.dev = &handle->dev;
-    return ide_register_hw(&hw, &ide_undecoded_slave, NULL);
+
+    hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+    if (hwif == NULL)
+	return -1;
+
+    i = hwif->index;
+
+    if (hwif->present)
+	ide_unregister(i, 0, 1);
+    else if (!hwif->hold)
+	ide_init_port_data(hwif, i);
+
+    ide_init_port_hw(hwif, &hw);
+    hwif->quirkproc = &ide_undecoded_slave;
+
+    idx[0] = i;
+
+    ide_device_add(idx, NULL);
+
+    return hwif->present ? i : -1;
 }
 
 /*======================================================================
Index: b/drivers/ide/pci/delkin_cb.c
===================================================================
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -51,6 +51,7 @@ delkin_cb_probe (struct pci_dev *dev, co
 	ide_hwif_t *hwif = NULL;
 	ide_drive_t *drive;
 	int i, rc;
+	u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
 
 	rc = pci_enable_device(dev);
 	if (rc) {
@@ -77,12 +78,27 @@ delkin_cb_probe (struct pci_dev *dev, co
 	hw.irq = dev->irq;
 	hw.chipset = ide_pci;		/* this enables IRQ sharing */
 
-	rc = ide_register_hw(&hw, &ide_undecoded_slave, &hwif);
-	if (rc < 0) {
-		printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc);
-		pci_disable_device(dev);
-		return -ENODEV;
-	}
+	hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]);
+	if (hwif == NULL)
+		goto out_disable;
+
+	i = hwif->index;
+
+	if (hwif->present)
+		ide_unregister(i, 0, 1);
+	else if (!hwif->hold)
+		ide_init_port_data(hwif, i);
+
+	ide_init_port_hw(hwif, &hw);
+	hwif->quirkproc = &ide_undecoded_slave;
+
+	idx[0] = i;
+
+	ide_device_add(idx, NULL);
+
+	if (!hwif->present)
+		goto out_disable;
+
 	pci_set_drvdata(dev, hwif);
 	hwif->dev = &dev->dev;
 	drive = &hwif->drives[0];
@@ -91,6 +107,11 @@ delkin_cb_probe (struct pci_dev *dev, co
 		drive->unmask   = 1;
 	}
 	return 0;
+
+out_disable:
+	printk(KERN_ERR "delkin_cb: no IDE devices found\n");
+	pci_disable_device(dev);
+	return -ENODEV;
 }
 
 static void
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -196,6 +196,7 @@ typedef struct hw_regs_s {
 } hw_regs_t;
 
 struct hwif_s * ide_find_port(unsigned long);
+struct hwif_s *ide_deprecated_find_port(unsigned long);
 void ide_init_port_data(struct hwif_s *, unsigned int);
 void ide_init_port_hw(struct hwif_s *, hw_regs_t *);
 

  parent reply	other threads:[~2008-01-16 23:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-16 23:25 [PATCH 00/22] ide: even more IDE probing code rework Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 01/22] ide: remove redundant hwif->present check from ide_register_hw() Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 02/22] ide: remove redundant init_hwif_default() call " Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 03/22] ide: add 'init_default' and 'restore' arguments to ide_unregister() Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` Bartlomiej Zolnierkiewicz [this message]
2008-05-21 14:29   ` [PATCH 04/22] ide: add ide_deprecated_find_port() helper Sergei Shtylyov
2008-05-27 18:36     ` Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 05/22] ide: fix ide_unregister() usage in host drivers Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 06/22] ide: factor out code initializing devices from ide_init_port() Bartlomiej Zolnierkiewicz
2008-01-16 23:26 ` [PATCH 07/22] ide: add IDE_HFLAG_NO_{IO32_BIT,UNMASK_IRQS} host flags Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 08/22] ide: add ->init_port_devs method to ide_hwif_t Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 09/22] ide: remove incorrect init_gendisk() comment Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 10/22] ide: skip not present devices in init_gendisk() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 11/22] ide: move blk_register_region() call out from init_gendisk() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 12/22] ide: call init_gendisk() after ide_acpi_init() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 13/22] ide: merge init_gendisk() into hwif_register_devices() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 14/22] ide: move hwif->rqsize init from ide_init_queue() to init_irq() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 15/22] ide: factor out adding drive to hwgroup from init_irq() Bartlomiej Zolnierkiewicz
2008-01-16 23:27 ` [PATCH 16/22] ide: factor out devices setup " Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 17/22] ide: move ide_acpi_init() call to ide_device_add_all() Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 18/22] ide-acpi: remove needless exports Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 19/22] ide-acpi: remove dead code from do_drive_get_GTF() Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 20/22] ide: factor out devices setup from ide_acpi_init() Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 21/22] ide: move hwif->present check out from ide_proc_register_port() Bartlomiej Zolnierkiewicz
2008-01-16 23:28 ` [PATCH 22/22] ide: move create_proc_ide_drives() call to ide_device_add_all() 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=20080116232624.9166.73929.sendpatchset@localhost.localdomain \
    --to=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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).