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: linux-kernel@vger.kernel.org, Sergei Shtylyov <sshtylyov@ru.mvista.com>
Subject: [PATCH 09/50] hpt366: convert to use ->host_priv
Date: Sun, 06 Jul 2008 19:20:19 +0200	[thread overview]
Message-ID: <48710238.1ade660a.3458.627b@mx.google.com> (raw)
In-Reply-To: 20080706172010.559358957@bzolnier@gmail.com

[-- Attachment #1: hpt366-convert-to-use-host_priv.patch --]
[-- Type: text/plain, Size: 6539 bytes --]

While at it:

* Allocate both struct hpt_info instances at once.

Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
Sergei: we may also consider using only one struct hpt_info instance
for both PCI devices on HPT366 with split PCI config space and HPT374
but I'm leaving this to your judgement.

 drivers/ide/pci/hpt366.c |   72 ++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 31 deletions(-)

Index: b/drivers/ide/pci/hpt366.c
===================================================================
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -620,7 +620,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t
 {
 	ide_hwif_t *hwif	= HWIF(drive);
 	struct pci_dev *dev	= to_pci_dev(hwif->dev);
-	struct hpt_info *info	= pci_get_drvdata(dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 	u8 mask 		= hwif->ultra_mask;
 
 	switch (info->chip_type) {
@@ -660,7 +661,8 @@ static u8 hpt3xx_mdma_filter(ide_drive_t
 {
 	ide_hwif_t *hwif	= HWIF(drive);
 	struct pci_dev *dev	= to_pci_dev(hwif->dev);
-	struct hpt_info *info	= pci_get_drvdata(dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 
 	switch (info->chip_type) {
 	case HPT372 :
@@ -694,8 +696,10 @@ static u32 get_speed_setting(u8 speed, s
 
 static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
 {
-	struct pci_dev  *dev	= to_pci_dev(drive->hwif->dev);
-	struct hpt_info	*info	= pci_get_drvdata(dev);
+	ide_hwif_t *hwif	= drive->hwif;
+	struct pci_dev *dev	= to_pci_dev(hwif->dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 	struct hpt_timings *t	= info->timings;
 	u8  itr_addr		= 0x40 + (drive->dn * 4);
 	u32 old_itr		= 0;
@@ -738,7 +742,8 @@ static void hpt3xx_maskproc(ide_drive_t 
 {
 	ide_hwif_t *hwif	= HWIF(drive);
 	struct pci_dev	*dev	= to_pci_dev(hwif->dev);
-	struct hpt_info *info	= pci_get_drvdata(dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 
 	if (drive->quirk_list) {
 		if (info->chip_type >= HPT370) {
@@ -965,22 +970,13 @@ static int __devinit hpt37x_calibrate_dp
 
 static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
 {
-	struct hpt_info *info	= kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
 	unsigned long io_base	= pci_resource_start(dev, 4);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (&dev->dev == host->dev[1]);
 	u8 pci_clk,  dpll_clk	= 0;	/* PCI and DPLL clock in MHz */
 	u8 chip_type;
 	enum ata_clock	clock;
 
-	if (info == NULL) {
-		printk(KERN_ERR "%s: out of memory!\n", name);
-		return -ENOMEM;
-	}
-
-	/*
-	 * Copy everything from a static "template" structure
-	 * to just allocated per-chip hpt_info structure.
-	 */
-	memcpy(info, pci_get_drvdata(dev), sizeof(struct hpt_info));
 	chip_type = info->chip_type;
 
 	pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
@@ -1142,7 +1138,6 @@ static unsigned int __devinit init_chips
 
 		if (info->timings->clock_table[clock] == NULL) {
 			printk(KERN_ERR "%s: unknown bus timing!\n", name);
-			kfree(info);
 			return -EIO;
 		}
 
@@ -1169,7 +1164,6 @@ static unsigned int __devinit init_chips
 		}
 		if (adjust == 8) {
 			printk(KERN_ERR "%s: DPLL did not stabilize!\n", name);
-			kfree(info);
 			return -EIO;
 		}
 
@@ -1186,9 +1180,6 @@ static unsigned int __devinit init_chips
 	info->pci_clk	= pci_clk;
 	info->clock	= clock;
 
-	/* Point to this chip's own instance of the hpt_info structure. */
-	pci_set_drvdata(dev, info);
-
 	if (chip_type >= HPT370) {
 		u8  mcr1, mcr4;
 
@@ -1218,7 +1209,8 @@ static unsigned int __devinit init_chips
 static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
 {
 	struct pci_dev	*dev	= to_pci_dev(hwif->dev);
-	struct hpt_info *info	= pci_get_drvdata(dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 	u8 chip_type		= info->chip_type;
 	u8 scr1 = 0, ata66	= hwif->channel ? 0x01 : 0x02;
 
@@ -1262,7 +1254,8 @@ static u8 __devinit hpt3xx_cable_detect(
 static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
 {
 	struct pci_dev *dev	= to_pci_dev(hwif->dev);
-	struct hpt_info *info	= pci_get_drvdata(dev);
+	struct ide_host *host	= pci_get_drvdata(dev);
+	struct hpt_info *info	= host->host_priv + (hwif->dev == host->dev[1]);
 	int serialize		= HPT_SERIALIZE_IO;
 	u8  chip_type		= info->chip_type;
 	u8  new_mcr, old_mcr	= 0;
@@ -1542,10 +1535,12 @@ static const struct ide_port_info hpt366
 static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	const struct hpt_info *info = NULL;
+	struct hpt_info *dyn_info;
 	struct pci_dev *dev2 = NULL;
 	struct ide_port_info d;
 	u8 idx = id->driver_data;
 	u8 rev = dev->revision;
+	int ret;
 
 	if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1))
 		return -ENODEV;
@@ -1591,15 +1586,24 @@ static int __devinit hpt366_init_one(str
 	if (info == &hpt370 || info == &hpt370a)
 		d.dma_ops = &hpt370_dma_ops;
 
-	pci_set_drvdata(dev, (void *)info);
-
 	if (info == &hpt36x || info == &hpt374)
 		dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
 
-	if (dev2) {
-		int ret;
+	dyn_info = kzalloc(sizeof(*dyn_info) * (dev2 ? 2 : 1), GFP_KERNEL);
+	if (dyn_info == NULL) {
+		printk(KERN_ERR "%s: out of memory!\n", d.name);
+		pci_dev_put(dev2);
+		return -ENOMEM;
+	}
+
+	/*
+	 * Copy everything from a static "template" structure
+	 * to just allocated per-chip hpt_info structure.
+	 */
+	memcpy(dyn_info, info, sizeof(*dyn_info));
 
-		pci_set_drvdata(dev2, (void *)info);
+	if (dev2) {
+		memcpy(dyn_info + 1, info, sizeof(*dyn_info));
 
 		if (info == &hpt374)
 			hpt374_init(dev, dev2);
@@ -1608,13 +1612,19 @@ static int __devinit hpt366_init_one(str
 				d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE;
 		}
 
-		ret = ide_pci_init_two(dev, dev2, &d, NULL);
-		if (ret < 0)
+		ret = ide_pci_init_two(dev, dev2, &d, dyn_info);
+		if (ret < 0) {
 			pci_dev_put(dev2);
+			kfree(dyn_info);
+		}
 		return ret;
 	}
 
-	return ide_pci_init_one(dev, &d, NULL);
+	ret = ide_pci_init_one(dev, &d, dyn_info);
+	if (ret < 0)
+		kfree(dyn_info);
+
+	return ret;
 }
 
 static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {

-- 


  parent reply	other threads:[~2008-07-06 17:34 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080706172010.559358957@bzolnier@gmail.com>
2008-07-06 17:20 ` [PATCH 01/50] it8213: fix return value in it8213_init_one() Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 02/50] ide: always call ->init_chipset method in do_ide_setup_pci_device() Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 03/50] ide: respect dev->irq in do_ide_setup_pci_device() also if tried_config Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 04/50] ide: move ide_setup_pci_controller() call to ide_setup_pci_device() Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 05/50] ide: call ide_pci_setup_ports() before do_ide_setup_pci_device() Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 06/50] ide: add ->dev and ->host_priv fields to struct ide_host Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 07/50] ide: add ide_device_{get,put}() helpers Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 08/50] aec62xx: convert to use ->host_priv Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` Bartlomiej Zolnierkiewicz [this message]
2008-07-06 17:20 ` [PATCH 10/50] it821x: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 11/50] sc1200: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 12/50] siimage: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 13/50] via82cxxx: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 14/50] tc86c001: remove ->init_chipset method Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 15/50] amd74xx: cleanup " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 16/50] cmd64x: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 17/50] via82cxxx: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 18/50] ide: add ide_pci_remove() helper Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 19/50] aec62xx: add ->remove method and module_exit() Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 20/50] alim15x3: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 21/50] amd74xx: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 22/50] atiixp: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 23/50] cmd64x: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 24/50] cs5530: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 25/50] cs5535: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 26/50] cy82c693: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 27/50] ide/pci/generic: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 28/50] hpt34x: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 29/50] hpt366: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 30/50] it8213: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 31/50] it821x: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 32/50] jmicron: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 33/50] ns87415: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 34/50] opti621: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 35/50] pdc202xx_new: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 36/50] pdc202xx_old: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 37/50] piix: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 38/50] rz1000: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 39/50] sc1200: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 40/50] serverworks: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 41/50] siimage: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 42/50] sis5513: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 43/50] sl82c105: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 44/50] slc90e66: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 45/50] tc86c001: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 46/50] triflex: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 47/50] trm290: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 48/50] via82cxxx: " Bartlomiej Zolnierkiewicz
2008-07-06 17:20 ` [PATCH 49/50] icside: add module_exit() Bartlomiej Zolnierkiewicz
2008-07-06 17:21 ` [PATCH 50/50] rapide: " 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=48710238.1ade660a.3458.627b@mx.google.com \
    --to=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sshtylyov@ru.mvista.com \
    /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).