2 * libata-sff.c - helper library for PCI IDE BMDMA
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
8 * Copyright 2003-2006 Red Hat, Inc. All rights reserved.
9 * Copyright 2003-2006 Jeff Garzik
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/
35 #include <linux/kernel.h>
36 #include <linux/pci.h>
37 #include <linux/libata.h>
42 * ata_irq_on - Enable interrupts on a port.
43 * @ap: Port on which interrupts are enabled.
45 * Enable interrupts on a legacy IDE device using MMIO or PIO,
46 * wait for idle, clear any pending interrupts.
49 * Inherited from caller.
51 u8 ata_irq_on(struct ata_port *ap)
53 struct ata_ioports *ioaddr = &ap->ioaddr;
57 ap->last_ctl = ap->ctl;
60 iowrite8(ap->ctl, ioaddr->ctl_addr);
61 tmp = ata_wait_idle(ap);
63 ap->ops->irq_clear(ap);
69 * ata_tf_load - send taskfile registers to host controller
70 * @ap: Port to which output is sent
71 * @tf: ATA taskfile register set
73 * Outputs ATA taskfile to standard ATA host controller.
76 * Inherited from caller.
79 void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
81 struct ata_ioports *ioaddr = &ap->ioaddr;
82 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
84 if (tf->ctl != ap->last_ctl) {
86 iowrite8(tf->ctl, ioaddr->ctl_addr);
87 ap->last_ctl = tf->ctl;
91 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
92 WARN_ON(!ioaddr->ctl_addr);
93 iowrite8(tf->hob_feature, ioaddr->feature_addr);
94 iowrite8(tf->hob_nsect, ioaddr->nsect_addr);
95 iowrite8(tf->hob_lbal, ioaddr->lbal_addr);
96 iowrite8(tf->hob_lbam, ioaddr->lbam_addr);
97 iowrite8(tf->hob_lbah, ioaddr->lbah_addr);
98 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
107 iowrite8(tf->feature, ioaddr->feature_addr);
108 iowrite8(tf->nsect, ioaddr->nsect_addr);
109 iowrite8(tf->lbal, ioaddr->lbal_addr);
110 iowrite8(tf->lbam, ioaddr->lbam_addr);
111 iowrite8(tf->lbah, ioaddr->lbah_addr);
112 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
120 if (tf->flags & ATA_TFLAG_DEVICE) {
121 iowrite8(tf->device, ioaddr->device_addr);
122 VPRINTK("device 0x%X\n", tf->device);
129 * ata_exec_command - issue ATA command to host controller
130 * @ap: port to which command is being issued
131 * @tf: ATA taskfile register set
133 * Issues ATA command, with proper synchronization with interrupt
134 * handler / other threads.
137 * spin_lock_irqsave(host lock)
139 void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
141 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
143 iowrite8(tf->command, ap->ioaddr.command_addr);
148 * ata_tf_read - input device's ATA taskfile shadow registers
149 * @ap: Port from which input is read
150 * @tf: ATA taskfile register set for storing input
152 * Reads ATA taskfile registers for currently-selected device
153 * into @tf. Assumes the device has a fully SFF compliant task file
154 * layout and behaviour. If you device does not (eg has a different
155 * status method) then you will need to provide a replacement tf_read
158 * Inherited from caller.
160 void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
162 struct ata_ioports *ioaddr = &ap->ioaddr;
164 tf->command = ata_check_status(ap);
165 tf->feature = ioread8(ioaddr->error_addr);
166 tf->nsect = ioread8(ioaddr->nsect_addr);
167 tf->lbal = ioread8(ioaddr->lbal_addr);
168 tf->lbam = ioread8(ioaddr->lbam_addr);
169 tf->lbah = ioread8(ioaddr->lbah_addr);
170 tf->device = ioread8(ioaddr->device_addr);
172 if (tf->flags & ATA_TFLAG_LBA48) {
173 if (likely(ioaddr->ctl_addr)) {
174 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr);
175 tf->hob_feature = ioread8(ioaddr->error_addr);
176 tf->hob_nsect = ioread8(ioaddr->nsect_addr);
177 tf->hob_lbal = ioread8(ioaddr->lbal_addr);
178 tf->hob_lbam = ioread8(ioaddr->lbam_addr);
179 tf->hob_lbah = ioread8(ioaddr->lbah_addr);
180 iowrite8(tf->ctl, ioaddr->ctl_addr);
181 ap->last_ctl = tf->ctl;
188 * ata_check_status - Read device status reg & clear interrupt
189 * @ap: port where the device is
191 * Reads ATA taskfile status register for currently-selected device
192 * and return its value. This also clears pending interrupts
196 * Inherited from caller.
198 u8 ata_check_status(struct ata_port *ap)
200 return ioread8(ap->ioaddr.status_addr);
204 * ata_altstatus - Read device alternate status reg
205 * @ap: port where the device is
207 * Reads ATA taskfile alternate status register for
208 * currently-selected device and return its value.
210 * Note: may NOT be used as the check_altstatus() entry in
211 * ata_port_operations.
214 * Inherited from caller.
216 u8 ata_altstatus(struct ata_port *ap)
218 if (ap->ops->check_altstatus)
219 return ap->ops->check_altstatus(ap);
221 return ioread8(ap->ioaddr.altstatus_addr);
225 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
226 * @qc: Info associated with this ATA transaction.
229 * spin_lock_irqsave(host lock)
231 void ata_bmdma_setup(struct ata_queued_cmd *qc)
233 struct ata_port *ap = qc->ap;
234 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
237 /* load PRD table addr. */
238 mb(); /* make sure PRD table writes are visible to controller */
239 iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
241 /* specify data direction, triple-check start bit is clear */
242 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
243 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
245 dmactl |= ATA_DMA_WR;
246 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
248 /* issue r/w command */
249 ap->ops->exec_command(ap, &qc->tf);
253 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
254 * @qc: Info associated with this ATA transaction.
257 * spin_lock_irqsave(host lock)
259 void ata_bmdma_start(struct ata_queued_cmd *qc)
261 struct ata_port *ap = qc->ap;
264 /* start host DMA transaction */
265 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
266 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
268 /* Strictly, one may wish to issue an ioread8() here, to
269 * flush the mmio write. However, control also passes
270 * to the hardware at this point, and it will interrupt
271 * us when we are to resume control. So, in effect,
272 * we don't care when the mmio write flushes.
273 * Further, a read of the DMA status register _immediately_
274 * following the write may not be what certain flaky hardware
275 * is expected, so I think it is best to not add a readb()
276 * without first all the MMIO ATA cards/mobos.
277 * Or maybe I'm just being paranoid.
279 * FIXME: The posting of this write means I/O starts are
280 * unneccessarily delayed for MMIO
285 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
286 * @ap: Port associated with this ATA transaction.
288 * Clear interrupt and error flags in DMA status register.
290 * May be used as the irq_clear() entry in ata_port_operations.
293 * spin_lock_irqsave(host lock)
295 void ata_bmdma_irq_clear(struct ata_port *ap)
297 void __iomem *mmio = ap->ioaddr.bmdma_addr;
302 iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS);
306 * ata_noop_irq_clear - Noop placeholder for irq_clear
307 * @ap: Port associated with this ATA transaction.
309 void ata_noop_irq_clear(struct ata_port *ap)
314 * ata_bmdma_status - Read PCI IDE BMDMA status
315 * @ap: Port associated with this ATA transaction.
317 * Read and return BMDMA status register.
319 * May be used as the bmdma_status() entry in ata_port_operations.
322 * spin_lock_irqsave(host lock)
324 u8 ata_bmdma_status(struct ata_port *ap)
326 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
330 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
331 * @qc: Command we are ending DMA for
333 * Clears the ATA_DMA_START flag in the dma control register
335 * May be used as the bmdma_stop() entry in ata_port_operations.
338 * spin_lock_irqsave(host lock)
340 void ata_bmdma_stop(struct ata_queued_cmd *qc)
342 struct ata_port *ap = qc->ap;
343 void __iomem *mmio = ap->ioaddr.bmdma_addr;
345 /* clear start/stop bit */
346 iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
349 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
350 ata_altstatus(ap); /* dummy read */
354 * ata_bmdma_freeze - Freeze BMDMA controller port
355 * @ap: port to freeze
357 * Freeze BMDMA controller port.
360 * Inherited from caller.
362 void ata_bmdma_freeze(struct ata_port *ap)
364 struct ata_ioports *ioaddr = &ap->ioaddr;
367 ap->last_ctl = ap->ctl;
369 if (ioaddr->ctl_addr)
370 iowrite8(ap->ctl, ioaddr->ctl_addr);
372 /* Under certain circumstances, some controllers raise IRQ on
373 * ATA_NIEN manipulation. Also, many controllers fail to mask
374 * previously pending IRQ on ATA_NIEN assertion. Clear it.
378 ap->ops->irq_clear(ap);
382 * ata_bmdma_thaw - Thaw BMDMA controller port
385 * Thaw BMDMA controller port.
388 * Inherited from caller.
390 void ata_bmdma_thaw(struct ata_port *ap)
392 /* clear & re-enable interrupts */
394 ap->ops->irq_clear(ap);
399 * ata_bmdma_drive_eh - Perform EH with given methods for BMDMA controller
400 * @ap: port to handle error for
401 * @prereset: prereset method (can be NULL)
402 * @softreset: softreset method (can be NULL)
403 * @hardreset: hardreset method (can be NULL)
404 * @postreset: postreset method (can be NULL)
406 * Handle error for ATA BMDMA controller. It can handle both
407 * PATA and SATA controllers. Many controllers should be able to
408 * use this EH as-is or with some added handling before and
411 * This function is intended to be used for constructing
412 * ->error_handler callback by low level drivers.
415 * Kernel thread context (may sleep)
417 void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
418 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
419 ata_postreset_fn_t postreset)
421 struct ata_queued_cmd *qc;
425 qc = __ata_qc_from_tag(ap, ap->link.active_tag);
426 if (qc && !(qc->flags & ATA_QCFLAG_FAILED))
429 /* reset PIO HSM and stop DMA engine */
430 spin_lock_irqsave(ap->lock, flags);
432 ap->hsm_task_state = HSM_ST_IDLE;
434 if (qc && (qc->tf.protocol == ATA_PROT_DMA ||
435 qc->tf.protocol == ATAPI_PROT_DMA)) {
438 host_stat = ap->ops->bmdma_status(ap);
440 /* BMDMA controllers indicate host bus error by
441 * setting DMA_ERR bit and timing out. As it wasn't
442 * really a timeout event, adjust error mask and
443 * cancel frozen state.
445 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) {
446 qc->err_mask = AC_ERR_HOST_BUS;
450 ap->ops->bmdma_stop(qc);
455 ap->ops->irq_clear(ap);
457 spin_unlock_irqrestore(ap->lock, flags);
460 ata_eh_thaw_port(ap);
462 /* PIO and DMA engines have been stopped, perform recovery */
463 ata_do_eh(ap, prereset, softreset, hardreset, postreset);
467 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
468 * @ap: port to handle error for
470 * Stock error handler for BMDMA controller.
473 * Kernel thread context (may sleep)
475 void ata_bmdma_error_handler(struct ata_port *ap)
477 ata_reset_fn_t softreset = NULL, hardreset = NULL;
479 if (ap->ioaddr.ctl_addr)
480 softreset = ata_std_softreset;
481 if (sata_scr_valid(&ap->link))
482 hardreset = sata_std_hardreset;
484 ata_bmdma_drive_eh(ap, ata_std_prereset, softreset, hardreset,
489 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for
491 * @qc: internal command to clean up
494 * Kernel thread context (may sleep)
496 void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
498 if (qc->ap->ioaddr.bmdma_addr)
503 * ata_sff_port_start - Set port up for dma.
504 * @ap: Port to initialize
506 * Called just after data structures for each port are
507 * initialized. Allocates space for PRD table if the device
508 * is DMA capable SFF.
510 * May be used as the port_start() entry in ata_port_operations.
513 * Inherited from caller.
516 int ata_sff_port_start(struct ata_port *ap)
518 if (ap->ioaddr.bmdma_addr)
519 return ata_port_start(ap);
525 static int ata_resources_present(struct pci_dev *pdev, int port)
529 /* Check the PCI resources for this channel are enabled */
531 for (i = 0; i < 2; i ++) {
532 if (pci_resource_start(pdev, port + i) == 0 ||
533 pci_resource_len(pdev, port + i) == 0)
540 * ata_pci_init_bmdma - acquire PCI BMDMA resources and init ATA host
541 * @host: target ATA host
543 * Acquire PCI BMDMA resources and initialize @host accordingly.
546 * Inherited from calling layer (may sleep).
549 * 0 on success, -errno otherwise.
551 int ata_pci_init_bmdma(struct ata_host *host)
553 struct device *gdev = host->dev;
554 struct pci_dev *pdev = to_pci_dev(gdev);
557 /* No BAR4 allocation: No DMA */
558 if (pci_resource_start(pdev, 4) == 0)
561 /* TODO: If we get no DMA mask we should fall back to PIO */
562 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
565 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
569 /* request and iomap DMA region */
570 rc = pcim_iomap_regions(pdev, 1 << 4, dev_driver_string(gdev));
572 dev_printk(KERN_ERR, gdev, "failed to request/iomap BAR4\n");
575 host->iomap = pcim_iomap_table(pdev);
577 for (i = 0; i < 2; i++) {
578 struct ata_port *ap = host->ports[i];
579 void __iomem *bmdma = host->iomap[4] + 8 * i;
581 if (ata_port_is_dummy(ap))
584 ap->ioaddr.bmdma_addr = bmdma;
585 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) &&
586 (ioread8(bmdma + 2) & 0x80))
587 host->flags |= ATA_HOST_SIMPLEX;
589 ata_port_desc(ap, "bmdma 0x%llx",
590 (unsigned long long)pci_resource_start(pdev, 4) + 8 * i);
597 * ata_pci_init_sff_host - acquire native PCI ATA resources and init host
598 * @host: target ATA host
600 * Acquire native PCI ATA resources for @host and initialize the
601 * first two ports of @host accordingly. Ports marked dummy are
602 * skipped and allocation failure makes the port dummy.
604 * Note that native PCI resources are valid even for legacy hosts
605 * as we fix up pdev resources array early in boot, so this
606 * function can be used for both native and legacy SFF hosts.
609 * Inherited from calling layer (may sleep).
612 * 0 if at least one port is initialized, -ENODEV if no port is
615 int ata_pci_init_sff_host(struct ata_host *host)
617 struct device *gdev = host->dev;
618 struct pci_dev *pdev = to_pci_dev(gdev);
619 unsigned int mask = 0;
622 /* request, iomap BARs and init port addresses accordingly */
623 for (i = 0; i < 2; i++) {
624 struct ata_port *ap = host->ports[i];
626 void __iomem * const *iomap;
628 if (ata_port_is_dummy(ap))
631 /* Discard disabled ports. Some controllers show
632 * their unused channels this way. Disabled ports are
635 if (!ata_resources_present(pdev, i)) {
636 ap->ops = &ata_dummy_port_ops;
640 rc = pcim_iomap_regions(pdev, 0x3 << base,
641 dev_driver_string(gdev));
643 dev_printk(KERN_WARNING, gdev,
644 "failed to request/iomap BARs for port %d "
645 "(errno=%d)\n", i, rc);
647 pcim_pin_device(pdev);
648 ap->ops = &ata_dummy_port_ops;
651 host->iomap = iomap = pcim_iomap_table(pdev);
653 ap->ioaddr.cmd_addr = iomap[base];
654 ap->ioaddr.altstatus_addr =
655 ap->ioaddr.ctl_addr = (void __iomem *)
656 ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
657 ata_std_ports(&ap->ioaddr);
659 ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
660 (unsigned long long)pci_resource_start(pdev, base),
661 (unsigned long long)pci_resource_start(pdev, base + 1));
667 dev_printk(KERN_ERR, gdev, "no available native port\n");
675 * ata_pci_prepare_sff_host - helper to prepare native PCI ATA host
676 * @pdev: target PCI device
677 * @ppi: array of port_info, must be enough for two ports
678 * @r_host: out argument for the initialized ATA host
680 * Helper to allocate ATA host for @pdev, acquire all native PCI
681 * resources and initialize it accordingly in one go.
684 * Inherited from calling layer (may sleep).
687 * 0 on success, -errno otherwise.
689 int ata_pci_prepare_sff_host(struct pci_dev *pdev,
690 const struct ata_port_info * const * ppi,
691 struct ata_host **r_host)
693 struct ata_host *host;
696 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
699 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
701 dev_printk(KERN_ERR, &pdev->dev,
702 "failed to allocate ATA host\n");
707 rc = ata_pci_init_sff_host(host);
711 /* init DMA related stuff */
712 rc = ata_pci_init_bmdma(host);
716 devres_remove_group(&pdev->dev, NULL);
721 /* This is necessary because PCI and iomap resources are
722 * merged and releasing the top group won't release the
723 * acquired resources if some of those have been acquired
724 * before entering this function.
726 pcim_iounmap_regions(pdev, 0xf);
728 devres_release_group(&pdev->dev, NULL);
733 * ata_pci_activate_sff_host - start SFF host, request IRQ and register it
734 * @host: target SFF ATA host
735 * @irq_handler: irq_handler used when requesting IRQ(s)
736 * @sht: scsi_host_template to use when registering the host
738 * This is the counterpart of ata_host_activate() for SFF ATA
739 * hosts. This separate helper is necessary because SFF hosts
740 * use two separate interrupts in legacy mode.
743 * Inherited from calling layer (may sleep).
746 * 0 on success, -errno otherwise.
748 int ata_pci_activate_sff_host(struct ata_host *host,
749 irq_handler_t irq_handler,
750 struct scsi_host_template *sht)
752 struct device *dev = host->dev;
753 struct pci_dev *pdev = to_pci_dev(dev);
754 const char *drv_name = dev_driver_string(host->dev);
755 int legacy_mode = 0, rc;
757 rc = ata_host_start(host);
761 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
764 /* TODO: What if one channel is in native mode ... */
765 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
766 mask = (1 << 2) | (1 << 0);
767 if ((tmp8 & mask) != mask)
769 #if defined(CONFIG_NO_ATA_LEGACY)
770 /* Some platforms with PCI limits cannot address compat
771 port space. In that case we punt if their firmware has
772 left a device in compatibility mode */
774 printk(KERN_ERR "ata: Compatibility mode ATA is not supported on this platform, skipping.\n");
780 if (!devres_open_group(dev, NULL, GFP_KERNEL))
783 if (!legacy_mode && pdev->irq) {
784 rc = devm_request_irq(dev, pdev->irq, irq_handler,
785 IRQF_SHARED, drv_name, host);
789 ata_port_desc(host->ports[0], "irq %d", pdev->irq);
790 ata_port_desc(host->ports[1], "irq %d", pdev->irq);
791 } else if (legacy_mode) {
792 if (!ata_port_is_dummy(host->ports[0])) {
793 rc = devm_request_irq(dev, ATA_PRIMARY_IRQ(pdev),
794 irq_handler, IRQF_SHARED,
799 ata_port_desc(host->ports[0], "irq %d",
800 ATA_PRIMARY_IRQ(pdev));
803 if (!ata_port_is_dummy(host->ports[1])) {
804 rc = devm_request_irq(dev, ATA_SECONDARY_IRQ(pdev),
805 irq_handler, IRQF_SHARED,
810 ata_port_desc(host->ports[1], "irq %d",
811 ATA_SECONDARY_IRQ(pdev));
815 rc = ata_host_register(host, sht);
818 devres_remove_group(dev, NULL);
820 devres_release_group(dev, NULL);
826 * ata_pci_init_one - Initialize/register PCI IDE host controller
827 * @pdev: Controller to be initialized
828 * @ppi: array of port_info, must be enough for two ports
829 * @sht: scsi_host_template to use when registering the host
831 * This is a helper function which can be called from a driver's
832 * xxx_init_one() probe function if the hardware uses traditional
833 * IDE taskfile registers.
835 * This function calls pci_enable_device(), reserves its register
836 * regions, sets the dma mask, enables bus master mode, and calls
840 * Nobody makes a single channel controller that appears solely as
841 * the secondary legacy port on PCI.
844 * Inherited from PCI layer (may sleep).
847 * Zero on success, negative on errno-based value on error.
849 int ata_pci_init_one(struct pci_dev *pdev,
850 const struct ata_port_info * const * ppi,
851 struct scsi_host_template *sht)
853 struct device *dev = &pdev->dev;
854 const struct ata_port_info *pi = NULL;
855 struct ata_host *host = NULL;
860 /* look up the first valid port_info */
861 for (i = 0; i < 2 && ppi[i]; i++) {
862 if (ppi[i]->port_ops != &ata_dummy_port_ops) {
869 dev_printk(KERN_ERR, &pdev->dev,
870 "no valid port_info specified\n");
874 if (!devres_open_group(dev, NULL, GFP_KERNEL))
877 rc = pcim_enable_device(pdev);
881 /* prepare and activate SFF host */
882 rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
886 pci_set_master(pdev);
887 rc = ata_pci_activate_sff_host(host, ata_interrupt, sht);
890 devres_remove_group(&pdev->dev, NULL);
892 devres_release_group(&pdev->dev, NULL);
898 * ata_pci_clear_simplex - attempt to kick device out of simplex
901 * Some PCI ATA devices report simplex mode but in fact can be told to
902 * enter non simplex mode. This implements the necessary logic to
903 * perform the task on such devices. Calling it on other devices will
904 * have -undefined- behaviour.
907 int ata_pci_clear_simplex(struct pci_dev *pdev)
909 unsigned long bmdma = pci_resource_start(pdev, 4);
915 simplex = inb(bmdma + 0x02);
916 outb(simplex & 0x60, bmdma + 0x02);
917 simplex = inb(bmdma + 0x02);
923 unsigned long ata_pci_default_filter(struct ata_device *adev, unsigned long xfer_mask)
925 /* Filter out DMA modes if the device has been configured by
926 the BIOS as PIO only */
928 if (adev->link->ap->ioaddr.bmdma_addr == NULL)
929 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
933 #endif /* CONFIG_PCI */