1 /*- 2 * Copyright (c) 1998 - 2006 Søren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD: src/sys/dev/ata/ata-chipset.c,v 1.196 2007/04/08 19:18:51 sos Exp $ 27 */ 28 29 #include "opt_ata.h" 30 31 #include <sys/param.h> 32 #include <sys/bus.h> 33 #include <sys/bus_dma.h> 34 #include <sys/bus_resource.h> 35 #include <sys/callout.h> 36 #include <sys/endian.h> 37 #include <sys/libkern.h> 38 #include <sys/malloc.h> 39 #include <sys/nata.h> 40 #include <sys/queue.h> 41 #include <sys/rman.h> 42 #include <sys/systm.h> 43 #include <sys/taskqueue.h> 44 #include <sys/machintr.h> 45 46 #include <machine/bus_dma.h> 47 48 #include <bus/pci/pcireg.h> 49 #include <bus/pci/pcivar.h> 50 51 #include "ata-all.h" 52 #include "ata-pci.h" 53 #include "ata_if.h" 54 55 /* ATA_NO_SMTH helper */ 56 #define ATA_IDENT_DUMMY(name) int ata_ ## name ## _ident \ 57 (device_t x __unused){return 1;} 58 59 /* local prototypes */ 60 /* ata-chipset.c */ 61 static int ata_generic_chipinit(device_t dev); 62 static void ata_generic_setmode(device_t dev, int mode); 63 64 #if !defined(ATA_NO_AHCI) 65 /* used by ata-{ahci,acerlabs,ati,intel,jmicron,via}.c */ 66 static int ata_ahci_chipinit(device_t dev); 67 68 /* used by ata-ahci.c and ata-jmicron.c */ 69 static int ata_ahci_allocate(device_t dev); 70 static void ata_ahci_dmainit(device_t dev); 71 static void ata_ahci_reset(device_t dev); 72 #endif 73 74 #if !defined(ATA_NO_MARVELL) 75 /* ata-adaptec.c depends on ata-marwell.c */ 76 static int ata_marvell_edma_chipinit(device_t dev); 77 #endif 78 79 #if !defined(ATA_NO_SILICONIMAGE) 80 /* ata-ati.c depends on ata-siliconimage.c */ 81 /* used by ata-ati.c and ata-siliconimage.c */ 82 static int ata_sii_chipinit(device_t dev); 83 #endif 84 85 86 /* 87 * ahci capable chipset support functions (needed for some vendor chipsets) 88 */ 89 #if !defined(ATA_NO_AHCI) 90 #include "chipsets/ata-ahci.c" 91 #else 92 ATA_IDENT_DUMMY(ahci) 93 #endif 94 95 /* 96 * various vendor specific chipset support functions 97 */ 98 #if !defined(ATA_NO_ACARD) 99 #include "chipsets/ata-acard.c" 100 #else 101 ATA_IDENT_DUMMY(acard) 102 #endif 103 104 #if !defined(ATA_NO_ACERLABS) && !defined(ATA_NO_AHCI) 105 #include "chipsets/ata-acerlabs.c" 106 #else 107 ATA_IDENT_DUMMY(ali) 108 #endif 109 110 #if !defined(ATA_NO_AMD) 111 #include "chipsets/ata-amd.c" 112 #else 113 ATA_IDENT_DUMMY(amd) 114 #endif 115 116 #if !defined(ATA_NO_AHCI) && !defined(ATA_NO_SILICONIMAGE) 117 #include "chipsets/ata-ati.c" 118 #else 119 ATA_IDENT_DUMMY(ati) 120 #endif 121 122 #if !defined(ATA_NO_CYPRESS) 123 #include "chipsets/ata-cypress.c" 124 #else 125 ATA_IDENT_DUMMY(cypress) 126 #endif 127 128 #if !defined(ATA_NO_CYRIX) 129 #include "chipsets/ata-cyrix.c" 130 #else 131 ATA_IDENT_DUMMY(cyrix) 132 #endif 133 134 #if !defined(ATA_NO_HIGHPOINT) 135 #include "chipsets/ata-highpoint.c" 136 #else 137 ATA_IDENT_DUMMY(highpoint) 138 #endif 139 140 #if !defined(ATA_NO_INTEL) && !defined(ATA_NO_AHCI) 141 #include "chipsets/ata-intel.c" 142 #else 143 ATA_IDENT_DUMMY(intel) 144 #endif 145 146 #if !defined(ATA_NO_ITE) 147 #include "chipsets/ata-ite.c" 148 #else 149 ATA_IDENT_DUMMY(ite) 150 #endif 151 152 #if !defined(ATA_NO_JMICRON) && !defined(ATA_NO_AHCI) 153 #include "chipsets/ata-jmicron.c" 154 #else 155 ATA_IDENT_DUMMY(jmicron) 156 #endif 157 158 #if !defined(ATA_NO_MARVELL) 159 #include "chipsets/ata-adaptec.c" 160 #include "chipsets/ata-marvell.c" 161 #else 162 ATA_IDENT_DUMMY(adaptec) 163 ATA_IDENT_DUMMY(marvell) 164 #endif 165 166 #if !defined(ATA_NO_NATIONAL) 167 #include "chipsets/ata-national.c" 168 #else 169 ATA_IDENT_DUMMY(national) 170 #endif 171 172 #if !defined(ATA_NO_NETCELL) 173 #include "chipsets/ata-netcell.c" 174 #else 175 ATA_IDENT_DUMMY(netcell) 176 #endif 177 178 #if !defined(ATA_NO_NVIDIA) 179 #include "chipsets/ata-nvidia.c" 180 #else 181 ATA_IDENT_DUMMY(nvidia) 182 #endif 183 184 #if !defined(ATA_NO_PROMISE) 185 #include "chipsets/ata-promise.c" 186 #else 187 ATA_IDENT_DUMMY(promise) 188 #endif 189 190 #if !defined(ATA_NO_SERVERWORKS) 191 #include "chipsets/ata-serverworks.c" 192 #else 193 ATA_IDENT_DUMMY(serverworks) 194 #endif 195 196 #if !defined(ATA_NO_SILICONIMAGE) 197 #include "chipsets/ata-siliconimage.c" 198 #else 199 ATA_IDENT_DUMMY(sii) 200 #endif 201 202 #if !defined(ATA_NO_SIS) 203 #include "chipsets/ata-sis.c" 204 #else 205 ATA_IDENT_DUMMY(sis) 206 #endif 207 208 #if !defined(ATA_NO_VIA) && !defined(ATA_NO_AHCI) 209 #include "chipsets/ata-via.c" 210 #else 211 ATA_IDENT_DUMMY(via) 212 #endif 213 214 /* 215 * various vendor specific chipset support functions based on generic ATA 216 */ 217 218 #include "chipsets/ata-cenatek.c" 219 #include "chipsets/ata-micron.c" 220 221 /* 222 * generic ATA support functions 223 */ 224 int 225 ata_generic_ident(device_t dev) 226 { 227 struct ata_pci_controller *ctlr = device_get_softc(dev); 228 char buffer[64]; 229 230 ksnprintf(buffer, sizeof(buffer), 231 "%s ATA controller", ata_pcivendor2str(dev)); 232 device_set_desc_copy(dev, buffer); 233 ctlr->chipinit = ata_generic_chipinit; 234 return 0; 235 } 236 237 static int 238 ata_generic_chipinit(device_t dev) 239 { 240 struct ata_pci_controller *ctlr = device_get_softc(dev); 241 242 if (ata_setup_interrupt(dev, ata_generic_intr)) 243 return ENXIO; 244 ctlr->setmode = ata_generic_setmode; 245 return 0; 246 } 247 248 static void 249 ata_generic_setmode(device_t dev, int mode) 250 { 251 struct ata_device *atadev = device_get_softc(dev); 252 253 mode = ata_limit_mode(dev, mode, ATA_UDMA2); 254 mode = ata_check_80pin(dev, mode); 255 if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) 256 atadev->mode = mode; 257 } 258