11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Linux driver attachment glue for PCI based 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/aic7xxx_osm_pci.c#47 $ 401da177e4SLinus Torvalds */ 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #include "aic7xxx_osm.h" 431da177e4SLinus Torvalds #include "aic7xxx_pci.h" 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* Define the macro locally since it's different for different class of chips. 461da177e4SLinus Torvalds */ 471da177e4SLinus Torvalds #define ID(x) ID_C(x, PCI_CLASS_STORAGE_SCSI) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds static struct pci_device_id ahc_linux_pci_id_table[] = { 501da177e4SLinus Torvalds /* aic7850 based controllers */ 511da177e4SLinus Torvalds ID(ID_AHA_2902_04_10_15_20C_30C), 521da177e4SLinus Torvalds /* aic7860 based controllers */ 531da177e4SLinus Torvalds ID(ID_AHA_2930CU), 541da177e4SLinus Torvalds ID(ID_AHA_1480A & ID_DEV_VENDOR_MASK), 551da177e4SLinus Torvalds ID(ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK), 561da177e4SLinus Torvalds ID(ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK), 571da177e4SLinus Torvalds ID(ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK), 581da177e4SLinus Torvalds /* aic7870 based controllers */ 591da177e4SLinus Torvalds ID(ID_AHA_2940), 601da177e4SLinus Torvalds ID(ID_AHA_3940), 611da177e4SLinus Torvalds ID(ID_AHA_398X), 621da177e4SLinus Torvalds ID(ID_AHA_2944), 631da177e4SLinus Torvalds ID(ID_AHA_3944), 641da177e4SLinus Torvalds ID(ID_AHA_4944), 651da177e4SLinus Torvalds /* aic7880 based controllers */ 661da177e4SLinus Torvalds ID(ID_AHA_2940U & ID_DEV_VENDOR_MASK), 671da177e4SLinus Torvalds ID(ID_AHA_3940U & ID_DEV_VENDOR_MASK), 681da177e4SLinus Torvalds ID(ID_AHA_2944U & ID_DEV_VENDOR_MASK), 691da177e4SLinus Torvalds ID(ID_AHA_3944U & ID_DEV_VENDOR_MASK), 701da177e4SLinus Torvalds ID(ID_AHA_398XU & ID_DEV_VENDOR_MASK), 711da177e4SLinus Torvalds ID(ID_AHA_4944U & ID_DEV_VENDOR_MASK), 721da177e4SLinus Torvalds ID(ID_AHA_2930U & ID_DEV_VENDOR_MASK), 731da177e4SLinus Torvalds ID(ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK), 741da177e4SLinus Torvalds ID(ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK), 751da177e4SLinus Torvalds /* aic7890 based controllers */ 761da177e4SLinus Torvalds ID(ID_AHA_2930U2), 771da177e4SLinus Torvalds ID(ID_AHA_2940U2B), 781da177e4SLinus Torvalds ID(ID_AHA_2940U2_OEM), 791da177e4SLinus Torvalds ID(ID_AHA_2940U2), 801da177e4SLinus Torvalds ID(ID_AHA_2950U2B), 811da177e4SLinus Torvalds ID16(ID_AIC7890_ARO & ID_AIC7895_ARO_MASK), 821da177e4SLinus Torvalds ID(ID_AAA_131U2), 831da177e4SLinus Torvalds /* aic7890 based controllers */ 841da177e4SLinus Torvalds ID(ID_AHA_29160), 851da177e4SLinus Torvalds ID(ID_AHA_29160_CPQ), 861da177e4SLinus Torvalds ID(ID_AHA_29160N), 871da177e4SLinus Torvalds ID(ID_AHA_29160C), 881da177e4SLinus Torvalds ID(ID_AHA_29160B), 891da177e4SLinus Torvalds ID(ID_AHA_19160B), 901da177e4SLinus Torvalds ID(ID_AIC7892_ARO), 911da177e4SLinus Torvalds /* aic7892 based controllers */ 921da177e4SLinus Torvalds ID(ID_AHA_2940U_DUAL), 931da177e4SLinus Torvalds ID(ID_AHA_3940AU), 941da177e4SLinus Torvalds ID(ID_AHA_3944AU), 951da177e4SLinus Torvalds ID(ID_AIC7895_ARO), 961da177e4SLinus Torvalds ID(ID_AHA_3950U2B_0), 971da177e4SLinus Torvalds ID(ID_AHA_3950U2B_1), 981da177e4SLinus Torvalds ID(ID_AHA_3950U2D_0), 991da177e4SLinus Torvalds ID(ID_AHA_3950U2D_1), 1001da177e4SLinus Torvalds ID(ID_AIC7896_ARO), 1011da177e4SLinus Torvalds /* aic7899 based controllers */ 1021da177e4SLinus Torvalds ID(ID_AHA_3960D), 1031da177e4SLinus Torvalds ID(ID_AHA_3960D_CPQ), 1041da177e4SLinus Torvalds ID(ID_AIC7899_ARO), 1051da177e4SLinus Torvalds /* Generic chip probes for devices we don't know exactly. */ 1061da177e4SLinus Torvalds ID(ID_AIC7850 & ID_DEV_VENDOR_MASK), 1071da177e4SLinus Torvalds ID(ID_AIC7855 & ID_DEV_VENDOR_MASK), 1081da177e4SLinus Torvalds ID(ID_AIC7859 & ID_DEV_VENDOR_MASK), 1091da177e4SLinus Torvalds ID(ID_AIC7860 & ID_DEV_VENDOR_MASK), 1101da177e4SLinus Torvalds ID(ID_AIC7870 & ID_DEV_VENDOR_MASK), 1111da177e4SLinus Torvalds ID(ID_AIC7880 & ID_DEV_VENDOR_MASK), 1121da177e4SLinus Torvalds ID16(ID_AIC7890 & ID_9005_GENERIC_MASK), 1131da177e4SLinus Torvalds ID16(ID_AIC7892 & ID_9005_GENERIC_MASK), 1141da177e4SLinus Torvalds ID(ID_AIC7895 & ID_DEV_VENDOR_MASK), 1151da177e4SLinus Torvalds ID16(ID_AIC7896 & ID_9005_GENERIC_MASK), 1161da177e4SLinus Torvalds ID16(ID_AIC7899 & ID_9005_GENERIC_MASK), 1171da177e4SLinus Torvalds ID(ID_AIC7810 & ID_DEV_VENDOR_MASK), 1181da177e4SLinus Torvalds ID(ID_AIC7815 & ID_DEV_VENDOR_MASK), 1191da177e4SLinus Torvalds { 0 } 1201da177e4SLinus Torvalds }; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table); 1231da177e4SLinus Torvalds 124b5720729SHannes Reinecke #ifdef CONFIG_PM 125b5720729SHannes Reinecke static int 126b5720729SHannes Reinecke ahc_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg) 127b5720729SHannes Reinecke { 128b5720729SHannes Reinecke struct ahc_softc *ahc = pci_get_drvdata(pdev); 129b5720729SHannes Reinecke int rc; 130b5720729SHannes Reinecke 131b5720729SHannes Reinecke if ((rc = ahc_suspend(ahc))) 132b5720729SHannes Reinecke return rc; 133b5720729SHannes Reinecke 134b5720729SHannes Reinecke pci_save_state(pdev); 135b5720729SHannes Reinecke pci_disable_device(pdev); 136b5720729SHannes Reinecke 137*3a2d5b70SRafael J. Wysocki if (mesg.event & PM_EVENT_SLEEP) 138b5720729SHannes Reinecke pci_set_power_state(pdev, PCI_D3hot); 139b5720729SHannes Reinecke 140b5720729SHannes Reinecke return rc; 141b5720729SHannes Reinecke } 142b5720729SHannes Reinecke 143b5720729SHannes Reinecke static int 144b5720729SHannes Reinecke ahc_linux_pci_dev_resume(struct pci_dev *pdev) 145b5720729SHannes Reinecke { 146b5720729SHannes Reinecke struct ahc_softc *ahc = pci_get_drvdata(pdev); 147b5720729SHannes Reinecke int rc; 148b5720729SHannes Reinecke 149b5720729SHannes Reinecke pci_set_power_state(pdev, PCI_D0); 150b5720729SHannes Reinecke pci_restore_state(pdev); 151b5720729SHannes Reinecke 152b5720729SHannes Reinecke if ((rc = pci_enable_device(pdev))) { 153b5720729SHannes Reinecke dev_printk(KERN_ERR, &pdev->dev, 154b5720729SHannes Reinecke "failed to enable device after resume (%d)\n", rc); 155b5720729SHannes Reinecke return rc; 156b5720729SHannes Reinecke } 157b5720729SHannes Reinecke 158b5720729SHannes Reinecke pci_set_master(pdev); 159b5720729SHannes Reinecke 160b5720729SHannes Reinecke ahc_pci_resume(ahc); 161b5720729SHannes Reinecke 162b5720729SHannes Reinecke return (ahc_resume(ahc)); 163b5720729SHannes Reinecke } 16403e7925dSFUJITA Tomonori #endif 165b5720729SHannes Reinecke 1661da177e4SLinus Torvalds static void 1671da177e4SLinus Torvalds ahc_linux_pci_dev_remove(struct pci_dev *pdev) 1681da177e4SLinus Torvalds { 1693d65692aSChristoph Hellwig struct ahc_softc *ahc = pci_get_drvdata(pdev); 1701da177e4SLinus Torvalds u_long s; 1711da177e4SLinus Torvalds 17297af50f6SJames Bottomley if (ahc->platform_data && ahc->platform_data->host) 17397af50f6SJames Bottomley scsi_remove_host(ahc->platform_data->host); 17497af50f6SJames Bottomley 1751da177e4SLinus Torvalds ahc_lock(ahc, &s); 1761da177e4SLinus Torvalds ahc_intr_enable(ahc, FALSE); 1771da177e4SLinus Torvalds ahc_unlock(ahc, &s); 1781da177e4SLinus Torvalds ahc_free(ahc); 1791da177e4SLinus Torvalds } 1801da177e4SLinus Torvalds 1813a4f5c60SJames Bottomley static void 1823a4f5c60SJames Bottomley ahc_linux_pci_inherit_flags(struct ahc_softc *ahc) 1833a4f5c60SJames Bottomley { 1843a4f5c60SJames Bottomley struct pci_dev *pdev = ahc->dev_softc, *master_pdev; 1853a4f5c60SJames Bottomley unsigned int master_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0); 1863a4f5c60SJames Bottomley 1873a4f5c60SJames Bottomley master_pdev = pci_get_slot(pdev->bus, master_devfn); 1883a4f5c60SJames Bottomley if (master_pdev) { 1893a4f5c60SJames Bottomley struct ahc_softc *master = pci_get_drvdata(master_pdev); 1903a4f5c60SJames Bottomley if (master) { 1913a4f5c60SJames Bottomley ahc->flags &= ~AHC_BIOS_ENABLED; 1923a4f5c60SJames Bottomley ahc->flags |= master->flags & AHC_BIOS_ENABLED; 1933a4f5c60SJames Bottomley 1943a4f5c60SJames Bottomley ahc->flags &= ~AHC_PRIMARY_CHANNEL; 1953a4f5c60SJames Bottomley ahc->flags |= master->flags & AHC_PRIMARY_CHANNEL; 1963a4f5c60SJames Bottomley } else 1973a4f5c60SJames Bottomley printk(KERN_ERR "aic7xxx: no multichannel peer found!\n"); 1983a4f5c60SJames Bottomley pci_dev_put(master_pdev); 1993a4f5c60SJames Bottomley } 2003a4f5c60SJames Bottomley } 2013a4f5c60SJames Bottomley 2021da177e4SLinus Torvalds static int 2031da177e4SLinus Torvalds ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 2041da177e4SLinus Torvalds { 2051da177e4SLinus Torvalds char buf[80]; 2061da177e4SLinus Torvalds const uint64_t mask_39bit = 0x7FFFFFFFFFULL; 2071da177e4SLinus Torvalds struct ahc_softc *ahc; 2081da177e4SLinus Torvalds ahc_dev_softc_t pci; 2091da177e4SLinus Torvalds struct ahc_pci_identity *entry; 2101da177e4SLinus Torvalds char *name; 2111da177e4SLinus Torvalds int error; 212a89f29f6SJames Bottomley struct device *dev = &pdev->dev; 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds pci = pdev; 2151da177e4SLinus Torvalds entry = ahc_find_pci_device(pci); 2161da177e4SLinus Torvalds if (entry == NULL) 2171da177e4SLinus Torvalds return (-ENODEV); 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds /* 2201da177e4SLinus Torvalds * Allocate a softc for this card and 2211da177e4SLinus Torvalds * set it up for attachment by our 2221da177e4SLinus Torvalds * common detect routine. 2231da177e4SLinus Torvalds */ 2241da177e4SLinus Torvalds sprintf(buf, "ahc_pci:%d:%d:%d", 2251da177e4SLinus Torvalds ahc_get_pci_bus(pci), 2261da177e4SLinus Torvalds ahc_get_pci_slot(pci), 2271da177e4SLinus Torvalds ahc_get_pci_function(pci)); 2281da177e4SLinus Torvalds name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); 2291da177e4SLinus Torvalds if (name == NULL) 2301da177e4SLinus Torvalds return (-ENOMEM); 2311da177e4SLinus Torvalds strcpy(name, buf); 2321da177e4SLinus Torvalds ahc = ahc_alloc(NULL, name); 2331da177e4SLinus Torvalds if (ahc == NULL) 2341da177e4SLinus Torvalds return (-ENOMEM); 2351da177e4SLinus Torvalds if (pci_enable_device(pdev)) { 2361da177e4SLinus Torvalds ahc_free(ahc); 2371da177e4SLinus Torvalds return (-ENODEV); 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds pci_set_master(pdev); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds if (sizeof(dma_addr_t) > 4 242a89f29f6SJames Bottomley && ahc->features & AHC_LARGE_SCBS 243a89f29f6SJames Bottomley && dma_set_mask(dev, mask_39bit) == 0 244a89f29f6SJames Bottomley && dma_get_required_mask(dev) > DMA_32BIT_MASK) { 2451da177e4SLinus Torvalds ahc->flags |= AHC_39BIT_ADDRESSING; 2461da177e4SLinus Torvalds } else { 247a89f29f6SJames Bottomley if (dma_set_mask(dev, DMA_32BIT_MASK)) { 2484a6fae1dSJesper Juhl ahc_free(ahc); 2491da177e4SLinus Torvalds printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n"); 2501da177e4SLinus Torvalds return (-ENODEV); 2511da177e4SLinus Torvalds } 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds ahc->dev_softc = pci; 2541da177e4SLinus Torvalds error = ahc_pci_config(ahc, entry); 2551da177e4SLinus Torvalds if (error != 0) { 2561da177e4SLinus Torvalds ahc_free(ahc); 2571da177e4SLinus Torvalds return (-error); 2581da177e4SLinus Torvalds } 2593a4f5c60SJames Bottomley 2603a4f5c60SJames Bottomley /* 2613a4f5c60SJames Bottomley * Second Function PCI devices need to inherit some 2623a4f5c60SJames Bottomley * settings from function 0. 2633a4f5c60SJames Bottomley */ 2643a4f5c60SJames Bottomley if ((ahc->features & AHC_MULTI_FUNC) && PCI_FUNC(pdev->devfn) != 0) 2653a4f5c60SJames Bottomley ahc_linux_pci_inherit_flags(ahc); 2663a4f5c60SJames Bottomley 2671da177e4SLinus Torvalds pci_set_drvdata(pdev, ahc); 2681da177e4SLinus Torvalds ahc_linux_register_host(ahc, &aic7xxx_driver_template); 2691da177e4SLinus Torvalds return (0); 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds 27203e7925dSFUJITA Tomonori static struct pci_driver aic7xxx_pci_driver = { 27303e7925dSFUJITA Tomonori .name = "aic7xxx", 27403e7925dSFUJITA Tomonori .probe = ahc_linux_pci_dev_probe, 27503e7925dSFUJITA Tomonori #ifdef CONFIG_PM 27603e7925dSFUJITA Tomonori .suspend = ahc_linux_pci_dev_suspend, 27703e7925dSFUJITA Tomonori .resume = ahc_linux_pci_dev_resume, 27803e7925dSFUJITA Tomonori #endif 27903e7925dSFUJITA Tomonori .remove = ahc_linux_pci_dev_remove, 28003e7925dSFUJITA Tomonori .id_table = ahc_linux_pci_id_table 28103e7925dSFUJITA Tomonori }; 28203e7925dSFUJITA Tomonori 2831da177e4SLinus Torvalds int 2841da177e4SLinus Torvalds ahc_linux_pci_init(void) 2851da177e4SLinus Torvalds { 286dcbccbdeSHenrik Kretzschmar return pci_register_driver(&aic7xxx_pci_driver); 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds void 2901da177e4SLinus Torvalds ahc_linux_pci_exit(void) 2911da177e4SLinus Torvalds { 2921da177e4SLinus Torvalds pci_unregister_driver(&aic7xxx_pci_driver); 2931da177e4SLinus Torvalds } 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds static int 2961da177e4SLinus Torvalds ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc, u_long *base) 2971da177e4SLinus Torvalds { 2981da177e4SLinus Torvalds if (aic7xxx_allow_memio == 0) 2991da177e4SLinus Torvalds return (ENOMEM); 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds *base = pci_resource_start(ahc->dev_softc, 0); 3021da177e4SLinus Torvalds if (*base == 0) 3031da177e4SLinus Torvalds return (ENOMEM); 3041da177e4SLinus Torvalds if (request_region(*base, 256, "aic7xxx") == 0) 3051da177e4SLinus Torvalds return (ENOMEM); 3061da177e4SLinus Torvalds return (0); 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds static int 3101da177e4SLinus Torvalds ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc, 3111da177e4SLinus Torvalds u_long *bus_addr, 3121da177e4SLinus Torvalds uint8_t __iomem **maddr) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds u_long start; 3151da177e4SLinus Torvalds int error; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds error = 0; 3181da177e4SLinus Torvalds start = pci_resource_start(ahc->dev_softc, 1); 3191da177e4SLinus Torvalds if (start != 0) { 3201da177e4SLinus Torvalds *bus_addr = start; 3211da177e4SLinus Torvalds if (request_mem_region(start, 0x1000, "aic7xxx") == 0) 3221da177e4SLinus Torvalds error = ENOMEM; 3231da177e4SLinus Torvalds if (error == 0) { 3241da177e4SLinus Torvalds *maddr = ioremap_nocache(start, 256); 3251da177e4SLinus Torvalds if (*maddr == NULL) { 3261da177e4SLinus Torvalds error = ENOMEM; 3271da177e4SLinus Torvalds release_mem_region(start, 0x1000); 3281da177e4SLinus Torvalds } 3291da177e4SLinus Torvalds } 3301da177e4SLinus Torvalds } else 3311da177e4SLinus Torvalds error = ENOMEM; 3321da177e4SLinus Torvalds return (error); 3331da177e4SLinus Torvalds } 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds int 3361da177e4SLinus Torvalds ahc_pci_map_registers(struct ahc_softc *ahc) 3371da177e4SLinus Torvalds { 3381da177e4SLinus Torvalds uint32_t command; 3391da177e4SLinus Torvalds u_long base; 3401da177e4SLinus Torvalds uint8_t __iomem *maddr; 3411da177e4SLinus Torvalds int error; 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds /* 3441da177e4SLinus Torvalds * If its allowed, we prefer memory mapped access. 3451da177e4SLinus Torvalds */ 3461da177e4SLinus Torvalds command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4); 3471da177e4SLinus Torvalds command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN); 3481da177e4SLinus Torvalds base = 0; 3491da177e4SLinus Torvalds maddr = NULL; 3501da177e4SLinus Torvalds error = ahc_linux_pci_reserve_mem_region(ahc, &base, &maddr); 3511da177e4SLinus Torvalds if (error == 0) { 3521da177e4SLinus Torvalds ahc->platform_data->mem_busaddr = base; 3531da177e4SLinus Torvalds ahc->tag = BUS_SPACE_MEMIO; 3541da177e4SLinus Torvalds ahc->bsh.maddr = maddr; 3551da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, 3561da177e4SLinus Torvalds command | PCIM_CMD_MEMEN, 4); 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds /* 3591da177e4SLinus Torvalds * Do a quick test to see if memory mapped 3601da177e4SLinus Torvalds * I/O is functioning correctly. 3611da177e4SLinus Torvalds */ 3621da177e4SLinus Torvalds if (ahc_pci_test_register_access(ahc) != 0) { 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds printf("aic7xxx: PCI Device %d:%d:%d " 3651da177e4SLinus Torvalds "failed memory mapped test. Using PIO.\n", 3661da177e4SLinus Torvalds ahc_get_pci_bus(ahc->dev_softc), 3671da177e4SLinus Torvalds ahc_get_pci_slot(ahc->dev_softc), 3681da177e4SLinus Torvalds ahc_get_pci_function(ahc->dev_softc)); 3691da177e4SLinus Torvalds iounmap(maddr); 3701da177e4SLinus Torvalds release_mem_region(ahc->platform_data->mem_busaddr, 3711da177e4SLinus Torvalds 0x1000); 3721da177e4SLinus Torvalds ahc->bsh.maddr = NULL; 3731da177e4SLinus Torvalds maddr = NULL; 3741da177e4SLinus Torvalds } else 3751da177e4SLinus Torvalds command |= PCIM_CMD_MEMEN; 3761da177e4SLinus Torvalds } else { 3771da177e4SLinus Torvalds printf("aic7xxx: PCI%d:%d:%d MEM region 0x%lx " 3781da177e4SLinus Torvalds "unavailable. Cannot memory map device.\n", 3791da177e4SLinus Torvalds ahc_get_pci_bus(ahc->dev_softc), 3801da177e4SLinus Torvalds ahc_get_pci_slot(ahc->dev_softc), 3811da177e4SLinus Torvalds ahc_get_pci_function(ahc->dev_softc), 3821da177e4SLinus Torvalds base); 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds /* 3861da177e4SLinus Torvalds * We always prefer memory mapped access. 3871da177e4SLinus Torvalds */ 3881da177e4SLinus Torvalds if (maddr == NULL) { 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds error = ahc_linux_pci_reserve_io_region(ahc, &base); 3911da177e4SLinus Torvalds if (error == 0) { 3921da177e4SLinus Torvalds ahc->tag = BUS_SPACE_PIO; 3931da177e4SLinus Torvalds ahc->bsh.ioport = base; 3941da177e4SLinus Torvalds command |= PCIM_CMD_PORTEN; 3951da177e4SLinus Torvalds } else { 3961da177e4SLinus Torvalds printf("aic7xxx: PCI%d:%d:%d IO region 0x%lx[0..255] " 3971da177e4SLinus Torvalds "unavailable. Cannot map device.\n", 3981da177e4SLinus Torvalds ahc_get_pci_bus(ahc->dev_softc), 3991da177e4SLinus Torvalds ahc_get_pci_slot(ahc->dev_softc), 4001da177e4SLinus Torvalds ahc_get_pci_function(ahc->dev_softc), 4011da177e4SLinus Torvalds base); 4021da177e4SLinus Torvalds } 4031da177e4SLinus Torvalds } 4041da177e4SLinus Torvalds ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4); 4051da177e4SLinus Torvalds return (error); 4061da177e4SLinus Torvalds } 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds int 4091da177e4SLinus Torvalds ahc_pci_map_int(struct ahc_softc *ahc) 4101da177e4SLinus Torvalds { 4111da177e4SLinus Torvalds int error; 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds error = request_irq(ahc->dev_softc->irq, ahc_linux_isr, 4141d6f359aSThomas Gleixner IRQF_SHARED, "aic7xxx", ahc); 4151da177e4SLinus Torvalds if (error == 0) 4161da177e4SLinus Torvalds ahc->platform_data->irq = ahc->dev_softc->irq; 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds return (-error); 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds 421