Skip to content

Commit f5cda25

Browse files
htejunJeff Garzik
authored andcommitted
libata: implement ata_host_alloc_pinfo() and ata_host_register()
Implement ata_host_alloc_pinfo() and ata_host_register(). These helpers will be used in the following patches to adopt new init model. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
1 parent f318719 commit f5cda25

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

drivers/ata/libata-core.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5829,6 +5829,55 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
58295829
return NULL;
58305830
}
58315831

5832+
/**
5833+
* ata_host_alloc_pinfo - alloc host and init with port_info array
5834+
* @dev: generic device this host is associated with
5835+
* @ppi: array of ATA port_info to initialize host with
5836+
* @n_ports: number of ATA ports attached to this host
5837+
*
5838+
* Allocate ATA host and initialize with info from @ppi. If NULL
5839+
* terminated, @ppi may contain fewer entries than @n_ports. The
5840+
* last entry will be used for the remaining ports.
5841+
*
5842+
* RETURNS:
5843+
* Allocate ATA host on success, NULL on failure.
5844+
*
5845+
* LOCKING:
5846+
* Inherited from calling layer (may sleep).
5847+
*/
5848+
struct ata_host *ata_host_alloc_pinfo(struct device *dev,
5849+
const struct ata_port_info * const * ppi,
5850+
int n_ports)
5851+
{
5852+
const struct ata_port_info *pi;
5853+
struct ata_host *host;
5854+
int i, j;
5855+
5856+
host = ata_host_alloc(dev, n_ports);
5857+
if (!host)
5858+
return NULL;
5859+
5860+
for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) {
5861+
struct ata_port *ap = host->ports[i];
5862+
5863+
if (ppi[j])
5864+
pi = ppi[j++];
5865+
5866+
ap->pio_mask = pi->pio_mask;
5867+
ap->mwdma_mask = pi->mwdma_mask;
5868+
ap->udma_mask = pi->udma_mask;
5869+
ap->flags |= pi->flags;
5870+
ap->ops = pi->port_ops;
5871+
5872+
if (!host->ops && (pi->port_ops != &ata_dummy_port_ops))
5873+
host->ops = pi->port_ops;
5874+
if (!host->private_data && pi->private_data)
5875+
host->private_data = pi->private_data;
5876+
}
5877+
5878+
return host;
5879+
}
5880+
58325881
/**
58335882
* ata_host_start - start and freeze ports of an ATA host
58345883
* @host: ATA host to start ports for
@@ -6041,6 +6090,48 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
60416090
return 0;
60426091
}
60436092

6093+
/**
6094+
* ata_host_activate - start host, request IRQ and register it
6095+
* @host: target ATA host
6096+
* @irq: IRQ to request
6097+
* @irq_handler: irq_handler used when requesting IRQ
6098+
* @irq_flags: irq_flags used when requesting IRQ
6099+
* @sht: scsi_host_template to use when registering the host
6100+
*
6101+
* After allocating an ATA host and initializing it, most libata
6102+
* LLDs perform three steps to activate the host - start host,
6103+
* request IRQ and register it. This helper takes necessasry
6104+
* arguments and performs the three steps in one go.
6105+
*
6106+
* LOCKING:
6107+
* Inherited from calling layer (may sleep).
6108+
*
6109+
* RETURNS:
6110+
* 0 on success, -errno otherwise.
6111+
*/
6112+
int ata_host_activate(struct ata_host *host, int irq,
6113+
irq_handler_t irq_handler, unsigned long irq_flags,
6114+
struct scsi_host_template *sht)
6115+
{
6116+
int rc;
6117+
6118+
rc = ata_host_start(host);
6119+
if (rc)
6120+
return rc;
6121+
6122+
rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags,
6123+
dev_driver_string(host->dev), host);
6124+
if (rc)
6125+
return rc;
6126+
6127+
rc = ata_host_register(host, sht);
6128+
/* if failed, just free the IRQ and leave ports alone */
6129+
if (rc)
6130+
devm_free_irq(host->dev, irq, host);
6131+
6132+
return rc;
6133+
}
6134+
60446135
/**
60456136
* ata_device_add - Register hardware device with ATA and SCSI layers
60466137
* @ent: Probe information describing hardware device to be registered
@@ -6547,8 +6638,10 @@ EXPORT_SYMBOL_GPL(ata_std_bios_param);
65476638
EXPORT_SYMBOL_GPL(ata_std_ports);
65486639
EXPORT_SYMBOL_GPL(ata_host_init);
65496640
EXPORT_SYMBOL_GPL(ata_host_alloc);
6641+
EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
65506642
EXPORT_SYMBOL_GPL(ata_host_start);
65516643
EXPORT_SYMBOL_GPL(ata_host_register);
6644+
EXPORT_SYMBOL_GPL(ata_host_activate);
65526645
EXPORT_SYMBOL_GPL(ata_device_add);
65536646
EXPORT_SYMBOL_GPL(ata_host_detach);
65546647
EXPORT_SYMBOL_GPL(ata_sg_init);

include/linux/libata.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,14 @@ extern int ata_pci_device_resume(struct pci_dev *pdev);
734734
extern int ata_pci_clear_simplex(struct pci_dev *pdev);
735735
#endif /* CONFIG_PCI */
736736
extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
737+
extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
738+
const struct ata_port_info * const * ppi, int n_ports);
737739
extern int ata_host_start(struct ata_host *host);
738740
extern int ata_host_register(struct ata_host *host,
739741
struct scsi_host_template *sht);
742+
extern int ata_host_activate(struct ata_host *host, int irq,
743+
irq_handler_t irq_handler, unsigned long irq_flags,
744+
struct scsi_host_template *sht);
740745
extern int ata_device_add(const struct ata_probe_ent *ent);
741746
extern void ata_host_detach(struct ata_host *host);
742747
extern void ata_host_init(struct ata_host *, struct device *,

0 commit comments

Comments
 (0)