ata_kauai.c revision 175668
1/*- 2 * Copyright 2004 by Peter Grehan. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 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, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28#include <sys/cdefs.h> 29__FBSDID("$FreeBSD: head/sys/powerpc/powermac/ata_kauai.c 175668 2008-01-26 05:11:09Z julian $"); 30 31/* 32 * Mac 'Kauai' PCI ATA controller 33 */ 34#include "opt_ata.h" 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> 38#include <sys/module.h> 39#include <sys/bus.h> 40#include <sys/malloc.h> 41#include <sys/sema.h> 42#include <sys/taskqueue.h> 43#include <vm/uma.h> 44#include <machine/stdarg.h> 45#include <machine/resource.h> 46#include <machine/bus.h> 47#include <sys/rman.h> 48#include <sys/ata.h> 49#include <dev/ata/ata-all.h> 50#include <ata_if.h> 51 52#include <dev/ofw/openfirm.h> 53 54#include <dev/pci/pcivar.h> 55#include <dev/pci/pcireg.h> 56 57#define ATA_KAUAI_REGOFFSET 0x2000 58 59/* 60 * Offset to alt-control register from base 61 */ 62#define ATA_KAUAI_ALTOFFSET (ATA_KAUAI_REGOFFSET + 0x160) 63 64/* 65 * Define the gap between registers 66 */ 67#define ATA_KAUAI_REGGAP 16 68 69/* 70 * Define the kauai pci bus attachment. 71 */ 72static int ata_kauai_probe(device_t dev); 73static void ata_kauai_setmode(device_t parent, device_t dev); 74 75static device_method_t ata_kauai_methods[] = { 76 /* Device interface */ 77 DEVMETHOD(device_probe, ata_kauai_probe), 78 DEVMETHOD(device_attach, ata_attach), 79 DEVMETHOD(device_detach, bus_generic_detach), 80 DEVMETHOD(device_shutdown, bus_generic_shutdown), 81 DEVMETHOD(device_suspend, bus_generic_suspend), 82 DEVMETHOD(device_resume, bus_generic_resume), 83 84 /* ATA interface */ 85 DEVMETHOD(ata_setmode, ata_kauai_setmode), 86 { 0, 0 } 87}; 88 89static driver_t ata_kauai_driver = { 90 "ata", 91 ata_kauai_methods, 92 sizeof(struct ata_channel), 93}; 94 95DRIVER_MODULE(ata, pci, ata_kauai_driver, ata_devclass, 0, 0); 96MODULE_DEPEND(ata, ata, 1, 1, 1); 97 98/* 99 * PCI ID search table 100 */ 101static struct kauai_pci_dev { 102 u_int32_t kpd_devid; 103 char *kpd_desc; 104} kauai_pci_devlist[] = { 105 { 0x0033106b, "Uninorth2 Kauai ATA Controller" }, 106 { 0x003b106b, "Intrepid Kauai ATA Controller" }, 107 { 0x0043106b, "K2 Kauai ATA Controller" }, 108 { 0x0069106b, "Intrepid-2 Kauai ATA Controller" }, 109 { 0, NULL } 110}; 111 112static int 113ata_kauai_probe(device_t dev) 114{ 115 struct ata_channel *ch; 116 struct resource *mem; 117 u_long startp, countp; 118 u_int32_t devid; 119 int i, found, rid, status; 120 121 found = 0; 122 devid = pci_get_devid(dev); 123 for (i = 0; kauai_pci_devlist[i].kpd_desc != NULL; i++) { 124 if (devid == kauai_pci_devlist[i].kpd_devid) { 125 found = 1; 126 device_set_desc(dev, kauai_pci_devlist[i].kpd_desc); 127 } 128 } 129 130 if (!found) 131 return (ENXIO); 132 133 /* 134 * This device seems to ignore writes to the interrupt 135 * config register, resulting in interrupt resources 136 * not being attached. If this is the case, use 137 * Open Firmware to determine the irq, and then attach 138 * the resource. This allows the ATA common code to 139 * allocate the irq. 140 */ 141 status = bus_get_resource(dev, SYS_RES_IRQ, 0, &startp, &countp); 142 if (status == ENOENT) { 143 int irq; 144 145 /* 146 * Aargh, hideous hack until ofw pci intr routine is 147 * exported 148 */ 149 irq = 39; /* XXX */ 150 bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1); 151 152 /* 153 * Sanity check... 154 */ 155 status = bus_get_resource(dev, SYS_RES_IRQ, 0, &startp, 156 &countp); 157 if (status == ENOENT || 158 startp != 39) { 159 printf("kauai irq not set!\n"); 160 return (ENXIO); 161 } 162 } 163 164 ch = device_get_softc(dev); 165 bzero(ch, sizeof(struct ata_channel)); 166 167 rid = PCIR_BARS; 168 mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); 169 if (mem == NULL) { 170 device_printf(dev, "could not allocate memory\n"); 171 return (ENXIO); 172 } 173 174 /* 175 * Set up the resource vectors 176 */ 177 for (i = ATA_DATA; i <= ATA_COMMAND; i++) { 178 ch->r_io[i].res = mem; 179 ch->r_io[i].offset = i*ATA_KAUAI_REGGAP + ATA_KAUAI_REGOFFSET; 180 } 181 ch->r_io[ATA_CONTROL].res = mem; 182 ch->r_io[ATA_CONTROL].offset = ATA_KAUAI_ALTOFFSET; 183 ata_default_registers(dev); 184 185 ch->unit = 0; 186 ch->flags |= ATA_USE_16BIT; 187 ata_generic_hw(dev); 188 189 return (ata_probe(dev)); 190} 191 192static void 193ata_kauai_setmode(device_t parent, device_t dev) 194{ 195 struct ata_device *atadev = device_get_softc(dev); 196 197 /* TODO bang kauai speed register */ 198 atadev->mode = ATA_PIO; 199} 200