From nobody Thu Feb 12 23:02:22 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EA95148304; Thu, 2 Jan 2025 16:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735835780; cv=none; b=CoAkT9DZMK+3GpkAKOM4JAsngobvuPkSQx+XBGefvTstimEEX2evbBMheKPozOvfZZ2wBJbPd82ZU6yt4rx0GO0Hs/UO4sHgBCckMA5w7AUkpCXSCZ/OUyPLZlDNRuuoMa6HC2f1cVwNloudZrpDjlKlBBMHP7SWVmmstb74fgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735835780; c=relaxed/simple; bh=0Md6c+b+wpcjvX1QpcwZdOFUz1aQd23eKmAYPL+lzgk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=aTQ9PH3kH6AqJ8XxddVv3tbexmDXUT4uWQZpMFSCaASqqdU8qW7Zcn1U0cMaCLOs8+WYFjY/U4jUPGFTMJNq7Ob8lHaqL9O+9WAQH2nPFVXwVsiYe+b2O633q8Y6EDN9WRAo7jrvidSmqMZ/p2xlw8gYSeamMathL8ZgX9qBC9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s2gf2AuT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s2gf2AuT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42D91C4CEDC; Thu, 2 Jan 2025 16:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735835780; bh=0Md6c+b+wpcjvX1QpcwZdOFUz1aQd23eKmAYPL+lzgk=; h=From:To:Cc:Subject:Date:From; b=s2gf2AuTNFSnTIkfAR7KPeJ528qKMZG0BPq2l+/c3RyTe8ighka7Hc0ODZkQ2cOwK wyAmOuHnlkh9vfUbENShP24qnYA5vjwqO6WNYGXZC7ktKVK4tf4/fIGvi9IBHaeU+q RBis6VDcPRea7XD+CSpvLX2N8iUNR53ydB6D04yvFvZgOcOUg5PjtqB0Zq1WqFKDjS i3/u2IMhQwlQcvwRyeKh81rcZyNG6vWCFE+2+s6po85HA4J1xCP708AZPHmJVh53S0 eUqtlKEtzs4fFiLNpEDHEgQU1sMRa++33ox78LJ4wQce4dVLRH1beqiyRRgN9Sj4Q/ aKehbjQZMuBig== From: Philipp Stanner To: Damien Le Moal , Niklas Cassel , Mikael Pettersson Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Philipp Stanner Subject: [PATCH] ata: Replace deprecated PCI functions Date: Thu, 2 Jan 2025 17:35:32 +0100 Message-ID: <20250102163531.63839-2-phasta@kernel.org> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Philipp Stanner struct ata_host.iomap has been created and administrated so far by pcim_iomap_table(), a problematic function that has been deprecated in commit e354bb84a4c1c ("PCI: Deprecate pcim_iomap_table(), pcim_iomap_regions_request_all()") Ideally, drivers should not need a global table at all and should store ioremaped BARs in their respective structs separately. For ATA, however, it's far easier to deprecate pcim_iomap_table() by allocating struct ata_host.iomap statically as an array of iomem pointers. Since PCI_STD_NUM_BARS is currently defined to be 6, the memory overhead is irrelevant. Make struct ata_host.iomap a static iomem pointer table. Remove all calls to pcim_iomap_table() and pcim_iomap_regions(), and fill the aforementioned table directly through pcim_iomap_region(). Signed-off-by: Philipp Stanner --- Happy New Year folks. Squased version (so that everything compiles without hacks) of my RFC from a while back [1]. Mostly identical to the RFC, just some formatting comments taken into account. The changes in libata-sff.c will probably be happy about a careful review. It wasn't easy to figure out the bitmask sorcery there. Cheers, P. [1] https://lore.kernel.org/all/20241204171033.86804-2-pstanner@redhat.com/ --- drivers/ata/ata_piix.c | 7 +- drivers/ata/libata-sff.c | 133 +++++++++++++++++++++++------------- drivers/ata/pata_atp867x.c | 13 ++-- drivers/ata/pata_hpt3x3.c | 7 +- drivers/ata/pata_ninja32.c | 9 ++- drivers/ata/pata_pdc2027x.c | 11 ++- drivers/ata/pata_sil680.c | 11 +-- drivers/ata/pdc_adma.c | 9 ++- drivers/ata/sata_inic162x.c | 10 ++- drivers/ata/sata_mv.c | 7 +- drivers/ata/sata_nv.c | 8 +-- drivers/ata/sata_promise.c | 6 +- drivers/ata/sata_qstor.c | 7 +- drivers/ata/sata_sil.c | 6 +- drivers/ata/sata_sil24.c | 20 +++--- drivers/ata/sata_sis.c | 8 +-- drivers/ata/sata_svw.c | 8 +-- drivers/ata/sata_sx4.c | 15 +++- drivers/ata/sata_via.c | 31 +++++---- drivers/ata/sata_vsc.c | 6 +- include/linux/libata.h | 7 +- 21 files changed, 200 insertions(+), 139 deletions(-) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 093b940bc953..8db14065a256 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -1456,10 +1456,9 @@ static int piix_init_sidpr(struct ata_host *host) pci_resource_len(pdev, PIIX_SIDPR_BAR) !=3D PIIX_SIDPR_LEN) return 0; =20 - if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME)) - return 0; - - hpriv->sidpr =3D pcim_iomap_table(pdev)[PIIX_SIDPR_BAR]; + hpriv->sidpr =3D pcim_iomap_region(pdev, PIIX_SIDPR_BAR, DRV_NAME); + if (IS_ERR(hpriv->sidpr)) + return PTR_ERR(hpriv->sidpr); =20 /* SCR access via SIDPR doesn't work on some configurations. * Give it a test drive by inhibiting power save modes which diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index 67f277e1c3bf..181741b8db36 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -2127,6 +2127,76 @@ static bool ata_resources_present(struct pci_dev *pd= ev, int port) return true; } =20 +static void ata_pci_sff_set_port_data(struct ata_port *ap, struct ata_host= *host, + struct pci_dev *pdev, unsigned short base) +{ + void __iomem *ctl_addr; + + ctl_addr =3D host->iomap[base + 1]; + ctl_addr =3D (void __iomem *)((unsigned long)ctl_addr | ATA_PCI_CTL_OFS); + + ap->ioaddr.cmd_addr =3D host->iomap[base]; + ap->ioaddr.altstatus_addr =3D ctl_addr; + ap->ioaddr.ctl_addr =3D ctl_addr; + + ata_sff_std_ports(&ap->ioaddr); + + ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", + (unsigned long long)pci_resource_start(pdev, base), + (unsigned long long)pci_resource_start(pdev, base + 1)); +} + +/** + * ata_pci_sff_obtain_bars - obtain the PCI BARs associated with an ATA po= rt + * @pdev: the PCI device + * @host: the ATA host + * @ap: the ATA port + * @port: @ap's port index in @host + * + * Returns: Number of successfully ioremaped BARs, a negative code on fail= ure + */ +static int ata_pci_sff_obtain_bars(struct pci_dev *pdev, struct ata_host *= host, + struct ata_port *ap, unsigned short port) +{ + int ret =3D 0, bars_mapped =3D 0; + unsigned short i, base, bar_index; + void __iomem *iomem; + const char *name =3D dev_driver_string(&pdev->dev); + + /* + * Port can be 0 or 1. + * Port 0 corresponds to PCI BARs 0 and 1, port 1 to BARs 2 and 3. + */ + base =3D port * 2; + + /* + * Discard disabled ports. Some controllers show their unused channels + * this way. Disabled ports are made dummy. + */ + if (!ata_resources_present(pdev, port)) + goto try_next; + + for (i =3D 0; i < 2; i++) { + bar_index =3D base + i; + + iomem =3D pcim_iomap_region(pdev, bar_index, name); + ret =3D PTR_ERR_OR_ZERO(iomem); + if (ret) + goto try_next; + + host->iomap[bar_index] =3D iomem; + bars_mapped++; + } + + ata_pci_sff_set_port_data(ap, host, pdev, base); + + return bars_mapped; + +try_next: + ap->ops =3D &ata_dummy_port_ops; + return ret; +} + /** * ata_pci_sff_init_host - acquire native PCI ATA resources and init host * @host: target ATA host @@ -2148,59 +2218,31 @@ static bool ata_resources_present(struct pci_dev *p= dev, int port) */ int ata_pci_sff_init_host(struct ata_host *host) { - struct device *gdev =3D host->dev; - struct pci_dev *pdev =3D to_pci_dev(gdev); - unsigned int mask =3D 0; - int i, rc; - - /* request, iomap BARs and init port addresses accordingly */ - for (i =3D 0; i < 2; i++) { - struct ata_port *ap =3D host->ports[i]; - int base =3D i * 2; - void __iomem * const *iomap; + int ret; + unsigned short port_nr, operational_ports =3D 0; + struct device *dev =3D host->dev; + struct pci_dev *pdev =3D to_pci_dev(dev); + struct ata_port *ap; =20 + for (port_nr =3D 0; port_nr < 2; port_nr++) { + ap =3D host->ports[port_nr]; if (ata_port_is_dummy(ap)) continue; =20 - /* Discard disabled ports. Some controllers show - * their unused channels this way. Disabled ports are - * made dummy. - */ - if (!ata_resources_present(pdev, i)) { - ap->ops =3D &ata_dummy_port_ops; - continue; - } - - rc =3D pcim_iomap_regions(pdev, 0x3 << base, - dev_driver_string(gdev)); - if (rc) { - dev_warn(gdev, + ret =3D ata_pci_sff_obtain_bars(pdev, host, ap, port_nr); + if (ret > 0) { + operational_ports +=3D ret; + } else if (ret < 0) { + dev_warn(dev, "failed to request/iomap BARs for port %d (errno=3D%d)\n", - i, rc); - if (rc =3D=3D -EBUSY) + port_nr, ret); + if (ret =3D=3D -EBUSY) pcim_pin_device(pdev); - ap->ops =3D &ata_dummy_port_ops; - continue; } - host->iomap =3D iomap =3D pcim_iomap_table(pdev); - - ap->ioaddr.cmd_addr =3D iomap[base]; - ap->ioaddr.altstatus_addr =3D - ap->ioaddr.ctl_addr =3D (void __iomem *) - ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS); - ata_sff_std_ports(&ap->ioaddr); - - ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", - (unsigned long long)pci_resource_start(pdev, base), - (unsigned long long)pci_resource_start(pdev, base + 1)); - - mask |=3D 1 << i; } =20 - if (!mask) { - dev_err(gdev, "no available native port\n"); + if (!operational_ports) return -ENODEV; - } =20 return 0; } @@ -3094,12 +3136,11 @@ void ata_pci_bmdma_init(struct ata_host *host) ata_bmdma_nodma(host, "failed to set dma mask"); =20 /* request and iomap DMA region */ - rc =3D pcim_iomap_regions(pdev, 1 << 4, dev_driver_string(gdev)); - if (rc) { + host->iomap[4] =3D pcim_iomap_region(pdev, 4, dev_driver_string(gdev)); + if (IS_ERR(host->iomap[4])) { ata_bmdma_nodma(host, "failed to request/iomap BAR4"); return; } - host->iomap =3D pcim_iomap_table(pdev); =20 for (i =3D 0; i < 2; i++) { struct ata_port *ap =3D host->ports[i]; diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c index aaef5924f636..4b47cb92cbe6 100644 --- a/drivers/ata/pata_atp867x.c +++ b/drivers/ata/pata_atp867x.c @@ -405,17 +405,20 @@ static int atp867x_ata_pci_sff_init_host(struct ata_h= ost *host) struct device *gdev =3D host->dev; struct pci_dev *pdev =3D to_pci_dev(gdev); unsigned int mask =3D 0; + void __iomem *iomem; int i, rc; =20 /* * do not map rombase */ - rc =3D pcim_iomap_regions(pdev, 1 << ATP867X_BAR_IOBASE, DRV_NAME); - if (rc =3D=3D -EBUSY) - pcim_pin_device(pdev); - if (rc) + iomem =3D pcim_iomap_region(pdev, ATP867X_BAR_IOBASE, DRV_NAME); + if (IS_ERR(iomem)) { + rc =3D PTR_ERR(iomem); + if (rc =3D=3D -EBUSY) + pcim_pin_device(pdev); return rc; - host->iomap =3D pcim_iomap_table(pdev); + } + host->iomap[ATP867X_BAR_IOBASE] =3D iomem; =20 atp867x_check_res(pdev); =20 diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c index d65c586b5ad0..2dd62317eb4f 100644 --- a/drivers/ata/pata_hpt3x3.c +++ b/drivers/ata/pata_hpt3x3.c @@ -215,17 +215,18 @@ static int hpt3x3_init_one(struct pci_dev *pdev, cons= t struct pci_device_id *id) return rc; =20 /* Everything is relative to BAR4 if we set up this way */ - rc =3D pcim_iomap_regions(pdev, 1 << 4, DRV_NAME); + base =3D pcim_iomap_region(pdev, 4, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(base); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); + rc =3D dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); if (rc) return rc; =20 - base =3D host->iomap[4]; /* Bus mastering base */ + host->iomap[4] =3D base; /* Bus mastering base */ =20 for (i =3D 0; i < host->n_ports; i++) { struct ata_port *ap =3D host->ports[i]; diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c index 76a91013d27d..d1edcd504044 100644 --- a/drivers/ata/pata_ninja32.c +++ b/drivers/ata/pata_ninja32.c @@ -116,13 +116,14 @@ static int ninja32_init_one(struct pci_dev *dev, cons= t struct pci_device_id *id) rc =3D pcim_enable_device(dev); if (rc) return rc; - rc =3D pcim_iomap_regions(dev, 1 << 0, DRV_NAME); + + base =3D pcim_iomap_region(dev, 0, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(base); if (rc =3D=3D -EBUSY) pcim_pin_device(dev); if (rc) return rc; =20 - host->iomap =3D pcim_iomap_table(dev); rc =3D dma_set_mask_and_coherent(&dev->dev, ATA_DMA_MASK); if (rc) return rc; @@ -130,9 +131,7 @@ static int ninja32_init_one(struct pci_dev *dev, const = struct pci_device_id *id) =20 /* Set up the register mappings. We use the I/O mapping as only the older chips also have MMIO on BAR 1 */ - base =3D host->iomap[0]; - if (!base) - return -ENOMEM; + host->iomap[0] =3D base; ap->ops =3D &ninja32_port_ops; ap->pio_mask =3D ATA_PIO4; ap->flags |=3D ATA_FLAG_SLAVE_POSS; diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c index 6820c5597b14..360b8d7e08bf 100644 --- a/drivers/ata/pata_pdc2027x.c +++ b/drivers/ata/pata_pdc2027x.c @@ -702,17 +702,16 @@ static int pdc2027x_init_one(struct pci_dev *pdev, if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME); - if (rc) - return rc; - host->iomap =3D pcim_iomap_table(pdev); + mmio_base =3D pcim_iomap_region(pdev, PDC_MMIO_BAR, DRV_NAME); + if (IS_ERR(mmio_base)) + return PTR_ERR(mmio_base); + + host->iomap[PDC_MMIO_BAR] =3D mmio_base; =20 rc =3D dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); if (rc) return rc; =20 - mmio_base =3D host->iomap[PDC_MMIO_BAR]; - for (i =3D 0; i < 2; i++) { struct ata_port *ap =3D host->ports[i]; =20 diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c index abe64b5f83cf..8a17df73412e 100644 --- a/drivers/ata/pata_sil680.c +++ b/drivers/ata/pata_sil680.c @@ -360,15 +360,16 @@ static int sil680_init_one(struct pci_dev *pdev, cons= t struct pci_device_id *id) /* Try to acquire MMIO resources and fallback to PIO if * that fails */ - rc =3D pcim_iomap_regions(pdev, 1 << SIL680_MMIO_BAR, DRV_NAME); - if (rc) + mmio_base =3D pcim_iomap_region(pdev, SIL680_MMIO_BAR, DRV_NAME); + if (IS_ERR(mmio_base)) { + rc =3D PTR_ERR(mmio_base); goto use_ioports; + } =20 /* Allocate host and set it up */ host =3D ata_host_alloc_pinfo(&pdev->dev, ppi, 2); if (!host) return -ENOMEM; - host->iomap =3D pcim_iomap_table(pdev); =20 /* Setup DMA masks */ rc =3D dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); @@ -376,8 +377,8 @@ static int sil680_init_one(struct pci_dev *pdev, const = struct pci_device_id *id) return rc; pci_set_master(pdev); =20 - /* Get MMIO base and initialize port addresses */ - mmio_base =3D host->iomap[SIL680_MMIO_BAR]; + /* Set MMIO base in table and initialize port addresses */ + host->iomap[SIL680_MMIO_BAR] =3D mmio_base; host->ports[0]->ioaddr.bmdma_addr =3D mmio_base + 0x00; host->ports[0]->ioaddr.cmd_addr =3D mmio_base + 0x80; host->ports[0]->ioaddr.ctl_addr =3D mmio_base + 0x8a; diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c index 8e6b2599f0d5..f6fe0645c4b8 100644 --- a/drivers/ata/pdc_adma.c +++ b/drivers/ata/pdc_adma.c @@ -568,11 +568,10 @@ static int adma_ata_init_one(struct pci_dev *pdev, if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) =3D=3D 0) return -ENODEV; =20 - rc =3D pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME); - if (rc) - return rc; - host->iomap =3D pcim_iomap_table(pdev); - mmio_base =3D host->iomap[ADMA_MMIO_BAR]; + mmio_base =3D pcim_iomap_region(pdev, ADMA_MMIO_BAR, DRV_NAME); + if (IS_ERR(mmio_base)) + return PTR_ERR(mmio_base); + host->iomap[ADMA_MMIO_BAR] =3D mmio_base; =20 rc =3D dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (rc) { diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c index db9c255dc9f2..9512c920e4f6 100644 --- a/drivers/ata/sata_inic162x.c +++ b/drivers/ata/sata_inic162x.c @@ -817,7 +817,6 @@ static int inic_init_one(struct pci_dev *pdev, const st= ruct pci_device_id *ent) const struct ata_port_info *ppi[] =3D { &inic_port_info, NULL }; struct ata_host *host; struct inic_host_priv *hpriv; - void __iomem * const *iomap; int mmio_bar; int i, rc; =20 @@ -845,11 +844,10 @@ static int inic_init_one(struct pci_dev *pdev, const = struct pci_device_id *ent) else mmio_bar =3D MMIO_BAR_CARDBUS; =20 - rc =3D pcim_iomap_regions(pdev, 1 << mmio_bar, DRV_NAME); - if (rc) - return rc; - host->iomap =3D iomap =3D pcim_iomap_table(pdev); - hpriv->mmio_base =3D iomap[mmio_bar]; + hpriv->mmio_base =3D pcim_iomap_region(pdev, mmio_bar, DRV_NAME); + if (IS_ERR(hpriv->mmio_base)) + return PTR_ERR(hpriv->mmio_base); + host->iomap[mmio_bar] =3D hpriv->mmio_base; hpriv->cached_hctl =3D readw(hpriv->mmio_base + HOST_CTL); =20 for (i =3D 0; i < NR_PORTS; i++) { diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index b8f363370e1a..dfb0f51bfc53 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -4083,7 +4083,6 @@ static int mv_platform_probe(struct platform_device *= pdev) host->private_data =3D hpriv; hpriv->board_idx =3D chip_soc; =20 - host->iomap =3D NULL; hpriv->base =3D devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!hpriv->base) @@ -4392,13 +4391,13 @@ static int mv_pci_init_one(struct pci_dev *pdev, if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); + hpriv->base =3D pcim_iomap_region(pdev, MV_PRIMARY_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(hpriv->base); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); - hpriv->base =3D host->iomap[MV_PRIMARY_BAR]; + host->iomap[MV_PRIMARY_BAR] =3D hpriv->base; =20 rc =3D dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); if (rc) { diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index 36d99043ef50..771f73452670 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c @@ -2353,12 +2353,12 @@ static int nv_init_one(struct pci_dev *pdev, const = struct pci_device_id *ent) host->private_data =3D hpriv; =20 /* request and iomap NV_MMIO_BAR */ - rc =3D pcim_iomap_regions(pdev, 1 << NV_MMIO_BAR, DRV_NAME); - if (rc) - return rc; + base =3D pcim_iomap_region(pdev, NV_MMIO_BAR, DRV_NAME); + if (IS_ERR(base)) + return PTR_ERR(base); =20 /* configure SCR access */ - base =3D host->iomap[NV_MMIO_BAR]; + host->iomap[NV_MMIO_BAR] =3D base; host->ports[0]->ioaddr.scr_addr =3D base + NV_PORT0_SCR_REG_OFFSET; host->ports[1]->ioaddr.scr_addr =3D base + NV_PORT1_SCR_REG_OFFSET; =20 diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index 2df1a070b25a..0f98e784fbe7 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c @@ -1163,12 +1163,12 @@ static int pdc_ata_init_one(struct pci_dev *pdev, if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME); + host_mmio =3D pcim_iomap_region(pdev, PDC_MMIO_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(host_mmio); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host_mmio =3D pcim_iomap_table(pdev)[PDC_MMIO_BAR]; =20 /* determine port configuration and setup host */ n_ports =3D 2; @@ -1193,7 +1193,7 @@ static int pdc_ata_init_one(struct pci_dev *pdev, return -ENOMEM; spin_lock_init(&hpriv->hard_reset_lock); host->private_data =3D hpriv; - host->iomap =3D pcim_iomap_table(pdev); + host->iomap[PDC_MMIO_BAR] =3D host_mmio; =20 is_sataii_tx4 =3D pdc_is_sataii_tx4(pi->flags); for (i =3D 0; i < host->n_ports; i++) { diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c index 8a6286159044..2b645404687b 100644 --- a/drivers/ata/sata_qstor.c +++ b/drivers/ata/sata_qstor.c @@ -560,10 +560,9 @@ static int qs_ata_init_one(struct pci_dev *pdev, if ((pci_resource_flags(pdev, QS_MMIO_BAR) & IORESOURCE_MEM) =3D=3D 0) return -ENODEV; =20 - rc =3D pcim_iomap_regions(pdev, 1 << QS_MMIO_BAR, DRV_NAME); - if (rc) - return rc; - host->iomap =3D pcim_iomap_table(pdev); + host->iomap[QS_MMIO_BAR] =3D pcim_iomap_region(pdev, QS_MMIO_BAR, DRV_NAM= E); + if (IS_ERR(host->iomap[QS_MMIO_BAR])) + return PTR_ERR(host->iomap[QS_MMIO_BAR]); =20 rc =3D qs_set_dma_masks(pdev, host->iomap[QS_MMIO_BAR]); if (rc) diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c index 3a99f66198a9..9935eb61a694 100644 --- a/drivers/ata/sata_sil.c +++ b/drivers/ata/sata_sil.c @@ -751,18 +751,18 @@ static int sil_init_one(struct pci_dev *pdev, const s= truct pci_device_id *ent) if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, 1 << SIL_MMIO_BAR, DRV_NAME); + mmio_base =3D pcim_iomap_region(pdev, SIL_MMIO_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(mmio_base); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); =20 rc =3D dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); if (rc) return rc; =20 - mmio_base =3D host->iomap[SIL_MMIO_BAR]; + host->iomap[SIL_MMIO_BAR] =3D mmio_base; =20 for (i =3D 0; i < host->n_ports; i++) { struct ata_port *ap =3D host->ports[i]; diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index 72c03cbdaff4..fc6e7c42ad23 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c @@ -1261,7 +1261,7 @@ static int sil24_init_one(struct pci_dev *pdev, const= struct pci_device_id *ent) extern int __MARKER__sil24_cmd_block_is_sized_wrongly; struct ata_port_info pi =3D sil24_port_info[ent->driver_data]; const struct ata_port_info *ppi[] =3D { &pi, NULL }; - void __iomem * const *iomap; + void __iomem *host_iomem, *port_iomem; struct ata_host *host; int rc; u32 tmp; @@ -1277,16 +1277,17 @@ static int sil24_init_one(struct pci_dev *pdev, con= st struct pci_device_id *ent) if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, - (1 << SIL24_HOST_BAR) | (1 << SIL24_PORT_BAR), - DRV_NAME); - if (rc) - return rc; - iomap =3D pcim_iomap_table(pdev); + host_iomem =3D pcim_iomap_region(pdev, SIL24_HOST_BAR, DRV_NAME); + if (IS_ERR(host_iomem)) + return PTR_ERR(host_iomem); + + port_iomem =3D pcim_iomap_region(pdev, SIL24_PORT_BAR, DRV_NAME); + if (IS_ERR(port_iomem)) + return PTR_ERR(port_iomem); =20 /* apply workaround for completion IRQ loss on PCI-X errata */ if (pi.flags & SIL24_FLAG_PCIX_IRQ_WOC) { - tmp =3D readl(iomap[SIL24_HOST_BAR] + HOST_CTRL); + tmp =3D readl(host_iomem + HOST_CTRL); if (tmp & (HOST_CTRL_TRDY | HOST_CTRL_STOP | HOST_CTRL_DEVSEL)) dev_info(&pdev->dev, "Applying completion IRQ loss on PCI-X errata fix\n"); @@ -1299,7 +1300,8 @@ static int sil24_init_one(struct pci_dev *pdev, const= struct pci_device_id *ent) SIL24_FLAG2NPORTS(ppi[0]->flags)); if (!host) return -ENOMEM; - host->iomap =3D iomap; + host->iomap[SIL24_HOST_BAR] =3D host_iomem; + host->iomap[SIL24_PORT_BAR] =3D port_iomem; =20 /* configure and activate the device */ rc =3D dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c index ef8724986de3..45e4ae8c8996 100644 --- a/drivers/ata/sata_sis.c +++ b/drivers/ata/sata_sis.c @@ -280,10 +280,10 @@ static int sis_init_one(struct pci_dev *pdev, const s= truct pci_device_id *ent) if (!(pi.flags & SIS_FLAG_CFGSCR)) { void __iomem *mmio; =20 - rc =3D pcim_iomap_regions(pdev, 1 << SIS_SCR_PCI_BAR, DRV_NAME); - if (rc) - return rc; - mmio =3D host->iomap[SIS_SCR_PCI_BAR]; + mmio =3D pcim_iomap_region(pdev, SIS_SCR_PCI_BAR, DRV_NAME); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + host->iomap[SIS_SCR_PCI_BAR] =3D mmio; =20 host->ports[0]->ioaddr.scr_addr =3D mmio; host->ports[1]->ioaddr.scr_addr =3D mmio + port2_start; diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c index 598a872f6a08..f67f5b0dc5d9 100644 --- a/drivers/ata/sata_svw.c +++ b/drivers/ata/sata_svw.c @@ -451,14 +451,14 @@ static int k2_sata_init_one(struct pci_dev *pdev, con= st struct pci_device_id *en return -ENODEV; } =20 - /* Request and iomap PCI regions */ - rc =3D pcim_iomap_regions(pdev, 1 << bar_pos, DRV_NAME); + /* Request and iomap PCI region */ + mmio_base =3D pcim_iomap_region(pdev, bar_pos, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(mmio_base); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); - mmio_base =3D host->iomap[bar_pos]; + host->iomap[bar_pos] =3D mmio_base; =20 /* different controllers have different number of ports - currently 4 or = 8 */ /* All ports are on the same function. Multi-function device is no diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c index a482741eb181..8fc411701374 100644 --- a/drivers/ata/sata_sx4.c +++ b/drivers/ata/sata_sx4.c @@ -1390,6 +1390,7 @@ static int pdc_sata_init_one(struct pci_dev *pdev, struct ata_host *host; struct pdc_host_priv *hpriv; int i, rc; + void __iomem *iomem; =20 ata_print_version_once(&pdev->dev, DRV_VERSION); =20 @@ -1406,13 +1407,21 @@ static int pdc_sata_init_one(struct pci_dev *pdev, if (rc) return rc; =20 - rc =3D pcim_iomap_regions(pdev, (1 << PDC_MMIO_BAR) | (1 << PDC_DIMM_BAR), - DRV_NAME); + iomem =3D pcim_iomap_region(pdev, PDC_MMIO_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(iomem); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); + host->iomap[PDC_MMIO_BAR] =3D iomem; + + iomem =3D pcim_iomap_region(pdev, PDC_DIMM_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(iomem); + if (rc =3D=3D -EBUSY) + pcim_pin_device(pdev); + if (rc) + return rc; + host->iomap[PDC_DIMM_BAR] =3D iomem; =20 for (i =3D 0; i < 4; i++) { struct ata_port *ap =3D host->ports[i]; diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c index 57cbf2cef618..73b78834fa3f 100644 --- a/drivers/ata/sata_via.c +++ b/drivers/ata/sata_via.c @@ -457,6 +457,7 @@ static int vt6420_prepare_host(struct pci_dev *pdev, st= ruct ata_host **r_host) { const struct ata_port_info *ppi[] =3D { &vt6420_port_info, NULL }; struct ata_host *host; + void __iomem *iomem; int rc; =20 if (vt6420_hotplug) { @@ -469,11 +470,12 @@ static int vt6420_prepare_host(struct pci_dev *pdev, = struct ata_host **r_host) return rc; *r_host =3D host; =20 - rc =3D pcim_iomap_regions(pdev, 1 << 5, DRV_NAME); - if (rc) { + iomem =3D pcim_iomap_region(pdev, 5, DRV_NAME); + if (IS_ERR(iomem)) { dev_err(&pdev->dev, "failed to iomap PCI BAR 5\n"); - return rc; + return PTR_ERR(iomem); } + host->iomap[5] =3D iomem; =20 host->ports[0]->ioaddr.scr_addr =3D svia_scr_addr(host->iomap[5], 0); host->ports[1]->ioaddr.scr_addr =3D svia_scr_addr(host->iomap[5], 1); @@ -486,6 +488,7 @@ static int vt6421_prepare_host(struct pci_dev *pdev, st= ruct ata_host **r_host) const struct ata_port_info *ppi[] =3D { &vt6421_sport_info, &vt6421_sport_info, &vt6421_pport_info }; struct ata_host *host; + void __iomem *iomem; int i, rc; =20 *r_host =3D host =3D ata_host_alloc_pinfo(&pdev->dev, ppi, ARRAY_SIZE(ppi= )); @@ -494,13 +497,17 @@ static int vt6421_prepare_host(struct pci_dev *pdev, = struct ata_host **r_host) return -ENOMEM; } =20 - rc =3D pcim_iomap_regions(pdev, 0x3f, DRV_NAME); - if (rc) { - dev_err(&pdev->dev, "failed to request/iomap PCI BARs (errno=3D%d)\n", - rc); - return rc; + /* Request and ioremap _all_ PCI BARs. */ + for (i =3D 0; i < PCI_STD_NUM_BARS; i++) { + iomem =3D pcim_iomap_region(pdev, i, DRV_NAME); + if (IS_ERR(iomem)) { + rc =3D PTR_ERR(iomem); + dev_err(&pdev->dev, "failed to request/iomap PCI BARs (errno=3D%d)\n", + rc); + return rc; + } + host->iomap[i] =3D iomem; } - host->iomap =3D pcim_iomap_table(pdev); =20 for (i =3D 0; i < host->n_ports; i++) vt6421_init_addrs(host->ports[i]); @@ -519,10 +526,10 @@ static int vt8251_prepare_host(struct pci_dev *pdev, = struct ata_host **r_host) return rc; *r_host =3D host; =20 - rc =3D pcim_iomap_regions(pdev, 1 << 5, DRV_NAME); - if (rc) { + host->iomap[5] =3D pcim_iomap_region(pdev, 5, DRV_NAME); + if (IS_ERR(host->iomap[5])) { dev_err(&pdev->dev, "failed to iomap PCI BAR 5\n"); - return rc; + return PTR_ERR(host->iomap[5]); } =20 /* 8251 hosts four sata ports as M/S of the two channels */ diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c index d39b87537168..2a1c9a9fc558 100644 --- a/drivers/ata/sata_vsc.c +++ b/drivers/ata/sata_vsc.c @@ -349,14 +349,14 @@ static int vsc_sata_init_one(struct pci_dev *pdev, return -ENODEV; =20 /* map IO regions and initialize host accordingly */ - rc =3D pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME); + mmio_base =3D pcim_iomap_region(pdev, VSC_MMIO_BAR, DRV_NAME); + rc =3D PTR_ERR_OR_ZERO(mmio_base); if (rc =3D=3D -EBUSY) pcim_pin_device(pdev); if (rc) return rc; - host->iomap =3D pcim_iomap_table(pdev); =20 - mmio_base =3D host->iomap[VSC_MMIO_BAR]; + host->iomap[VSC_MMIO_BAR] =3D mmio_base; =20 for (i =3D 0; i < host->n_ports; i++) { struct ata_port *ap =3D host->ports[i]; diff --git a/include/linux/libata.h b/include/linux/libata.h index c1a85d46eba6..d12a9627c96e 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -23,6 +23,9 @@ #include #include #include +#ifdef CONFIG_PCI +#include /* for PCI_STD_NUM_BARS */ +#endif /* CONFIG_PCI */ =20 /* * Define if arch has non-standard setup. This is a _PCI_ standard @@ -615,7 +618,9 @@ struct ata_ioports { struct ata_host { spinlock_t lock; struct device *dev; - void __iomem * const *iomap; +#ifdef CONFIG_PCI + void __iomem *iomap[PCI_STD_NUM_BARS]; +#endif /* CONFIG_PCI */ unsigned int n_ports; unsigned int n_tags; /* nr of NCQ tags */ void *private_data; --=20 2.47.1