2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
3 * Copyright (c) 2017 The FreeBSD Foundation
6 * Portions of this software were developed by Landon Fuller
7 * under sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGES.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/kernel.h>
40 #include <sys/module.h>
42 #include <dev/bhnd/bhnd_ids.h>
43 #include <dev/bhnd/bhnd.h>
45 #include "bhnd_pwrctl_hostb_if.h"
50 * bhnd(4) driver mix-in providing a shared common methods for
51 * bhnd devices attached via a bhndb bridge.
55 bhnd_bhndb_read_board_info(device_t dev, device_t child,
56 struct bhnd_board_info *info)
60 /* Initialize with NVRAM-derived values */
61 if ((error = bhnd_bus_generic_read_board_info(dev, child, info)))
64 /* Let the bridge fill in any additional data */
65 return (BHNDB_POPULATE_BOARD_INFO(device_get_parent(dev), dev, info));
68 static bhnd_attach_type
69 bhnd_bhndb_get_attach_type(device_t dev, device_t child)
71 /* It's safe to assume that a bridged device is always an adapter */
72 return (BHND_ATTACH_ADAPTER);
77 bhnd_bhndb_is_hw_disabled(device_t dev, device_t child)
79 struct bhnd_core_info core = bhnd_get_core_info(child);
81 /* Delegate to parent bridge */
82 return (BHNDB_IS_CORE_DISABLED(device_get_parent(dev), dev, &core));
87 bhnd_bhndb_find_hostb_device(device_t dev)
89 struct bhnd_core_info core;
90 struct bhnd_core_match md;
93 /* Ask the bridge for the hostb core info */
94 if ((error = BHNDB_GET_HOSTB_CORE(device_get_parent(dev), dev, &core)))
97 /* Find the corresponding bus device */
98 md = bhnd_core_get_match_desc(&core);
99 return (bhnd_bus_match_child(dev, &md));
103 bhnd_bhndb_map_intr(device_t dev, device_t child, u_int intr, rman_res_t *irq)
105 /* Delegate to parent bridge */
106 return (BHND_BUS_MAP_INTR(device_get_parent(dev), child, intr, irq));
110 bhnd_bhndb_unmap_intr(device_t dev, device_t child, rman_res_t irq)
112 /* Delegate to parent bridge */
113 return (BHND_BUS_UNMAP_INTR(device_get_parent(dev), child, irq));
117 bhnd_bhndb_pwrctl_get_clksrc(device_t dev, device_t child,
120 /* Delegate to parent bridge */
121 return (BHND_PWRCTL_HOSTB_GET_CLKSRC(device_get_parent(dev), child,
126 bhnd_bhndb_pwrctl_gate_clock(device_t dev, device_t child,
129 /* Delegate to parent bridge */
130 return (BHND_PWRCTL_HOSTB_GATE_CLOCK(device_get_parent(dev), child,
135 bhnd_bhndb_pwrctl_ungate_clock(device_t dev, device_t child,
138 /* Delegate to parent bridge */
139 return (BHND_PWRCTL_HOSTB_UNGATE_CLOCK(device_get_parent(dev), child,
144 bhnd_bhndb_setup_intr(device_t dev, device_t child, struct resource *irq,
145 int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg,
151 /* Find the actual bus-attached child core */
153 while ((bus = device_get_parent(core)) != NULL) {
160 KASSERT(core != NULL, ("%s is not a child of %s",
161 device_get_nameunit(child), device_get_nameunit(dev)));
163 /* Ask our bridge to enable interrupt routing for the child core */
164 error = BHNDB_ROUTE_INTERRUPTS(device_get_parent(dev), core);
168 /* Delegate actual interrupt setup to the default bhnd bus
170 return (bhnd_generic_setup_intr(dev, child, irq, flags, filter, intr,
174 static device_method_t bhnd_bhndb_methods[] = {
176 DEVMETHOD(bus_setup_intr, bhnd_bhndb_setup_intr),
179 DEVMETHOD(bhnd_bus_get_attach_type, bhnd_bhndb_get_attach_type),
180 DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_bhndb_is_hw_disabled),
181 DEVMETHOD(bhnd_bus_find_hostb_device, bhnd_bhndb_find_hostb_device),
182 DEVMETHOD(bhnd_bus_read_board_info, bhnd_bhndb_read_board_info),
183 DEVMETHOD(bhnd_bus_map_intr, bhnd_bhndb_map_intr),
184 DEVMETHOD(bhnd_bus_unmap_intr, bhnd_bhndb_unmap_intr),
186 /* BHND PWRCTL hostb interface */
187 DEVMETHOD(bhnd_pwrctl_hostb_get_clksrc, bhnd_bhndb_pwrctl_get_clksrc),
188 DEVMETHOD(bhnd_pwrctl_hostb_gate_clock, bhnd_bhndb_pwrctl_gate_clock),
189 DEVMETHOD(bhnd_pwrctl_hostb_ungate_clock, bhnd_bhndb_pwrctl_ungate_clock),
194 DEFINE_CLASS_0(bhnd, bhnd_bhndb_driver, bhnd_bhndb_methods, 0);