@@ -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);
65476638EXPORT_SYMBOL_GPL (ata_std_ports );
65486639EXPORT_SYMBOL_GPL (ata_host_init );
65496640EXPORT_SYMBOL_GPL (ata_host_alloc );
6641+ EXPORT_SYMBOL_GPL (ata_host_alloc_pinfo );
65506642EXPORT_SYMBOL_GPL (ata_host_start );
65516643EXPORT_SYMBOL_GPL (ata_host_register );
6644+ EXPORT_SYMBOL_GPL (ata_host_activate );
65526645EXPORT_SYMBOL_GPL (ata_device_add );
65536646EXPORT_SYMBOL_GPL (ata_host_detach );
65546647EXPORT_SYMBOL_GPL (ata_sg_init );
0 commit comments