xref: /freebsd/sys/dev/bhnd/bhndb/bhndb_if.m (revision ca6a6373bdaed010d6cbfb27f7249ae96009409d)
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
30#include <sys/param.h>
31#include <sys/bus.h>
32
33#include <machine/bus.h>
34#include <sys/rman.h>
35#include <machine/resource.h>
36
37#include <dev/bhnd/bhnd.h>
38
39#
40# bhndb bridge device interface.
41#
42
43INTERFACE bhndb;
44
45HEADER {
46	struct bhndb_intr_isrc;
47	struct bhndb_regwin;
48	struct bhndb_hw;
49	struct bhndb_hw_priority;
50}
51
52CODE {
53	#include <sys/systm.h>
54	#include <dev/bhnd/bhndb/bhndbvar.h>
55
56	static const struct bhnd_chipid *
57	bhndb_null_get_chipid(device_t dev, device_t child)
58	{
59		panic("bhndb_get_chipid unimplemented");
60	}
61
62	static int
63	bhndb_null_populate_board_info(device_t dev, device_t child,
64	    struct bhnd_board_info *info)
65	{
66		panic("bhndb_populate_board_info unimplemented");
67	}
68
69	static int
70	bhndb_null_is_core_disabled(device_t dev, device_t child,
71	    struct bhnd_core_info *core)
72	{
73		panic("bhndb_is_core_disabled unimplemented");
74	}
75
76	static int
77	bhndb_null_get_hostb_core(device_t dev, device_t child,
78	    struct bhnd_core_info *core)
79	{
80		panic("bhndb_get_hostb_core unimplemented");
81	}
82
83	static void
84	bhndb_null_suspend_resource(device_t dev, device_t child, int type,
85	    struct resource *r)
86	{
87		panic("bhndb_suspend_resource unimplemented");
88	}
89
90	static int
91	bhndb_null_resume_resource(device_t dev, device_t child, int type,
92	    struct resource *r)
93	{
94		panic("bhndb_resume_resource unimplemented");
95	}
96
97	static int
98	bhndb_null_route_interrupts(device_t dev, device_t child)
99	{
100		panic("bhndb_route_interrupts unimplemented");
101	}
102
103	static int
104	bhndb_null_set_window_addr(device_t dev,
105	    const struct bhndb_regwin *rw, bhnd_addr_t addr)
106	{
107		panic("bhndb_set_window_addr unimplemented");
108	}
109
110	static int
111	bhndb_null_map_intr_isrc(device_t dev, struct resource *irq,
112	    struct bhndb_intr_isrc **isrc)
113	{
114		panic("bhndb_map_intr_isrc unimplemented");
115	}
116}
117
118/**
119 * Return the chip identification information for @p child.
120 *
121 * @param dev The parent device of @p child.
122 * @param child The bhndb-attached device.
123 */
124METHOD const struct bhnd_chipid * get_chipid {
125	device_t dev;
126	device_t child;
127} DEFAULT bhndb_null_get_chipid;
128
129/**
130 * Populate @p info with board info known only to the bridge,
131 * deferring to any existing initialized fields in @p info.
132 *
133 * @param dev The parent device of @p child.
134 * @param child The bhndb-attached device.
135 * @param[in,out] info A board info structure previously initialized with any
136 * information available from NVRAM.
137 */
138METHOD int populate_board_info {
139	device_t dev;
140	device_t child;
141	struct bhnd_board_info *info;
142} DEFAULT bhndb_null_populate_board_info;
143
144/**
145 * Return true if the hardware required by @p core is unpopulated or
146 * otherwise unusable.
147 *
148 * In some cases, the core's pins may be left floating, or the hardware
149 * may otherwise be non-functional; this method allows the parent device
150 * to explicitly specify whether @p core should be disabled.
151 *
152 * @param dev The parent device of @p child.
153 * @param child The attached bhnd device.
154 * @param core A core discovered on @p child.
155 */
156METHOD bool is_core_disabled {
157	device_t dev;
158	device_t child;
159	struct bhnd_core_info *core;
160} DEFAULT bhndb_null_is_core_disabled;
161
162/**
163 * Get the host bridge core info for the attached bhnd bus.
164 *
165 * @param	dev	The bridge device.
166 * @param	child	The bhnd bus device attached to @p dev.
167 * @param[out]	core	Will be populated with the host bridge core info, if
168 *			found.
169 *
170 * @retval 0		success
171 * @retval ENOENT	No host bridge core found.
172 * @retval non-zero	If locating the host bridge core otherwise fails, a
173 *			regular UNIX error code should be returned.
174 */
175METHOD int get_hostb_core {
176	device_t dev;
177	device_t child;
178	struct bhnd_core_info *core;
179} DEFAULT bhndb_null_get_hostb_core;
180
181/**
182 * Mark a resource as 'suspended', gauranteeing to the bridge that no
183 * further use of the resource will be made until BHNDB_RESUME_RESOURCE()
184 * is called.
185 *
186 * Bridge resources consumed by the reference may be released; these will
187 * be reacquired if BHNDB_RESUME_RESOURCE() completes successfully.
188 *
189 * Requests to suspend a suspended resource will be ignored.
190 *
191 * @param dev The bridge device.
192 * @param child The child device requesting resource suspension. This does
193 * not need to be the owner of @p r.
194 * @param type The resource type.
195 * @param r The resource to be suspended.
196 */
197METHOD void suspend_resource {
198	device_t dev;
199	device_t child;
200	int type;
201	struct resource *r;
202} DEFAULT bhndb_null_suspend_resource;
203
204/**
205 * Attempt to re-enable a resource previously suspended by
206 * BHNDB_SUSPEND_RESOURCE().
207 *
208 * Bridge resources required by the reference may not be available, in which
209 * case an error will be returned and the resource mapped by @p r must not be
210 * used in any capacity.
211 *
212 * Requests to resume a non-suspended resource will be ignored.
213 *
214 * @param dev The bridge device.
215 * @param child The child device requesting resource suspension. This does
216 * not need to be the owner of @p r.
217 * @param type The resource type.
218 * @param r The resource to be suspended.
219 */
220METHOD int resume_resource {
221	device_t dev;
222	device_t child;
223	int type;
224	struct resource *r;
225} DEFAULT bhndb_null_resume_resource;
226
227/**
228 * Enable bridge-level interrupt routing for @p child.
229 *
230 * @param dev The bridge device.
231 * @param child The bhnd child device for which interrupts should be routed.
232 */
233METHOD int route_interrupts {
234	device_t dev;
235	device_t child;
236} DEFAULT bhndb_null_route_interrupts;
237
238/**
239 * Set a given register window's base address.
240 *
241 * @param dev The bridge device.
242 * @param win The register window.
243 * @param addr The address to be configured for @p win.
244 *
245 * @retval 0 success
246 * @retval ENODEV The provided @p win is not memory-mapped on the bus or does
247 * not support setting a base address.
248 * @retval non-zero failure
249 */
250METHOD int set_window_addr {
251	device_t dev;
252	const struct bhndb_regwin *win;
253	bhnd_addr_t addr;
254} DEFAULT bhndb_null_set_window_addr;
255
256/**
257 * Map a bridged interrupt resource to its corresponding host interrupt source,
258 * if any.
259 *
260 * @param dev The bridge device.
261 * @param irq The bridged interrupt resource.
262 * @param[out] isrc The host interrupt source to which the bridged interrupt
263 * is routed.
264 *
265 * @retval 0 success
266 * @retval non-zero if mapping @p irq otherwise fails, a regular unix error code
267 * will be returned.
268 */
269METHOD int map_intr_isrc {
270	device_t dev;
271	struct resource *irq;
272	struct bhndb_intr_isrc **isrc;
273} DEFAULT bhndb_null_map_intr_isrc;
274