1 /* 2 * Copyright 2002 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 * $FreeBSD$ 28 */ 29 30 /* 31 * Mac-io ATA controller 32 */ 33 #include "opt_ata.h" 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/module.h> 38 #include <sys/bus.h> 39 #include <sys/malloc.h> 40 #include <sys/sema.h> 41 #include <sys/taskqueue.h> 42 #include <vm/uma.h> 43 #include <machine/stdarg.h> 44 #include <machine/resource.h> 45 #include <machine/bus.h> 46 #include <sys/rman.h> 47 #include <sys/ata.h> 48 #include <dev/ata/ata-all.h> 49 50 #include <dev/ofw/ofw_bus.h> 51 52 /* 53 * Offset to control registers from base 54 */ 55 #define ATA_MACIO_ALTOFFSET 0x160 56 57 /* 58 * Define the gap between registers 59 */ 60 #define ATA_MACIO_REGGAP 16 61 62 /* 63 * Define the macio ata bus attachment. 64 */ 65 static int ata_macio_probe(device_t dev); 66 67 static device_method_t ata_macio_methods[] = { 68 /* Device interface */ 69 DEVMETHOD(device_probe, ata_macio_probe), 70 DEVMETHOD(device_attach, ata_attach), 71 72 { 0, 0 } 73 }; 74 75 static driver_t ata_macio_driver = { 76 "ata", 77 ata_macio_methods, 78 sizeof(struct ata_channel), 79 }; 80 81 DRIVER_MODULE(ata, macio, ata_macio_driver, ata_devclass, 0, 0); 82 83 static void 84 ata_macio_locknoop(struct ata_channel *ch, int type) 85 { 86 /* XXX SMP ? */ 87 } 88 89 static void 90 ata_macio_setmode(struct ata_device *atadev, int mode) 91 { 92 #if 0 93 atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); 94 #endif 95 atadev->mode = ATA_PIO; 96 } 97 98 static int 99 ata_macio_probe(device_t dev) 100 { 101 const char *type = ofw_bus_get_type(dev); 102 struct ata_channel *ch; 103 struct resource *mem; 104 int rid, i; 105 106 if (strcmp(type, "ata") != 0 && 107 strcmp(type, "ide") != 0) 108 return (ENXIO); 109 110 ch = device_get_softc(dev); 111 bzero(ch, sizeof(struct ata_channel)); 112 113 rid = 0; 114 mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); 115 if (mem == NULL) { 116 device_printf(dev, "could not allocate memory\n"); 117 return (ENXIO); 118 } 119 120 /* 121 * Set up the resource vectors 122 */ 123 for (i = ATA_DATA; i <= ATA_STATUS; i++) { 124 ch->r_io[i].res = mem; 125 ch->r_io[i].offset = i * ATA_MACIO_REGGAP; 126 } 127 ch->r_io[ATA_ALTSTAT].res = mem; 128 ch->r_io[ATA_ALTSTAT].offset = ATA_MACIO_ALTOFFSET; 129 130 ch->unit = 0; 131 ch->flags |= ATA_USE_16BIT; 132 ch->locking = ata_macio_locknoop; 133 ch->device[MASTER].setmode = ata_macio_setmode; 134 ch->device[SLAVE].setmode = ata_macio_setmode; 135 ata_generic_hw(ch); 136 137 return (ata_probe(dev)); 138 } 139 140