2 * Copyright (c) 2009-2012 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/module.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
36 #include <sys/endian.h>
37 #include <sys/malloc.h>
39 #include <sys/mutex.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/ahci/ahci.h>
47 #include <dev/ofw/ofw_bus.h>
48 #include <dev/ofw/ofw_bus_subr.h>
50 static struct ofw_compat_data compat_data[] = {
57 ahci_gen_ctlr_reset(device_t dev)
60 return ahci_ctlr_reset(dev);
64 ahci_probe(device_t dev)
67 if (!ofw_bus_status_okay(dev))
70 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data)
73 device_set_desc_copy(dev, "AHCI SATA controller");
74 return (BUS_PROBE_DEFAULT);
78 ahci_gen_attach(device_t dev)
80 struct ahci_controller *ctlr = device_get_softc(dev);
84 ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ctlr->r_rid,
86 if (ctlr->r_mem == NULL)
89 /* Setup controller defaults. */
92 /* Reset controller */
93 if ((error = ahci_gen_ctlr_reset(dev)) == 0)
94 error = ahci_attach(dev);
97 if (ctlr->r_mem != NULL)
98 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid,
105 ahci_gen_detach(device_t dev)
112 static devclass_t ahci_gen_devclass;
113 static device_method_t ahci_methods[] = {
114 DEVMETHOD(device_probe, ahci_probe),
115 DEVMETHOD(device_attach, ahci_gen_attach),
116 DEVMETHOD(device_detach, ahci_gen_detach),
117 DEVMETHOD(bus_print_child, ahci_print_child),
118 DEVMETHOD(bus_alloc_resource, ahci_alloc_resource),
119 DEVMETHOD(bus_release_resource, ahci_release_resource),
120 DEVMETHOD(bus_setup_intr, ahci_setup_intr),
121 DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
122 DEVMETHOD(bus_child_location_str, ahci_child_location_str),
123 DEVMETHOD(bus_get_dma_tag, ahci_get_dma_tag),
126 static driver_t ahci_driver = {
129 sizeof(struct ahci_controller)
131 DRIVER_MODULE(ahci, simplebus, ahci_driver, ahci_gen_devclass, NULL, NULL);