1*258223a3SMatthew Dillon /* 2*258223a3SMatthew Dillon * Copyright (c) 2009 The DragonFly Project. All rights reserved. 3*258223a3SMatthew Dillon * 4*258223a3SMatthew Dillon * This code is derived from software contributed to The DragonFly Project 5*258223a3SMatthew Dillon * by Matthew Dillon <dillon@backplane.com> 6*258223a3SMatthew Dillon * 7*258223a3SMatthew Dillon * Redistribution and use in source and binary forms, with or without 8*258223a3SMatthew Dillon * modification, are permitted provided that the following conditions 9*258223a3SMatthew Dillon * are met: 10*258223a3SMatthew Dillon * 11*258223a3SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 12*258223a3SMatthew Dillon * notice, this list of conditions and the following disclaimer. 13*258223a3SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 14*258223a3SMatthew Dillon * notice, this list of conditions and the following disclaimer in 15*258223a3SMatthew Dillon * the documentation and/or other materials provided with the 16*258223a3SMatthew Dillon * distribution. 17*258223a3SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its 18*258223a3SMatthew Dillon * contributors may be used to endorse or promote products derived 19*258223a3SMatthew Dillon * from this software without specific, prior written permission. 20*258223a3SMatthew Dillon * 21*258223a3SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*258223a3SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*258223a3SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*258223a3SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*258223a3SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*258223a3SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*258223a3SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28*258223a3SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29*258223a3SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30*258223a3SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31*258223a3SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*258223a3SMatthew Dillon * SUCH DAMAGE. 33*258223a3SMatthew Dillon */ 34*258223a3SMatthew Dillon /* 35*258223a3SMatthew Dillon * Primary device and CAM interface to OpenBSD AHCI driver, for DragonFly 36*258223a3SMatthew Dillon */ 37*258223a3SMatthew Dillon 38*258223a3SMatthew Dillon #include "ahci.h" 39*258223a3SMatthew Dillon 40*258223a3SMatthew Dillon /* 41*258223a3SMatthew Dillon * Device bus methods 42*258223a3SMatthew Dillon */ 43*258223a3SMatthew Dillon 44*258223a3SMatthew Dillon static int ahci_probe (device_t dev); 45*258223a3SMatthew Dillon static int ahci_attach (device_t dev); 46*258223a3SMatthew Dillon static int ahci_detach (device_t dev); 47*258223a3SMatthew Dillon #if 0 48*258223a3SMatthew Dillon static int ahci_shutdown (device_t dev); 49*258223a3SMatthew Dillon static int ahci_suspend (device_t dev); 50*258223a3SMatthew Dillon static int ahci_resume (device_t dev); 51*258223a3SMatthew Dillon #endif 52*258223a3SMatthew Dillon 53*258223a3SMatthew Dillon static device_method_t ahci_methods[] = { 54*258223a3SMatthew Dillon DEVMETHOD(device_probe, ahci_probe), 55*258223a3SMatthew Dillon DEVMETHOD(device_attach, ahci_attach), 56*258223a3SMatthew Dillon DEVMETHOD(device_detach, ahci_detach), 57*258223a3SMatthew Dillon #if 0 58*258223a3SMatthew Dillon DEVMETHOD(device_shutdown, ahci_shutdown), 59*258223a3SMatthew Dillon DEVMETHOD(device_suspend, ahci_suspend), 60*258223a3SMatthew Dillon DEVMETHOD(device_resume, ahci_resume), 61*258223a3SMatthew Dillon #endif 62*258223a3SMatthew Dillon 63*258223a3SMatthew Dillon DEVMETHOD(bus_print_child, bus_generic_print_child), 64*258223a3SMatthew Dillon DEVMETHOD(bus_driver_added, bus_generic_driver_added), 65*258223a3SMatthew Dillon {0, 0} 66*258223a3SMatthew Dillon }; 67*258223a3SMatthew Dillon 68*258223a3SMatthew Dillon static devclass_t ahci_devclass; 69*258223a3SMatthew Dillon 70*258223a3SMatthew Dillon static driver_t ahci_driver = { 71*258223a3SMatthew Dillon "ahci", 72*258223a3SMatthew Dillon ahci_methods, 73*258223a3SMatthew Dillon sizeof(struct ahci_softc) 74*258223a3SMatthew Dillon }; 75*258223a3SMatthew Dillon 76*258223a3SMatthew Dillon MODULE_DEPEND(ahci, cam, 1, 1, 1); 77*258223a3SMatthew Dillon DRIVER_MODULE(ahci, pci, ahci_driver, ahci_devclass, 0, 0); 78*258223a3SMatthew Dillon 79*258223a3SMatthew Dillon /* 80*258223a3SMatthew Dillon * Device bus method procedures 81*258223a3SMatthew Dillon */ 82*258223a3SMatthew Dillon static int 83*258223a3SMatthew Dillon ahci_probe (device_t dev) 84*258223a3SMatthew Dillon { 85*258223a3SMatthew Dillon const struct ahci_device *ad; 86*258223a3SMatthew Dillon 87*258223a3SMatthew Dillon ad = ahci_lookup_device(dev); 88*258223a3SMatthew Dillon if (ad) { 89*258223a3SMatthew Dillon device_set_desc(dev, ad->name); 90*258223a3SMatthew Dillon return(-5); /* higher priority the NATA */ 91*258223a3SMatthew Dillon } 92*258223a3SMatthew Dillon return(ENXIO); 93*258223a3SMatthew Dillon } 94*258223a3SMatthew Dillon 95*258223a3SMatthew Dillon static int 96*258223a3SMatthew Dillon ahci_attach (device_t dev) 97*258223a3SMatthew Dillon { 98*258223a3SMatthew Dillon struct ahci_softc *sc = device_get_softc(dev); 99*258223a3SMatthew Dillon int error; 100*258223a3SMatthew Dillon 101*258223a3SMatthew Dillon sc->sc_ad = ahci_lookup_device(dev); 102*258223a3SMatthew Dillon if (sc->sc_ad == NULL) 103*258223a3SMatthew Dillon return(ENXIO); 104*258223a3SMatthew Dillon error = sc->sc_ad->ad_attach(dev); 105*258223a3SMatthew Dillon return (error); 106*258223a3SMatthew Dillon } 107*258223a3SMatthew Dillon 108*258223a3SMatthew Dillon static int 109*258223a3SMatthew Dillon ahci_detach (device_t dev) 110*258223a3SMatthew Dillon { 111*258223a3SMatthew Dillon struct ahci_softc *sc = device_get_softc(dev); 112*258223a3SMatthew Dillon int error = 0; 113*258223a3SMatthew Dillon 114*258223a3SMatthew Dillon if (sc->sc_ad) { 115*258223a3SMatthew Dillon error = sc->sc_ad->ad_detach(dev); 116*258223a3SMatthew Dillon sc->sc_ad = NULL; 117*258223a3SMatthew Dillon } 118*258223a3SMatthew Dillon return(error); 119*258223a3SMatthew Dillon } 120*258223a3SMatthew Dillon 121*258223a3SMatthew Dillon #if 0 122*258223a3SMatthew Dillon 123*258223a3SMatthew Dillon static int 124*258223a3SMatthew Dillon ahci_shutdown (device_t dev) 125*258223a3SMatthew Dillon { 126*258223a3SMatthew Dillon return (0); 127*258223a3SMatthew Dillon } 128*258223a3SMatthew Dillon 129*258223a3SMatthew Dillon static int 130*258223a3SMatthew Dillon ahci_suspend (device_t dev) 131*258223a3SMatthew Dillon { 132*258223a3SMatthew Dillon return (0); 133*258223a3SMatthew Dillon } 134*258223a3SMatthew Dillon 135*258223a3SMatthew Dillon static int 136*258223a3SMatthew Dillon ahci_resume (device_t dev) 137*258223a3SMatthew Dillon { 138*258223a3SMatthew Dillon return (0); 139*258223a3SMatthew Dillon } 140*258223a3SMatthew Dillon 141*258223a3SMatthew Dillon #endif 142