xref: /openbmc/linux/drivers/scsi/aic7xxx/aic79xx_osm_pci.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Linux driver attachment glue for PCI based U320 controllers.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2000-2001 Adaptec Inc.
51da177e4SLinus Torvalds  * All rights reserved.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Redistribution and use in source and binary forms, with or without
81da177e4SLinus Torvalds  * modification, are permitted provided that the following conditions
91da177e4SLinus Torvalds  * are met:
101da177e4SLinus Torvalds  * 1. Redistributions of source code must retain the above copyright
111da177e4SLinus Torvalds  *    notice, this list of conditions, and the following disclaimer,
121da177e4SLinus Torvalds  *    without modification.
131da177e4SLinus Torvalds  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
141da177e4SLinus Torvalds  *    substantially similar to the "NO WARRANTY" disclaimer below
151da177e4SLinus Torvalds  *    ("Disclaimer") and any redistribution must be conditioned upon
161da177e4SLinus Torvalds  *    including a substantially similar Disclaimer requirement for further
171da177e4SLinus Torvalds  *    binary redistribution.
181da177e4SLinus Torvalds  * 3. Neither the names of the above-listed copyright holders nor the names
191da177e4SLinus Torvalds  *    of any contributors may be used to endorse or promote products derived
201da177e4SLinus Torvalds  *    from this software without specific prior written permission.
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  * Alternatively, this software may be distributed under the terms of the
231da177e4SLinus Torvalds  * GNU General Public License ("GPL") version 2 as published by the Free
241da177e4SLinus Torvalds  * Software Foundation.
251da177e4SLinus Torvalds  *
261da177e4SLinus Torvalds  * NO WARRANTY
271da177e4SLinus Torvalds  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
281da177e4SLinus Torvalds  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
291da177e4SLinus Torvalds  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
301da177e4SLinus Torvalds  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
311da177e4SLinus Torvalds  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321da177e4SLinus Torvalds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331da177e4SLinus Torvalds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341da177e4SLinus Torvalds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
351da177e4SLinus Torvalds  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
361da177e4SLinus Torvalds  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371da177e4SLinus Torvalds  * POSSIBILITY OF SUCH DAMAGES.
381da177e4SLinus Torvalds  *
391da177e4SLinus Torvalds  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm_pci.c#25 $
401da177e4SLinus Torvalds  */
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds #include "aic79xx_osm.h"
431da177e4SLinus Torvalds #include "aic79xx_inline.h"
441da177e4SLinus Torvalds #include "aic79xx_pci.h"
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /* Define the macro locally since it's different for different class of chips.
471da177e4SLinus Torvalds  */
481da177e4SLinus Torvalds #define ID(x)		 \
491da177e4SLinus Torvalds 	ID2C(x),	 \
501da177e4SLinus Torvalds 	ID2C(IDIROC(x))
511da177e4SLinus Torvalds 
52980b306aSDenys Vlasenko static const struct pci_device_id ahd_linux_pci_id_table[] = {
531da177e4SLinus Torvalds 	/* aic7901 based controllers */
541da177e4SLinus Torvalds 	ID(ID_AHA_29320A),
551da177e4SLinus Torvalds 	ID(ID_AHA_29320ALP),
56d32adcb8SSalyzyn, Mark 	ID(ID_AHA_29320LPE),
571da177e4SLinus Torvalds 	/* aic7902 based controllers */
581da177e4SLinus Torvalds 	ID(ID_AHA_29320),
591da177e4SLinus Torvalds 	ID(ID_AHA_29320B),
601da177e4SLinus Torvalds 	ID(ID_AHA_29320LP),
611da177e4SLinus Torvalds 	ID(ID_AHA_39320),
621da177e4SLinus Torvalds 	ID(ID_AHA_39320_B),
631da177e4SLinus Torvalds 	ID(ID_AHA_39320A),
641da177e4SLinus Torvalds 	ID(ID_AHA_39320D),
651da177e4SLinus Torvalds 	ID(ID_AHA_39320D_HP),
661da177e4SLinus Torvalds 	ID(ID_AHA_39320D_B),
671da177e4SLinus Torvalds 	ID(ID_AHA_39320D_B_HP),
681da177e4SLinus Torvalds 	/* Generic chip probes for devices we don't know exactly. */
691da177e4SLinus Torvalds 	ID16(ID_AIC7901 & ID_9005_GENERIC_MASK),
701da177e4SLinus Torvalds 	ID(ID_AIC7901A & ID_DEV_VENDOR_MASK),
711da177e4SLinus Torvalds 	ID16(ID_AIC7902 & ID_9005_GENERIC_MASK),
721da177e4SLinus Torvalds 	{ 0 }
731da177e4SLinus Torvalds };
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
761da177e4SLinus Torvalds 
77*ec199a8dSVaibhav Gupta static int __maybe_unused
ahd_linux_pci_dev_suspend(struct device * dev)78*ec199a8dSVaibhav Gupta ahd_linux_pci_dev_suspend(struct device *dev)
79b5720729SHannes Reinecke {
80*ec199a8dSVaibhav Gupta 	struct ahd_softc *ahd = dev_get_drvdata(dev);
81b5720729SHannes Reinecke 	int rc;
82b5720729SHannes Reinecke 
83b5720729SHannes Reinecke 	if ((rc = ahd_suspend(ahd)))
84b5720729SHannes Reinecke 		return rc;
85b5720729SHannes Reinecke 
86b5720729SHannes Reinecke 	ahd_pci_suspend(ahd);
87b5720729SHannes Reinecke 
88b5720729SHannes Reinecke 	return rc;
89b5720729SHannes Reinecke }
90b5720729SHannes Reinecke 
91*ec199a8dSVaibhav Gupta static int __maybe_unused
ahd_linux_pci_dev_resume(struct device * dev)92*ec199a8dSVaibhav Gupta ahd_linux_pci_dev_resume(struct device *dev)
93b5720729SHannes Reinecke {
94*ec199a8dSVaibhav Gupta 	struct ahd_softc *ahd = dev_get_drvdata(dev);
95b5720729SHannes Reinecke 
96b5720729SHannes Reinecke 	ahd_pci_resume(ahd);
97b5720729SHannes Reinecke 
98b5720729SHannes Reinecke 	ahd_resume(ahd);
99b5720729SHannes Reinecke 
100*ec199a8dSVaibhav Gupta 	return 0;
101b5720729SHannes Reinecke }
102b5720729SHannes Reinecke 
1031da177e4SLinus Torvalds static void
ahd_linux_pci_dev_remove(struct pci_dev * pdev)1041da177e4SLinus Torvalds ahd_linux_pci_dev_remove(struct pci_dev *pdev)
1051da177e4SLinus Torvalds {
10685a46523SChristoph Hellwig 	struct ahd_softc *ahd = pci_get_drvdata(pdev);
1071da177e4SLinus Torvalds 	u_long s;
1081da177e4SLinus Torvalds 
10997af50f6SJames Bottomley 	if (ahd->platform_data && ahd->platform_data->host)
11097af50f6SJames Bottomley 			scsi_remove_host(ahd->platform_data->host);
11197af50f6SJames Bottomley 
1121da177e4SLinus Torvalds 	ahd_lock(ahd, &s);
1131da177e4SLinus Torvalds 	ahd_intr_enable(ahd, FALSE);
1141da177e4SLinus Torvalds 	ahd_unlock(ahd, &s);
1151da177e4SLinus Torvalds 	ahd_free(ahd);
11685a46523SChristoph Hellwig }
11785a46523SChristoph Hellwig 
11885a46523SChristoph Hellwig static void
ahd_linux_pci_inherit_flags(struct ahd_softc * ahd)11985a46523SChristoph Hellwig ahd_linux_pci_inherit_flags(struct ahd_softc *ahd)
12085a46523SChristoph Hellwig {
12185a46523SChristoph Hellwig 	struct pci_dev *pdev = ahd->dev_softc, *master_pdev;
12285a46523SChristoph Hellwig 	unsigned int master_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
12385a46523SChristoph Hellwig 
12485a46523SChristoph Hellwig 	master_pdev = pci_get_slot(pdev->bus, master_devfn);
12585a46523SChristoph Hellwig 	if (master_pdev) {
12685a46523SChristoph Hellwig 		struct ahd_softc *master = pci_get_drvdata(master_pdev);
12785a46523SChristoph Hellwig 		if (master) {
12885a46523SChristoph Hellwig 			ahd->flags &= ~AHD_BIOS_ENABLED;
12985a46523SChristoph Hellwig 			ahd->flags |= master->flags & AHD_BIOS_ENABLED;
1301da177e4SLinus Torvalds 		} else
13185a46523SChristoph Hellwig 			printk(KERN_ERR "aic79xx: no multichannel peer found!\n");
13285a46523SChristoph Hellwig 		pci_dev_put(master_pdev);
13385a46523SChristoph Hellwig 	}
1341da177e4SLinus Torvalds }
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds static int
ahd_linux_pci_dev_probe(struct pci_dev * pdev,const struct pci_device_id * ent)1371da177e4SLinus Torvalds ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1381da177e4SLinus Torvalds {
1391da177e4SLinus Torvalds 	char		 buf[80];
1401da177e4SLinus Torvalds 	struct		 ahd_softc *ahd;
1411da177e4SLinus Torvalds 	ahd_dev_softc_t	 pci;
142980b306aSDenys Vlasenko 	const struct ahd_pci_identity *entry;
1431da177e4SLinus Torvalds 	char		*name;
1441da177e4SLinus Torvalds 	int		 error;
14519966769SHannes Reinecke 	struct device	*dev = &pdev->dev;
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	pci = pdev;
1481da177e4SLinus Torvalds 	entry = ahd_find_pci_device(pci);
1491da177e4SLinus Torvalds 	if (entry == NULL)
1501da177e4SLinus Torvalds 		return (-ENODEV);
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds 	/*
1531da177e4SLinus Torvalds 	 * Allocate a softc for this card and
1541da177e4SLinus Torvalds 	 * set it up for attachment by our
1551da177e4SLinus Torvalds 	 * common detect routine.
1561da177e4SLinus Torvalds 	 */
1571da177e4SLinus Torvalds 	sprintf(buf, "ahd_pci:%d:%d:%d",
1581da177e4SLinus Torvalds 		ahd_get_pci_bus(pci),
1591da177e4SLinus Torvalds 		ahd_get_pci_slot(pci),
1601da177e4SLinus Torvalds 		ahd_get_pci_function(pci));
1611f3d2d9eSHimangi Saraogi 	name = kstrdup(buf, GFP_ATOMIC);
1621da177e4SLinus Torvalds 	if (name == NULL)
1631da177e4SLinus Torvalds 		return (-ENOMEM);
1641da177e4SLinus Torvalds 	ahd = ahd_alloc(NULL, name);
1651da177e4SLinus Torvalds 	if (ahd == NULL)
1661da177e4SLinus Torvalds 		return (-ENOMEM);
1671da177e4SLinus Torvalds 	if (pci_enable_device(pdev)) {
1681da177e4SLinus Torvalds 		ahd_free(ahd);
1691da177e4SLinus Torvalds 		return (-ENODEV);
1701da177e4SLinus Torvalds 	}
1711da177e4SLinus Torvalds 	pci_set_master(pdev);
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds 	if (sizeof(dma_addr_t) > 4) {
17419966769SHannes Reinecke 		const u64 required_mask = dma_get_required_mask(dev);
1751da177e4SLinus Torvalds 
1766afd142fSYang Hongyang 		if (required_mask > DMA_BIT_MASK(39) &&
1776a35528aSYang Hongyang 		    dma_set_mask(dev, DMA_BIT_MASK(64)) == 0)
1781da177e4SLinus Torvalds 			ahd->flags |= AHD_64BIT_ADDRESSING;
179284901a9SYang Hongyang 		else if (required_mask > DMA_BIT_MASK(32) &&
1806afd142fSYang Hongyang 			 dma_set_mask(dev, DMA_BIT_MASK(39)) == 0)
1811da177e4SLinus Torvalds 			ahd->flags |= AHD_39BIT_ADDRESSING;
18219966769SHannes Reinecke 		else
183284901a9SYang Hongyang 			dma_set_mask(dev, DMA_BIT_MASK(32));
1841da177e4SLinus Torvalds 	} else {
185284901a9SYang Hongyang 		dma_set_mask(dev, DMA_BIT_MASK(32));
1861da177e4SLinus Torvalds 	}
1871da177e4SLinus Torvalds 	ahd->dev_softc = pci;
1881da177e4SLinus Torvalds 	error = ahd_pci_config(ahd, entry);
1891da177e4SLinus Torvalds 	if (error != 0) {
1901da177e4SLinus Torvalds 		ahd_free(ahd);
1911da177e4SLinus Torvalds 		return (-error);
1921da177e4SLinus Torvalds 	}
19385a46523SChristoph Hellwig 
19485a46523SChristoph Hellwig 	/*
19585a46523SChristoph Hellwig 	 * Second Function PCI devices need to inherit some
19685a46523SChristoph Hellwig 	 * * settings from function 0.
19785a46523SChristoph Hellwig 	 */
19885a46523SChristoph Hellwig 	if ((ahd->features & AHD_MULTI_FUNC) && PCI_FUNC(pdev->devfn) != 0)
19985a46523SChristoph Hellwig 		ahd_linux_pci_inherit_flags(ahd);
20085a46523SChristoph Hellwig 
2011da177e4SLinus Torvalds 	pci_set_drvdata(pdev, ahd);
20285a46523SChristoph Hellwig 
2031da177e4SLinus Torvalds 	ahd_linux_register_host(ahd, &aic79xx_driver_template);
2041da177e4SLinus Torvalds 	return (0);
2051da177e4SLinus Torvalds }
2061da177e4SLinus Torvalds 
207*ec199a8dSVaibhav Gupta static SIMPLE_DEV_PM_OPS(ahd_linux_pci_dev_pm_ops,
208*ec199a8dSVaibhav Gupta 			 ahd_linux_pci_dev_suspend,
209*ec199a8dSVaibhav Gupta 			 ahd_linux_pci_dev_resume);
210*ec199a8dSVaibhav Gupta 
21167eb6336SFUJITA Tomonori static struct pci_driver aic79xx_pci_driver = {
21267eb6336SFUJITA Tomonori 	.name		= "aic79xx",
21367eb6336SFUJITA Tomonori 	.probe		= ahd_linux_pci_dev_probe,
214*ec199a8dSVaibhav Gupta 	.driver.pm	= &ahd_linux_pci_dev_pm_ops,
21567eb6336SFUJITA Tomonori 	.remove		= ahd_linux_pci_dev_remove,
21667eb6336SFUJITA Tomonori 	.id_table	= ahd_linux_pci_id_table
21767eb6336SFUJITA Tomonori };
21867eb6336SFUJITA Tomonori 
2191da177e4SLinus Torvalds int
ahd_linux_pci_init(void)2201da177e4SLinus Torvalds ahd_linux_pci_init(void)
2211da177e4SLinus Torvalds {
222dcbccbdeSHenrik Kretzschmar 	return pci_register_driver(&aic79xx_pci_driver);
2231da177e4SLinus Torvalds }
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds void
ahd_linux_pci_exit(void)2261da177e4SLinus Torvalds ahd_linux_pci_exit(void)
2271da177e4SLinus Torvalds {
2281da177e4SLinus Torvalds 	pci_unregister_driver(&aic79xx_pci_driver);
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds static int
ahd_linux_pci_reserve_io_regions(struct ahd_softc * ahd,resource_size_t * base,resource_size_t * base2)2328911c9e3SSergei Shtylyov ahd_linux_pci_reserve_io_regions(struct ahd_softc *ahd, resource_size_t *base,
2338911c9e3SSergei Shtylyov 				 resource_size_t *base2)
2341da177e4SLinus Torvalds {
2351da177e4SLinus Torvalds 	*base = pci_resource_start(ahd->dev_softc, 0);
2361da177e4SLinus Torvalds 	/*
2371da177e4SLinus Torvalds 	 * This is really the 3rd bar and should be at index 2,
2381da177e4SLinus Torvalds 	 * but the Linux PCI code doesn't know how to "count" 64bit
2391da177e4SLinus Torvalds 	 * bars.
2401da177e4SLinus Torvalds 	 */
2411da177e4SLinus Torvalds 	*base2 = pci_resource_start(ahd->dev_softc, 3);
2421da177e4SLinus Torvalds 	if (*base == 0 || *base2 == 0)
2431da177e4SLinus Torvalds 		return (ENOMEM);
24453467e63SHannes Reinecke 	if (!request_region(*base, 256, "aic79xx"))
2451da177e4SLinus Torvalds 		return (ENOMEM);
24653467e63SHannes Reinecke 	if (!request_region(*base2, 256, "aic79xx")) {
24753467e63SHannes Reinecke 		release_region(*base, 256);
2481da177e4SLinus Torvalds 		return (ENOMEM);
2491da177e4SLinus Torvalds 	}
2501da177e4SLinus Torvalds 	return (0);
2511da177e4SLinus Torvalds }
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds static int
ahd_linux_pci_reserve_mem_region(struct ahd_softc * ahd,resource_size_t * bus_addr,uint8_t __iomem ** maddr)2541da177e4SLinus Torvalds ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
2558911c9e3SSergei Shtylyov 				 resource_size_t *bus_addr,
2561da177e4SLinus Torvalds 				 uint8_t __iomem **maddr)
2571da177e4SLinus Torvalds {
2588911c9e3SSergei Shtylyov 	resource_size_t	start;
2598911c9e3SSergei Shtylyov 	resource_size_t	base_page;
2601da177e4SLinus Torvalds 	u_long	base_offset;
26153467e63SHannes Reinecke 	int	error = 0;
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds 	if (aic79xx_allow_memio == 0)
2641da177e4SLinus Torvalds 		return (ENOMEM);
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds 	if ((ahd->bugs & AHD_PCIX_MMAPIO_BUG) != 0)
2671da177e4SLinus Torvalds 		return (ENOMEM);
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds 	start = pci_resource_start(ahd->dev_softc, 1);
2701da177e4SLinus Torvalds 	base_page = start & PAGE_MASK;
2711da177e4SLinus Torvalds 	base_offset = start - base_page;
2721da177e4SLinus Torvalds 	if (start != 0) {
2731da177e4SLinus Torvalds 		*bus_addr = start;
27453467e63SHannes Reinecke 		if (!request_mem_region(start, 0x1000, "aic79xx"))
2751da177e4SLinus Torvalds 			error = ENOMEM;
27653467e63SHannes Reinecke 		if (!error) {
2774bdc0d67SChristoph Hellwig 			*maddr = ioremap(base_page, base_offset + 512);
2781da177e4SLinus Torvalds 			if (*maddr == NULL) {
2791da177e4SLinus Torvalds 				error = ENOMEM;
2801da177e4SLinus Torvalds 				release_mem_region(start, 0x1000);
2811da177e4SLinus Torvalds 			} else
2821da177e4SLinus Torvalds 				*maddr += base_offset;
2831da177e4SLinus Torvalds 		}
2841da177e4SLinus Torvalds 	} else
2851da177e4SLinus Torvalds 		error = ENOMEM;
2861da177e4SLinus Torvalds 	return (error);
2871da177e4SLinus Torvalds }
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds int
ahd_pci_map_registers(struct ahd_softc * ahd)2901da177e4SLinus Torvalds ahd_pci_map_registers(struct ahd_softc *ahd)
2911da177e4SLinus Torvalds {
2921da177e4SLinus Torvalds 	uint32_t command;
2938911c9e3SSergei Shtylyov 	resource_size_t base;
2941da177e4SLinus Torvalds 	uint8_t	__iomem *maddr;
2951da177e4SLinus Torvalds 	int	 error;
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds 	/*
2981da177e4SLinus Torvalds 	 * If its allowed, we prefer memory mapped access.
2991da177e4SLinus Torvalds 	 */
3001da177e4SLinus Torvalds 	command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, 4);
3011da177e4SLinus Torvalds 	command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
3021da177e4SLinus Torvalds 	base = 0;
3031da177e4SLinus Torvalds 	maddr = NULL;
3041da177e4SLinus Torvalds 	error = ahd_linux_pci_reserve_mem_region(ahd, &base, &maddr);
3051da177e4SLinus Torvalds 	if (error == 0) {
3061da177e4SLinus Torvalds 		ahd->platform_data->mem_busaddr = base;
3071da177e4SLinus Torvalds 		ahd->tags[0] = BUS_SPACE_MEMIO;
3081da177e4SLinus Torvalds 		ahd->bshs[0].maddr = maddr;
3091da177e4SLinus Torvalds 		ahd->tags[1] = BUS_SPACE_MEMIO;
3101da177e4SLinus Torvalds 		ahd->bshs[1].maddr = maddr + 0x100;
3111da177e4SLinus Torvalds 		ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
3121da177e4SLinus Torvalds 				     command | PCIM_CMD_MEMEN, 4);
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 		if (ahd_pci_test_register_access(ahd) != 0) {
3151da177e4SLinus Torvalds 
31648813cf9SPekka Enberg 			printk("aic79xx: PCI Device %d:%d:%d "
3171da177e4SLinus Torvalds 			       "failed memory mapped test.  Using PIO.\n",
3181da177e4SLinus Torvalds 			       ahd_get_pci_bus(ahd->dev_softc),
3191da177e4SLinus Torvalds 			       ahd_get_pci_slot(ahd->dev_softc),
3201da177e4SLinus Torvalds 			       ahd_get_pci_function(ahd->dev_softc));
3211da177e4SLinus Torvalds 			iounmap(maddr);
3221da177e4SLinus Torvalds 			release_mem_region(ahd->platform_data->mem_busaddr,
3231da177e4SLinus Torvalds 					   0x1000);
3241da177e4SLinus Torvalds 			ahd->bshs[0].maddr = NULL;
3251da177e4SLinus Torvalds 			maddr = NULL;
3261da177e4SLinus Torvalds 		} else
3271da177e4SLinus Torvalds 			command |= PCIM_CMD_MEMEN;
3281da177e4SLinus Torvalds 	} else if (bootverbose) {
32948813cf9SPekka Enberg 		printk("aic79xx: PCI%d:%d:%d MEM region 0x%llx "
3301da177e4SLinus Torvalds 		       "unavailable. Cannot memory map device.\n",
3311da177e4SLinus Torvalds 		       ahd_get_pci_bus(ahd->dev_softc),
3321da177e4SLinus Torvalds 		       ahd_get_pci_slot(ahd->dev_softc),
3331da177e4SLinus Torvalds 		       ahd_get_pci_function(ahd->dev_softc),
3348911c9e3SSergei Shtylyov 		       (unsigned long long)base);
3351da177e4SLinus Torvalds 	}
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 	if (maddr == NULL) {
3388911c9e3SSergei Shtylyov 		resource_size_t base2;
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds 		error = ahd_linux_pci_reserve_io_regions(ahd, &base, &base2);
3411da177e4SLinus Torvalds 		if (error == 0) {
3421da177e4SLinus Torvalds 			ahd->tags[0] = BUS_SPACE_PIO;
3431da177e4SLinus Torvalds 			ahd->tags[1] = BUS_SPACE_PIO;
3448911c9e3SSergei Shtylyov 			ahd->bshs[0].ioport = (u_long)base;
3458911c9e3SSergei Shtylyov 			ahd->bshs[1].ioport = (u_long)base2;
3461da177e4SLinus Torvalds 			command |= PCIM_CMD_PORTEN;
3471da177e4SLinus Torvalds 		} else {
34848813cf9SPekka Enberg 			printk("aic79xx: PCI%d:%d:%d IO regions 0x%llx and "
3498911c9e3SSergei Shtylyov 			       "0x%llx unavailable. Cannot map device.\n",
3501da177e4SLinus Torvalds 			       ahd_get_pci_bus(ahd->dev_softc),
3511da177e4SLinus Torvalds 			       ahd_get_pci_slot(ahd->dev_softc),
3521da177e4SLinus Torvalds 			       ahd_get_pci_function(ahd->dev_softc),
3538911c9e3SSergei Shtylyov 			       (unsigned long long)base,
3548911c9e3SSergei Shtylyov 			       (unsigned long long)base2);
3551da177e4SLinus Torvalds 		}
3561da177e4SLinus Torvalds 	}
3571da177e4SLinus Torvalds 	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, 4);
3581da177e4SLinus Torvalds 	return (error);
3591da177e4SLinus Torvalds }
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds int
ahd_pci_map_int(struct ahd_softc * ahd)3621da177e4SLinus Torvalds ahd_pci_map_int(struct ahd_softc *ahd)
3631da177e4SLinus Torvalds {
3641da177e4SLinus Torvalds 	int error;
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	error = request_irq(ahd->dev_softc->irq, ahd_linux_isr,
3671d6f359aSThomas Gleixner 			    IRQF_SHARED, "aic79xx", ahd);
36853467e63SHannes Reinecke 	if (!error)
3691da177e4SLinus Torvalds 		ahd->platform_data->irq = ahd->dev_softc->irq;
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds 	return (-error);
3721da177e4SLinus Torvalds }
3731da177e4SLinus Torvalds 
3741da177e4SLinus Torvalds void
ahd_power_state_change(struct ahd_softc * ahd,ahd_power_state new_state)3751da177e4SLinus Torvalds ahd_power_state_change(struct ahd_softc *ahd, ahd_power_state new_state)
3761da177e4SLinus Torvalds {
3771da177e4SLinus Torvalds 	pci_set_power_state(ahd->dev_softc, new_state);
3781da177e4SLinus Torvalds }
379