xref: /freebsd/sys/dev/bhnd/bhndb/bhndb_if.m (revision 20f8619da05e2775ef7b381c5df080d621fa8332)
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_init_full_config(device_t dev, device_t child,
60	    const struct bhndb_hw_priority *priority_table)
61	{
62		panic("bhndb_init_full_config unimplemented");
63	}
64
65	static device_t
66	bhndb_null_find_hostb_device(device_t dev, device_t child)
67	{
68		panic("bhndb_find_hostb_device unimplemented");
69	}
70
71	static void
72	bhndb_null_suspend_resource(device_t dev, device_t child, int type,
73	    struct resource *r)
74	{
75		panic("bhndb_suspend_resource unimplemented");
76	}
77
78	static int
79	bhndb_null_resume_resource(device_t dev, device_t child, int type,
80	    struct resource *r)
81	{
82		panic("bhndb_resume_resource unimplemented");
83	}
84
85	static int
86	bhndb_null_set_window_addr(device_t dev,
87	    const struct bhndb_regwin *rw, bhnd_addr_t addr)
88	{
89		panic("bhndb_set_window_addr unimplemented");
90	}
91}
92
93/**
94 * Return the chip identification information for @p child.
95 *
96 * @param dev The parent device of @p child.
97 * @param child The bhndb-attached device.
98 */
99METHOD const struct bhnd_chipid * get_chipid {
100	device_t dev;
101	device_t child;
102} DEFAULT bhndb_null_get_chipid;
103
104/**
105 * Perform final bridge hardware configuration after @p child has fully
106 * enumerated its children.
107 *
108 * This must be called by any bhndb-attached bus device; this allows the
109 * bridge to perform final configuration based on the hardware information
110 * enumerated by the child bus.
111 *
112 * When calling this method:
113 * - Any bus resources previously allocated by @p child must be deallocated.
114 * - The @p child bus must have performed initial enumeration -- but not
115 *   probe or attachment -- of its children.
116 *
117 * @param dev The bridge device.
118 * @param child The bhnd bus device attached to @p dev.
119 * @param hw_priority The hardware priority table to be used when determining
120 * the bridge resource allocation strategy.
121 */
122METHOD int init_full_config {
123	device_t dev;
124	device_t child;
125	const struct bhndb_hw_priority *priority_table;
126} DEFAULT bhndb_null_init_full_config;
127
128/**
129 * Locate the active host bridge core for the attached bhnd bus.
130 *
131 * @param dev The bridge device.
132 * @param child The bhnd bus device attached to @p dev.
133 */
134METHOD device_t find_hostb_device {
135	device_t dev;
136	device_t child;
137} DEFAULT bhndb_null_find_hostb_device;
138
139/**
140 * Mark a resource as 'suspended', gauranteeing to the bridge that no
141 * further use of the resource will be made until BHNDB_RESUME_RESOURCE()
142 * is called.
143 *
144 * Bridge resources consumed by the reference may be released; these will
145 * be reacquired if BHNDB_RESUME_RESOURCE() completes successfully.
146 *
147 * Requests to suspend a suspended resource will be ignored.
148 *
149 * @param dev The bridge device.
150 * @param child The child device requesting resource suspension. This does
151 * not need to be the owner of @p r.
152 * @param type The resource type.
153 * @param r The resource to be suspended.
154 */
155METHOD void suspend_resource {
156	device_t dev;
157	device_t child;
158	int type;
159	struct resource *r;
160} DEFAULT bhndb_null_suspend_resource;
161
162/**
163 * Attempt to re-enable a resource previously suspended by
164 * BHNDB_SUSPEND_RESOURCE().
165 *
166 * Bridge resources required by the reference may not be available, in which
167 * case an error will be returned and the resource mapped by @p r must not be
168 * used in any capacity.
169 *
170 * Requests to resume a non-suspended resource will be ignored.
171 *
172 * @param dev The bridge device.
173 * @param child The child device requesting resource suspension. This does
174 * not need to be the owner of @p r.
175 * @param type The resource type.
176 * @param r The resource to be suspended.
177 */
178METHOD int resume_resource {
179	device_t dev;
180	device_t child;
181	int type;
182	struct resource *r;
183} DEFAULT bhndb_null_resume_resource;
184
185/**
186 * Set a given register window's base address.
187 *
188 * @param dev The bridge device.
189 * @param win The register window.
190 * @param addr The address to be configured for @p win.
191 *
192 * @retval 0 success
193 * @retval ENODEV The provided @p win is not memory-mapped on the bus or does
194 * not support setting a base address.
195 * @retval non-zero failure
196 */
197METHOD int set_window_addr {
198	device_t dev;
199	const struct bhndb_regwin *win;
200	bhnd_addr_t addr;
201} DEFAULT bhndb_null_set_window_addr;
202