From: Jeff Garzik <jgarzik@pobox.com>
To: Tejun Heo <htejun@gmail.com>
Cc: alan@lxorguk.ukuu.org.uk, mlord@pobox.com, albertcc@tw.ibm.com,
uchang@tw.ibm.com, forrest.zhao@intel.com, brking@us.ibm.com,
linux-ide@vger.kernel.org
Subject: Re: [PATCH 7/20] libata: implement PCI ATA init helpers
Date: Tue, 19 Sep 2006 01:29:16 -0400 [thread overview]
Message-ID: <450F802C.9040309@pobox.com> (raw)
In-Reply-To: <11559779711637-git-send-email-htejun@gmail.com>
Tejun Heo wrote:
> +int ata_pci_set_dma_mask(struct pci_dev *pdev, u64 dma_mask,
> + const char **p_reason)
> +{
> + const char *reason;
> + int rc = 0;
> +
> + if (dma_mask == DMA_64BIT_MASK) {
> + if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
> + rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
> + if (rc) {
> + rc = pci_set_consistent_dma_mask(pdev,
> + DMA_32BIT_MASK);
> + if (rc) {
> + reason = "64-bit DMA enable failed";
> + goto err;
> + }
> + }
> + } else {
> + rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
> + if (rc) {
> + reason = "32-bit DMA enable failed";
> + goto err;
> + }
> + rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
> + if (rc) {
> + reason = "32-bit consistent DMA enable failed";
> + goto err;
> + }
> + }
> + } else if (dma_mask) {
> + reason = "failed to set DMA mask";
> + rc = pci_set_dma_mask(pdev, dma_mask);
> + if (rc)
> + goto err;
> + rc = pci_set_consistent_dma_mask(pdev, dma_mask);
> + if (rc)
> + goto err;
> + }
else return -EINVAL, I suppose
> + return 0;
> +
> + err:
> + if (p_reason)
> + *p_reason = reason;
> + return rc;
> +}
> +
> +/**
> + * ata_pci_acquire_resources - acquire default PCI resources
> + * @host: target ATA host to acquire PCI resources for
> + * @dma_mask: DMA mask
> + * @p_reason: out arg for error message (can be NULL)
> + *
> + * Acquire default ATA PCI resources.
> + *
> + * LOCKING:
> + * Inherited from calling layer (may sleep).
> + *
> + * RETURNS:
> + * 0 on success, -errno otherwise.
> + */
> +int ata_pci_acquire_resources(struct ata_host *host, u64 dma_mask,
> + const char **p_reason)
> +{
> + struct pci_dev *pdev = to_pci_dev(host->dev);
> + const char *reason;
> + int rc;
> +
> + /* acquire generic resources */
> +
> + /* FIXME: Really for ATA it isn't safe because the device may
> + * be multi-purpose and we want to leave it alone if it was
> + * already enabled. Secondly for shared use as Arjan says we
> + * want refcounting
> + *
> + * Checking dev->is_enabled is insufficient as this is not set
> + * at boot for the primary video which is BIOS enabled
> + */
> + rc = pci_enable_device(pdev);
> + if (rc) {
> + reason = "failed to enable PCI device";
> + goto err;
> + }
> +
> + rc = pci_request_regions(pdev, DRV_NAME);
> + if (rc) {
> + host->flags |= ATA_HOST_DEV_BUSY;
> + reason = "failed to request PCI regions";
> + goto err;
> + }
> +
> + host->pci_flags |= ATA_PCI_RES_GEN;
> +
> + /* set DMA mask */
> + /* FIXME: If we get no DMA mask we should fall back to PIO */
> + rc = ata_pci_set_dma_mask(pdev, dma_mask, &reason);
> + if (rc)
> + goto err;
> +
> + return 0;
> +
> + err:
> + ata_pci_release_resources(host);
> + if (p_reason)
> + *p_reason = reason;
> + return rc;
> +}
> +
> +/**
> + * ata_pci_release_resources - release default PCI resources
> + * @host: target ATA host to release PCI resources for
> + *
> + * Release default ATA PCI resources.
> + *
> + * LOCKING:
> + * Inherited from calling layer (may sleep).
> + */
> +void ata_pci_release_resources(struct ata_host *host)
> +{
> + struct pci_dev *pdev = to_pci_dev(host->dev);
> +
> + if (host->pci_flags & ATA_PCI_RES_GEN) {
> + pci_release_regions(pdev);
> +
> + if (!(host->flags & ATA_HOST_DEV_BUSY))
> + pci_disable_device(pdev);
> +
> + host->pci_flags &= ~ATA_PCI_RES_GEN;
> + }
> +}
> +
> +/**
> + * ata_pci_init_ports - initialize PCI ATA port addresses
> + * @host: target ATA host
> + *
> + * Initialize native ATA port TF addresses and PCI BMDMA
> + * addresses for both legacy and native ports.
> + *
> + * LOCKING:
> + * Inherited from calling layer.
> + */
> +void ata_pci_init_ports(struct ata_host *host)
> +{
> + struct pci_dev *pdev = to_pci_dev(host->dev);
> + int i;
> +
> + /* initialize native TF and BMDMA */
> + for (i = 0; i < host->n_ports; i++) {
> + struct ata_port *ap = host->ports[i];
> + struct ata_ioports *ioaddr = &ap->ioaddr;
> + unsigned long cmd_addr, ctl_addr, bmdma_addr;
> +
> + cmd_addr = pci_resource_start(pdev, ap->port_no * 2);
> + ctl_addr = pci_resource_start(pdev, ap->port_no * 2 + 1) |
> + ATA_PCI_CTL_OFS;
> + bmdma_addr = pci_resource_start(pdev, 4);
> +
> + if (!((host->legacy_flags & ATA_LEGACY_MASK) & (1 << i))) {
> + ioaddr->cmd_addr = cmd_addr;
> + ioaddr->altstatus_addr = ctl_addr;
> + ioaddr->ctl_addr = ctl_addr;
> + ata_std_ports(ioaddr);
> + }
> +
> + if (bmdma_addr) {
> + bmdma_addr += ap->port_no * 8;
> + if (inb(bmdma_addr + 2) & 0x80)
> + host->flags |= ATA_HOST_SIMPLEX;
> + ioaddr->bmdma_addr = bmdma_addr;
> + }
> + }
> +}
I don't see where the legacy resource handling is?
For PCI devices in legacy, or mixed legacy+native mode, the above code
should be calling into ata-legacy.c to reserve resources.
next prev parent reply other threads:[~2006-09-19 5:29 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-19 8:57 [PATCHSET] libata: implement new initialization model w/ iomap support, take 2 Tejun Heo
2006-08-19 8:59 ` [PATCH 1/20] libata: kill ata_host_stop() Tejun Heo
2006-08-19 14:51 ` Jeff Garzik
2006-08-19 15:29 ` Tejun Heo
2006-09-19 4:46 ` Jeff Garzik
2006-09-19 4:50 ` Tejun Heo
2006-08-19 8:59 ` [PATCH 2/20] libata: implement ata_host_start/stop() Tejun Heo
2006-08-19 8:59 ` [PATCH 6/20] libata: implement legacy ATA init helpers Tejun Heo
2006-09-19 5:26 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 3/20] libata: implement ata_host_detach() and ata_host_free() Tejun Heo
2006-09-19 4:59 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 5/20] libata: implement several LLD init helpers Tejun Heo
2006-08-22 22:11 ` Brian King
2006-08-27 9:52 ` Tejun Heo
2006-08-30 21:16 ` Brian King
2006-09-19 5:16 ` Jeff Garzik
2006-09-19 5:57 ` Tejun Heo
2006-08-19 8:59 ` [PATCH 4/20] libata: separate out ata_host_alloc() and ata_host_attach() Tejun Heo
2006-09-19 5:08 ` Jeff Garzik
2006-09-19 5:48 ` Tejun Heo
2006-08-19 8:59 ` [PATCH 7/20] libata: implement PCI ATA init helpers Tejun Heo
2006-09-19 5:29 ` Jeff Garzik [this message]
2006-08-19 8:59 ` [PATCH 8/20] libata: reimplement ata_pci_init_one() using new " Tejun Heo
2006-09-19 5:32 ` Jeff Garzik
2006-09-19 6:04 ` Tejun Heo
2006-09-19 6:09 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 11/20] libata: use remove_one() for deinit instead of ->host_stop() Tejun Heo
2006-09-19 5:42 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 10/20] libata: reimplement ata_pci_remove_one() using new PCI init helpers Tejun Heo
2006-08-19 8:59 ` [PATCH 13/20] libata: kill unused ->host_stop() operation and related functions Tejun Heo
2006-09-19 5:42 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 12/20] libata: kill old init helpers Tejun Heo
2006-08-19 8:59 ` [PATCH 15/20] libata: move ->irq_handler from port_ops to port_info Tejun Heo
2006-09-19 5:43 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 16/20] libata: make ata_host_alloc() take care of hpriv alloc/free Tejun Heo
2006-09-19 5:45 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 19/20] libata: kill unused ATA_FLAG_MMIO Tejun Heo
2006-08-19 8:59 ` [PATCH 14/20] libata: use LLD name where possible Tejun Heo
2006-09-19 5:43 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 17/20] libata: make ata_pci_acquire_resources() handle iomap Tejun Heo
2006-09-19 5:47 ` Jeff Garzik
2006-09-19 6:27 ` Tejun Heo
2006-09-19 6:32 ` Jeff Garzik
2006-08-19 8:59 ` [PATCH 20/20] libata: move scattered PCI ATA functions into liata-pci.c Tejun Heo
2006-09-19 5:50 ` Jeff Garzik
2006-08-22 22:10 ` [PATCHSET] libata: implement new initialization model w/ iomap support, take 2 Brian King
2006-08-27 10:12 ` Tejun Heo
2006-08-30 20:58 ` Brian King
2006-09-01 13:45 ` Tejun Heo
2006-09-07 13:22 ` Brian King
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=450F802C.9040309@pobox.com \
--to=jgarzik@pobox.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=albertcc@tw.ibm.com \
--cc=brking@us.ibm.com \
--cc=forrest.zhao@intel.com \
--cc=htejun@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=mlord@pobox.com \
--cc=uchang@tw.ibm.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).