xref: /freebsd/sys/dev/bhnd/bhndb/bhndb_if.m (revision b5864e6de2f3aa8eb9bb269ec86282598b5201b1)
1#-
2# Copyright (c) 2015 Landon Fuller <landon@landonf.org>
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24#
25# $FreeBSD$
26
27#include <sys/param.h>
28#include <sys/bus.h>
29
30#include <machine/bus.h>
31#include <sys/rman.h>
32#include <machine/resource.h>
33
34#include <dev/bhnd/bhnd.h>
35
36#
37# bhndb bridge device interface.
38#
39
40INTERFACE bhndb;
41
42HEADER {
43	struct bhndb_regwin;
44	struct bhndb_hw;
45	struct bhndb_hw_priority;
46}
47
48CODE {
49	#include <sys/systm.h>
50	#include <dev/bhnd/bhndb/bhndbvar.h>
51
52	static const struct bhnd_chipid *
53	bhndb_null_get_chipid(device_t dev, device_t child)
54	{
55		panic("bhndb_get_chipid unimplemented");
56	}
57
58	static int
59	bhndb_null_populate_board_info(device_t dev, device_t child,
60	    struct bhnd_board_info *info)
61	{
62		panic("bhndb_populate_board_info unimplemented");
63	}
64
65	static int
66	bhndb_null_init_full_config(device_t dev, device_t child,
67	    const struct bhndb_hw_priority *priority_table)
68	{
69		panic("bhndb_init_full_config unimplemented");
70	}
71
72	static device_t
73	bhndb_null_find_hostb_device(device_t dev, device_t child)
74	{
75		panic("bhndb_find_hostb_device unimplemented");
76	}
77
78	static void
79	bhndb_null_suspend_resource(device_t dev, device_t child, int type,
80	    struct resource *r)
81	{
82		panic("bhndb_suspend_resource unimplemented");
83	}
84
85	static int
86	bhndb_null_resume_resource(device_t dev, device_t child, int type,
87	    struct resource *r)
88	{
89		panic("bhndb_resume_resource unimplemented");
90	}
91
92	static int
93	bhndb_null_set_window_addr(device_t dev,
94	    const struct bhndb_regwin *rw, bhnd_addr_t addr)
95	{
96		panic("bhndb_set_window_addr unimplemented");
97	}
98}
99
100/**
101 * Return the chip identification information for @p child.
102 *
103 * @param dev The parent device of @p child.
104 * @param child The bhndb-attached device.
105 */
106METHOD const struct bhnd_chipid * get_chipid {
107	device_t dev;
108	device_t child;
109} DEFAULT bhndb_null_get_chipid;
110
111/**
112 * Populate @p info with board info known only to the bridge,
113 * deferring to any existing initialized fields in @p info.
114 *
115 * @param dev The parent device of @p child.
116 * @param child The bhndb-attached device.
117 * @param[in,out] info A board info structure previously initialized with any
118 * information available from NVRAM.
119 */
120METHOD int populate_board_info {
121	device_t dev;
122	device_t child;
123	struct bhnd_board_info *info;
124} DEFAULT bhndb_null_populate_board_info;
125
126/**
127 * Perform final bridge hardware configuration after @p child has fully
128 * enumerated its children.
129 *
130 * This must be called by any bhndb-attached bus device; this allows the
131 * bridge to perform final configuration based on the hardware information
132 * enumerated by the child bus.
133 *
134 * When calling this method:
135 * - Any bus resources previously allocated by @p child must be deallocated.
136 * - The @p child bus must have performed initial enumeration -- but not
137 *   probe or attachment -- of its children.
138 *
139 * @param dev The bridge device.
140 * @param child The bhnd bus device attached to @p dev.
141 * @param hw_priority The hardware priority table to be used when determining
142 * the bridge resource allocation strategy.
143 */
144METHOD int init_full_config {
145	device_t dev;
146	device_t child;
147	const struct bhndb_hw_priority *priority_table;
148} DEFAULT bhndb_null_init_full_config;
149
150/**
151 * Locate the active host bridge core for the attached bhnd bus.
152 *
153 * @param dev The bridge device.
154 * @param child The bhnd bus device attached to @p dev.
155 */
156METHOD device_t find_hostb_device {
157	device_t dev;
158	device_t child;
159} DEFAULT bhndb_null_find_hostb_device;
160
161/**
162 * Mark a resource as 'suspended', gauranteeing to the bridge that no
163 * further use of the resource will be made until BHNDB_RESUME_RESOURCE()
164 * is called.
165 *
166 * Bridge resources consumed by the reference may be released; these will
167 * be reacquired if BHNDB_RESUME_RESOURCE() completes successfully.
168 *
169 * Requests to suspend a suspended resource will be ignored.
170 *
171 * @param dev The bridge device.
172 * @param child The child device requesting resource suspension. This does
173 * not need to be the owner of @p r.
174 * @param type The resource type.
175 * @param r The resource to be suspended.
176 */
177METHOD void suspend_resource {
178	device_t dev;
179	device_t child;
180	int type;
181	struct resource *r;
182} DEFAULT bhndb_null_suspend_resource;
183
184/**
185 * Attempt to re-enable a resource previously suspended by
186 * BHNDB_SUSPEND_RESOURCE().
187 *
188 * Bridge resources required by the reference may not be available, in which
189 * case an error will be returned and the resource mapped by @p r must not be
190 * used in any capacity.
191 *
192 * Requests to resume a non-suspended resource will be ignored.
193 *
194 * @param dev The bridge device.
195 * @param child The child device requesting resource suspension. This does
196 * not need to be the owner of @p r.
197 * @param type The resource type.
198 * @param r The resource to be suspended.
199 */
200METHOD int resume_resource {
201	device_t dev;
202	device_t child;
203	int type;
204	struct resource *r;
205} DEFAULT bhndb_null_resume_resource;
206
207/**
208 * Set a given register window's base address.
209 *
210 * @param dev The bridge device.
211 * @param win The register window.
212 * @param addr The address to be configured for @p win.
213 *
214 * @retval 0 success
215 * @retval ENODEV The provided @p win is not memory-mapped on the bus or does
216 * not support setting a base address.
217 * @retval non-zero failure
218 */
219METHOD int set_window_addr {
220	device_t dev;
221	const struct bhndb_regwin *win;
222	bhnd_addr_t addr;
223} DEFAULT bhndb_null_set_window_addr;
224