xref: /freebsd/sys/dev/bhnd/bhndb/bhndb_if.m (revision 780fb4a2)
1#-
2# Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
3# Copyright (c) 2017 The FreeBSD Foundation
4# All rights reserved.
5#
6# Portions of this software were developed by Landon Fuller
7# under sponsorship from the FreeBSD Foundation.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# $FreeBSD$
30
31#include <sys/param.h>
32#include <sys/bus.h>
33
34#include <machine/bus.h>
35#include <sys/rman.h>
36#include <machine/resource.h>
37
38#include <dev/bhnd/bhnd.h>
39
40#
41# bhndb bridge device interface.
42#
43
44INTERFACE bhndb;
45
46HEADER {
47	struct bhndb_intr_isrc;
48	struct bhndb_regwin;
49	struct bhndb_hw;
50	struct bhndb_hw_priority;
51}
52
53CODE {
54	#include <sys/systm.h>
55	#include <dev/bhnd/bhndb/bhndbvar.h>
56
57	static const struct bhnd_chipid *
58	bhndb_null_get_chipid(device_t dev, device_t child)
59	{
60		panic("bhndb_get_chipid unimplemented");
61	}
62
63	static int
64	bhndb_null_populate_board_info(device_t dev, device_t child,
65	    struct bhnd_board_info *info)
66	{
67		panic("bhndb_populate_board_info unimplemented");
68	}
69
70	static int
71	bhndb_null_is_core_disabled(device_t dev, device_t child,
72	    struct bhnd_core_info *core)
73	{
74		panic("bhndb_is_core_disabled unimplemented");
75	}
76
77	static int
78	bhndb_null_get_hostb_core(device_t dev, device_t child,
79	    struct bhnd_core_info *core)
80	{
81		panic("bhndb_get_hostb_core unimplemented");
82	}
83
84	static void
85	bhndb_null_suspend_resource(device_t dev, device_t child, int type,
86	    struct resource *r)
87	{
88		panic("bhndb_suspend_resource unimplemented");
89	}
90
91	static int
92	bhndb_null_resume_resource(device_t dev, device_t child, int type,
93	    struct resource *r)
94	{
95		panic("bhndb_resume_resource unimplemented");
96	}
97
98	static int
99	bhndb_null_route_interrupts(device_t dev, device_t child)
100	{
101		panic("bhndb_route_interrupts unimplemented");
102	}
103
104	static int
105	bhndb_null_set_window_addr(device_t dev,
106	    const struct bhndb_regwin *rw, bhnd_addr_t addr)
107	{
108		panic("bhndb_set_window_addr unimplemented");
109	}
110
111	static int
112	bhndb_null_map_intr_isrc(device_t dev, struct resource *irq,
113	    struct bhndb_intr_isrc **isrc)
114	{
115		panic("bhndb_map_intr_isrc unimplemented");
116	}
117}
118
119/**
120 * Return the chip identification information for @p child.
121 *
122 * @param dev The parent device of @p child.
123 * @param child The bhndb-attached device.
124 */
125METHOD const struct bhnd_chipid * get_chipid {
126	device_t dev;
127	device_t child;
128} DEFAULT bhndb_null_get_chipid;
129
130/**
131 * Populate @p info with board info known only to the bridge,
132 * deferring to any existing initialized fields in @p info.
133 *
134 * @param dev The parent device of @p child.
135 * @param child The bhndb-attached device.
136 * @param[in,out] info A board info structure previously initialized with any
137 * information available from NVRAM.
138 */
139METHOD int populate_board_info {
140	device_t dev;
141	device_t child;
142	struct bhnd_board_info *info;
143} DEFAULT bhndb_null_populate_board_info;
144
145/**
146 * Return true if the hardware required by @p core is unpopulated or
147 * otherwise unusable.
148 *
149 * In some cases, the core's pins may be left floating, or the hardware
150 * may otherwise be non-functional; this method allows the parent device
151 * to explicitly specify whether @p core should be disabled.
152 *
153 * @param dev The parent device of @p child.
154 * @param child The attached bhnd device.
155 * @param core A core discovered on @p child.
156 */
157METHOD bool is_core_disabled {
158	device_t dev;
159	device_t child;
160	struct bhnd_core_info *core;
161} DEFAULT bhndb_null_is_core_disabled;
162
163/**
164 * Get the host bridge core info for the attached bhnd bus.
165 *
166 * @param	dev	The bridge device.
167 * @param	child	The bhnd bus device attached to @p dev.
168 * @param[out]	core	Will be populated with the host bridge core info, if
169 *			found.
170 *
171 * @retval 0		success
172 * @retval ENOENT	No host bridge core found.
173 * @retval non-zero	If locating the host bridge core otherwise fails, a
174 *			regular UNIX error code should be returned.
175 */
176METHOD int get_hostb_core {
177	device_t dev;
178	device_t child;
179	struct bhnd_core_info *core;
180} DEFAULT bhndb_null_get_hostb_core;
181
182/**
183 * Mark a resource as 'suspended', gauranteeing to the bridge that no
184 * further use of the resource will be made until BHNDB_RESUME_RESOURCE()
185 * is called.
186 *
187 * Bridge resources consumed by the reference may be released; these will
188 * be reacquired if BHNDB_RESUME_RESOURCE() completes successfully.
189 *
190 * Requests to suspend a suspended resource will be ignored.
191 *
192 * @param dev The bridge device.
193 * @param child The child device requesting resource suspension. This does
194 * not need to be the owner of @p r.
195 * @param type The resource type.
196 * @param r The resource to be suspended.
197 */
198METHOD void suspend_resource {
199	device_t dev;
200	device_t child;
201	int type;
202	struct resource *r;
203} DEFAULT bhndb_null_suspend_resource;
204
205/**
206 * Attempt to re-enable a resource previously suspended by
207 * BHNDB_SUSPEND_RESOURCE().
208 *
209 * Bridge resources required by the reference may not be available, in which
210 * case an error will be returned and the resource mapped by @p r must not be
211 * used in any capacity.
212 *
213 * Requests to resume a non-suspended resource will be ignored.
214 *
215 * @param dev The bridge device.
216 * @param child The child device requesting resource suspension. This does
217 * not need to be the owner of @p r.
218 * @param type The resource type.
219 * @param r The resource to be suspended.
220 */
221METHOD int resume_resource {
222	device_t dev;
223	device_t child;
224	int type;
225	struct resource *r;
226} DEFAULT bhndb_null_resume_resource;
227
228/**
229 * Enable bridge-level interrupt routing for @p child.
230 *
231 * @param dev The bridge device.
232 * @param child The bhnd child device for which interrupts should be routed.
233 */
234METHOD int route_interrupts {
235	device_t dev;
236	device_t child;
237} DEFAULT bhndb_null_route_interrupts;
238
239/**
240 * Set a given register window's base address.
241 *
242 * @param dev The bridge device.
243 * @param win The register window.
244 * @param addr The address to be configured for @p win.
245 *
246 * @retval 0 success
247 * @retval ENODEV The provided @p win is not memory-mapped on the bus or does
248 * not support setting a base address.
249 * @retval non-zero failure
250 */
251METHOD int set_window_addr {
252	device_t dev;
253	const struct bhndb_regwin *win;
254	bhnd_addr_t addr;
255} DEFAULT bhndb_null_set_window_addr;
256
257/**
258 * Map a bridged interrupt resource to its corresponding host interrupt source,
259 * if any.
260 *
261 * @param dev The bridge device.
262 * @param irq The bridged interrupt resource.
263 * @param[out] isrc The host interrupt source to which the bridged interrupt
264 * is routed.
265 *
266 * @retval 0 success
267 * @retval non-zero if mapping @p irq otherwise fails, a regular unix error code
268 * will be returned.
269 */
270METHOD int map_intr_isrc {
271	device_t dev;
272	struct resource *irq;
273	struct bhndb_intr_isrc **isrc;
274} DEFAULT bhndb_null_map_intr_isrc;
275