···186 ata_wait_idle(ap);187}1880000000000000000000000189void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)190{191 if (ap->flags & ATA_FLAG_MMIO)···217}218219/**220- * ata_exec_command - issue ATA command to host controller221 * @ap: port to which command is being issued222 * @tf: ATA taskfile register set223 *224- * Issues PIO/MMIO write to ATA command register, with proper225 * synchronization with interrupt handler / other threads.226 *227 * LOCKING:···257 ata_pause(ap);258}259000000000000260void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)261{262 if (ap->flags & ATA_FLAG_MMIO)···339}340341/**342- * ata_tf_read - input device's ATA taskfile shadow registers343 * @ap: Port from which input is read344 * @tf: ATA taskfile register set for storing input345 *···402 }403}40400000000000000000405void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)406{407 if (ap->flags & ATA_FLAG_MMIO)···432 * @ap: port where the device is433 *434 * Reads ATA taskfile status register for currently-selected device435- * and return it's value. This also clears pending interrupts436 * from this device437 *438 * LOCKING:···448 * @ap: port where the device is449 *450 * Reads ATA taskfile status register for currently-selected device451- * via MMIO and return it's value. This also clears pending interrupts452 * from this device453 *454 * LOCKING:···459 return readb((void __iomem *) ap->ioaddr.status_addr);460}46100000000000000462u8 ata_check_status(struct ata_port *ap)463{464 if (ap->flags & ATA_FLAG_MMIO)···480 return ata_check_status_pio(ap);481}48200000000000000483u8 ata_altstatus(struct ata_port *ap)484{485 if (ap->ops->check_altstatus)···504 return inb(ap->ioaddr.altstatus_addr);505}50600000000000000507u8 ata_chk_err(struct ata_port *ap)508{509 if (ap->ops->check_err)···966 }967}9680000000000000969void ata_noop_dev_select (struct ata_port *ap, unsigned int device)970{971}0972973/**974 * ata_std_dev_select - Select device 0/1 on ATA bus···991 *992 * Use the method defined in the ATA specification to993 * make either device 0, or device 1, active on the994- * ATA channel.00995 *996 * LOCKING:997 * caller.···2236 * spin_lock_irqsave(host_set lock)2237 */223800000000000002239void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)2240{2241 struct scatterlist *sg;···2278 *2279 * LOCKING:2280 * spin_lock_irqsave(host_set lock)0000000000002281 */22822283void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,···2465 ata_qc_complete(qc, drv_stat);2466}24670000000000002468void swap_buf_le16(u16 *buf, unsigned int buf_words)2469{2470#ifdef __BIG_ENDIAN···3138 return -1;3139}314003141/**3142 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner3143 * @qc: command to issue to device···3147 * starts an ATA command. ATA commands are grouped into3148 * classes called "protocols", and issuing each type of protocol3149 * is slightly different.003150 *3151 * LOCKING:3152 * spin_lock_irqsave(host_set lock)···3207}32083209/**3210- * ata_bmdma_setup - Set up PCI IDE BMDMA transaction3211 * @qc: Info associated with this ATA transaction.3212 *3213 * LOCKING:···3314 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);3315}33160000000000003317void ata_bmdma_start(struct ata_queued_cmd *qc)3318{3319 if (qc->ap->flags & ATA_FLAG_MMIO)···3334 ata_bmdma_start_pio(qc);3335}3336000000000000003337void ata_bmdma_setup(struct ata_queued_cmd *qc)3338{3339 if (qc->ap->flags & ATA_FLAG_MMIO)···3355 else3356 ata_bmdma_setup_pio(qc);3357}000000000000033583359void ata_bmdma_irq_clear(struct ata_port *ap)3360{···33813382}338300000000000003384u8 ata_bmdma_status(struct ata_port *ap)3385{3386 u8 host_stat;···3404 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);3405 return host_stat;3406}000000000000034073408void ata_bmdma_stop(struct ata_port *ap)3409{···3621 ata_qc_complete(qc, ATA_ERR);3622}362300000000000003624int ata_port_start (struct ata_port *ap)3625{3626 struct device *dev = ap->host_set->dev;···36463647 return 0;3648}00000000000036493650void ata_port_stop (struct ata_port *ap)3651{···3959/**3960 * ata_std_ports - initialize ioaddr with standard port offsets.3961 * @ioaddr: IO address structure to be initialized00000003962 */03963void ata_std_ports(struct ata_ioports *ioaddr)3964{3965 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;···40084009 return probe_ent;4010}0000000000000040114012#ifdef CONFIG_PCI4013struct ata_probe_ent *···4103 * @pdev: Controller to be initialized4104 * @port_info: Information from low-level host driver4105 * @n_ports: Number of ports attached to host controller000000004106 *4107 * LOCKING:4108 * Inherited from PCI layer (may sleep).
···186 ata_wait_idle(ap);187}188189+190+/**191+ * ata_tf_load - send taskfile registers to host controller192+ * @ap: Port to which output is sent193+ * @tf: ATA taskfile register set194+ *195+ * Outputs ATA taskfile to standard ATA host controller using MMIO196+ * or PIO as indicated by the ATA_FLAG_MMIO flag.197+ * Writes the control, feature, nsect, lbal, lbam, and lbah registers.198+ * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,199+ * hob_lbal, hob_lbam, and hob_lbah.200+ *201+ * This function waits for idle (!BUSY and !DRQ) after writing202+ * registers. If the control register has a new value, this203+ * function also waits for idle after writing control and before204+ * writing the remaining registers.205+ *206+ * May be used as the tf_load() entry in ata_port_operations.207+ *208+ * LOCKING:209+ * Inherited from caller.210+ */211void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)212{213 if (ap->flags & ATA_FLAG_MMIO)···195}196197/**198+ * ata_exec_command_pio - issue ATA command to host controller199 * @ap: port to which command is being issued200 * @tf: ATA taskfile register set201 *202+ * Issues PIO write to ATA command register, with proper203 * synchronization with interrupt handler / other threads.204 *205 * LOCKING:···235 ata_pause(ap);236}237238+239+/**240+ * ata_exec_command - issue ATA command to host controller241+ * @ap: port to which command is being issued242+ * @tf: ATA taskfile register set243+ *244+ * Issues PIO/MMIO write to ATA command register, with proper245+ * synchronization with interrupt handler / other threads.246+ *247+ * LOCKING:248+ * spin_lock_irqsave(host_set lock)249+ */250void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)251{252 if (ap->flags & ATA_FLAG_MMIO)···305}306307/**308+ * ata_tf_read_pio - input device's ATA taskfile shadow registers309 * @ap: Port from which input is read310 * @tf: ATA taskfile register set for storing input311 *···368 }369}370371+372+/**373+ * ata_tf_read - input device's ATA taskfile shadow registers374+ * @ap: Port from which input is read375+ * @tf: ATA taskfile register set for storing input376+ *377+ * Reads ATA taskfile registers for currently-selected device378+ * into @tf.379+ *380+ * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48381+ * is set, also reads the hob registers.382+ *383+ * May be used as the tf_read() entry in ata_port_operations.384+ *385+ * LOCKING:386+ * Inherited from caller.387+ */388void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)389{390 if (ap->flags & ATA_FLAG_MMIO)···381 * @ap: port where the device is382 *383 * Reads ATA taskfile status register for currently-selected device384+ * and return its value. This also clears pending interrupts385 * from this device386 *387 * LOCKING:···397 * @ap: port where the device is398 *399 * Reads ATA taskfile status register for currently-selected device400+ * via MMIO and return its value. This also clears pending interrupts401 * from this device402 *403 * LOCKING:···408 return readb((void __iomem *) ap->ioaddr.status_addr);409}410411+412+/**413+ * ata_check_status - Read device status reg & clear interrupt414+ * @ap: port where the device is415+ *416+ * Reads ATA taskfile status register for currently-selected device417+ * and return its value. This also clears pending interrupts418+ * from this device419+ *420+ * May be used as the check_status() entry in ata_port_operations.421+ *422+ * LOCKING:423+ * Inherited from caller.424+ */425u8 ata_check_status(struct ata_port *ap)426{427 if (ap->flags & ATA_FLAG_MMIO)···415 return ata_check_status_pio(ap);416}417418+419+/**420+ * ata_altstatus - Read device alternate status reg421+ * @ap: port where the device is422+ *423+ * Reads ATA taskfile alternate status register for424+ * currently-selected device and return its value.425+ *426+ * Note: may NOT be used as the check_altstatus() entry in427+ * ata_port_operations.428+ *429+ * LOCKING:430+ * Inherited from caller.431+ */432u8 ata_altstatus(struct ata_port *ap)433{434 if (ap->ops->check_altstatus)···425 return inb(ap->ioaddr.altstatus_addr);426}427428+429+/**430+ * ata_chk_err - Read device error reg431+ * @ap: port where the device is432+ *433+ * Reads ATA taskfile error register for434+ * currently-selected device and return its value.435+ *436+ * Note: may NOT be used as the check_err() entry in437+ * ata_port_operations.438+ *439+ * LOCKING:440+ * Inherited from caller.441+ */442u8 ata_chk_err(struct ata_port *ap)443{444 if (ap->ops->check_err)···873 }874}875876+877+/**878+ * ata_noop_dev_select - Select device 0/1 on ATA bus879+ * @ap: ATA channel to manipulate880+ * @device: ATA device (numbered from zero) to select881+ *882+ * This function performs no actual function.883+ *884+ * May be used as the dev_select() entry in ata_port_operations.885+ *886+ * LOCKING:887+ * caller.888+ */889void ata_noop_dev_select (struct ata_port *ap, unsigned int device)890{891}892+893894/**895 * ata_std_dev_select - Select device 0/1 on ATA bus···884 *885 * Use the method defined in the ATA specification to886 * make either device 0, or device 1, active on the887+ * ATA channel. Works with both PIO and MMIO.888+ *889+ * May be used as the dev_select() entry in ata_port_operations.890 *891 * LOCKING:892 * caller.···2127 * spin_lock_irqsave(host_set lock)2128 */21292130+2131+2132+/**2133+ * ata_sg_init_one - Prepare a one-entry scatter-gather list.2134+ * @qc: Queued command2135+ * @buf: transfer buffer2136+ * @buflen: length of buf2137+ *2138+ * Builds a single-entry scatter-gather list to initiate a2139+ * transfer utilizing the specified buffer.2140+ *2141+ * LOCKING:2142+ */2143void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)2144{2145 struct scatterlist *sg;···2156 *2157 * LOCKING:2158 * spin_lock_irqsave(host_set lock)2159+ */2160+2161+2162+/**2163+ * ata_sg_init - Assign a scatter gather list to a queued command2164+ * @qc: Queued command2165+ * @sg: Scatter-gather list2166+ * @n_elem: length of sg list2167+ *2168+ * Attaches a scatter-gather list to a queued command.2169+ *2170+ * LOCKING:2171 */21722173void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,···2331 ata_qc_complete(qc, drv_stat);2332}23332334+2335+/**2336+ * swap_buf_le16 -2337+ * @buf: Buffer to swap2338+ * @buf_words: Number of 16-bit words in buffer.2339+ *2340+ * Swap halves of 16-bit words if needed to convert from2341+ * little-endian byte order to native cpu byte order, or2342+ * vice-versa.2343+ *2344+ * LOCKING:2345+ */2346void swap_buf_le16(u16 *buf, unsigned int buf_words)2347{2348#ifdef __BIG_ENDIAN···2992 return -1;2993}29942995+2996/**2997 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner2998 * @qc: command to issue to device···3000 * starts an ATA command. ATA commands are grouped into3001 * classes called "protocols", and issuing each type of protocol3002 * is slightly different.3003+ *3004+ * May be used as the qc_issue() entry in ata_port_operations.3005 *3006 * LOCKING:3007 * spin_lock_irqsave(host_set lock)···3058}30593060/**3061+ * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction3062 * @qc: Info associated with this ATA transaction.3063 *3064 * LOCKING:···3165 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);3166}31673168+3169+/**3170+ * ata_bmdma_start - Start a PCI IDE BMDMA transaction3171+ * @qc: Info associated with this ATA transaction.3172+ *3173+ * Writes the ATA_DMA_START flag to the DMA command register.3174+ *3175+ * May be used as the bmdma_start() entry in ata_port_operations.3176+ *3177+ * LOCKING:3178+ * spin_lock_irqsave(host_set lock)3179+ */3180void ata_bmdma_start(struct ata_queued_cmd *qc)3181{3182 if (qc->ap->flags & ATA_FLAG_MMIO)···3173 ata_bmdma_start_pio(qc);3174}31753176+3177+/**3178+ * ata_bmdma_setup - Set up PCI IDE BMDMA transaction3179+ * @qc: Info associated with this ATA transaction.3180+ *3181+ * Writes address of PRD table to device's PRD Table Address3182+ * register, sets the DMA control register, and calls3183+ * ops->exec_command() to start the transfer.3184+ *3185+ * May be used as the bmdma_setup() entry in ata_port_operations.3186+ *3187+ * LOCKING:3188+ * spin_lock_irqsave(host_set lock)3189+ */3190void ata_bmdma_setup(struct ata_queued_cmd *qc)3191{3192 if (qc->ap->flags & ATA_FLAG_MMIO)···3180 else3181 ata_bmdma_setup_pio(qc);3182}3183+3184+3185+/**3186+ * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.3187+ * @qc: Info associated with this ATA transaction.3188+ *3189+ * Clear interrupt and error flags in DMA status register.3190+ *3191+ * May be used as the irq_clear() entry in ata_port_operations.3192+ *3193+ * LOCKING:3194+ * spin_lock_irqsave(host_set lock)3195+ */31963197void ata_bmdma_irq_clear(struct ata_port *ap)3198{···31933194}31953196+3197+/**3198+ * ata_bmdma_status - Read PCI IDE BMDMA status3199+ * @qc: Info associated with this ATA transaction.3200+ *3201+ * Read and return BMDMA status register.3202+ *3203+ * May be used as the bmdma_status() entry in ata_port_operations.3204+ *3205+ * LOCKING:3206+ * spin_lock_irqsave(host_set lock)3207+ */3208+3209u8 ata_bmdma_status(struct ata_port *ap)3210{3211 u8 host_stat;···3203 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);3204 return host_stat;3205}3206+3207+3208+/**3209+ * ata_bmdma_stop - Stop PCI IDE BMDMA transfer3210+ * @qc: Info associated with this ATA transaction.3211+ *3212+ * Clears the ATA_DMA_START flag in the dma control register3213+ *3214+ * May be used as the bmdma_stop() entry in ata_port_operations.3215+ *3216+ * LOCKING:3217+ * spin_lock_irqsave(host_set lock)3218+ */32193220void ata_bmdma_stop(struct ata_port *ap)3221{···3407 ata_qc_complete(qc, ATA_ERR);3408}34093410+3411+/**3412+ * ata_port_start - Set port up for dma.3413+ * @ap: Port to initialize3414+ *3415+ * Called just after data structures for each port are3416+ * initialized. Allocates space for PRD table.3417+ *3418+ * May be used as the port_start() entry in ata_port_operations.3419+ *3420+ * LOCKING:3421+ */3422+3423int ata_port_start (struct ata_port *ap)3424{3425 struct device *dev = ap->host_set->dev;···34193420 return 0;3421}3422+3423+3424+/**3425+ * ata_port_stop - Undo ata_port_start()3426+ * @ap: Port to shut down3427+ *3428+ * Frees the PRD table.3429+ *3430+ * May be used as the port_stop() entry in ata_port_operations.3431+ *3432+ * LOCKING:3433+ */34343435void ata_port_stop (struct ata_port *ap)3436{···3720/**3721 * ata_std_ports - initialize ioaddr with standard port offsets.3722 * @ioaddr: IO address structure to be initialized3723+ *3724+ * Utility function which initializes data_addr, error_addr,3725+ * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,3726+ * device_addr, status_addr, and command_addr to standard offsets3727+ * relative to cmd_addr.3728+ *3729+ * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.3730 */3731+3732void ata_std_ports(struct ata_ioports *ioaddr)3733{3734 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;···37613762 return probe_ent;3763}3764+3765+3766+3767+/**3768+ * ata_pci_init_native_mode - Initialize native-mode driver3769+ * @pdev: pci device to be initialized3770+ * @port: array[2] of pointers to port info structures.3771+ *3772+ * Utility function which allocates and initializes an3773+ * ata_probe_ent structure for a standard dual-port3774+ * PIO-based IDE controller. The returned ata_probe_ent3775+ * structure can be passed to ata_device_add(). The returned3776+ * ata_probe_ent structure should then be freed with kfree().3777+ */37783779#ifdef CONFIG_PCI3780struct ata_probe_ent *···3842 * @pdev: Controller to be initialized3843 * @port_info: Information from low-level host driver3844 * @n_ports: Number of ports attached to host controller3845+ *3846+ * This is a helper function which can be called from a driver's3847+ * xxx_init_one() probe function if the hardware uses traditional3848+ * IDE taskfile registers.3849+ *3850+ * This function calls pci_enable_device(), reserves its register3851+ * regions, sets the dma mask, enables bus master mode, and calls3852+ * ata_device_add()3853 *3854 * LOCKING:3855 * Inherited from PCI layer (may sleep).
···466 return ap->ops->check_status(ap);467}468469+470+/**471+ * ata_pause - Flush writes and pause 400 nanoseconds.472+ * @ap: Port to wait for.473+ *474+ * LOCKING:475+ * Inherited from caller.476+ */477+478static inline void ata_pause(struct ata_port *ap)479{480 ata_altstatus(ap);481 ndelay(400);482}483+484+485+/**486+ * ata_busy_wait - Wait for a port status register487+ * @ap: Port to wait for.488+ *489+ * Waits up to max*10 microseconds for the selected bits in the port's490+ * status register to be cleared.491+ * Returns final value of status register.492+ *493+ * LOCKING:494+ * Inherited from caller.495+ */496497static inline u8 ata_busy_wait(struct ata_port *ap, unsigned int bits,498 unsigned int max)···485486 return status;487}488+489+490+/**491+ * ata_wait_idle - Wait for a port to be idle.492+ * @ap: Port to wait for.493+ *494+ * Waits up to 10ms for port's BUSY and DRQ signals to clear.495+ * Returns final value of status register.496+ *497+ * LOCKING:498+ * Inherited from caller.499+ */500501static inline u8 ata_wait_idle(struct ata_port *ap)502{···524 tf->device = ATA_DEVICE_OBS | ATA_DEV1;525}526527+528+/**529+ * ata_irq_on - Enable interrupts on a port.530+ * @ap: Port on which interrupts are enabled.531+ *532+ * Enable interrupts on a legacy IDE device using MMIO or PIO,533+ * wait for idle, clear any pending interrupts.534+ *535+ * LOCKING:536+ * Inherited from caller.537+ */538+539static inline u8 ata_irq_on(struct ata_port *ap)540{541 struct ata_ioports *ioaddr = &ap->ioaddr;···542543 return tmp;544}545+546+547+/**548+ * ata_irq_ack - Acknowledge a device interrupt.549+ * @ap: Port on which interrupts are enabled.550+ *551+ * Wait up to 10 ms for legacy IDE device to become idle (BUSY552+ * or BUSY+DRQ clear). Obtain dma status and port status from553+ * device. Clear the interrupt. Return port status.554+ *555+ * LOCKING:556+ */557558static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)559{