From 74811f355f4f69a187fa74892dcf2a684b84ce99 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Thu, 24 Jul 2008 22:53:15 +0200 Subject: [PATCH] hpt366: convert to use ->host_priv While at it: * Allocate both struct hpt_info instances at once. Cc: Sergei Shtylyov Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/ide/pci/hpt366.c | 72 +++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index b23b7a2..8f29571 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c @@ -620,7 +620,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive) { 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 *drive) { 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, struct hpt_info *info) 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 *drive, int mask) { 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_dpll(struct pci_dev *dev, u16 f_low, u16 f 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_chipset_hpt366(struct pci_dev *dev, const cha 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_chipset_hpt366(struct pci_dev *dev, const cha } 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_chipset_hpt366(struct pci_dev *dev, const cha 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_chipset_hpt366(struct pci_dev *dev, const cha 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(ide_hwif_t *hwif) 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_chipsets[] __devinitdata = { 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(struct pci_dev *dev, const struct pci_devic 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(struct pci_dev *dev, const struct pci_devic 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 = { -- 2.7.4