2 # Copyright (c) 2015 Landon Fuller <landon@landonf.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/types.h>
31 #include <dev/bhnd/bhnd_types.h>
36 # bhnd(4) bus interface
40 /* forward declarations */
41 struct bhnd_core_info;
48 #include <sys/systm.h>
50 #include <dev/bhnd/bhndvar.h>
52 static struct bhnd_chipid *
53 bhnd_bus_null_get_chipid(device_t dev, device_t child)
55 panic("bhnd_bus_get_chipid unimplemented");
59 bhnd_bus_null_is_hostb_device(device_t dev, device_t child)
61 panic("bhnd_bus_is_hostb_device unimplemented");
65 bhnd_bus_null_is_hw_disabled(device_t dev, device_t child)
67 panic("bhnd_bus_is_hw_disabled unimplemented");
71 bhnd_bus_null_get_probe_order(device_t dev, device_t child)
73 panic("bhnd_bus_get_probe_order unimplemented");
77 bhnd_bus_null_get_port_rid(device_t dev, device_t child,
78 bhnd_port_type port_type, u_int port, u_int region)
84 bhnd_bus_null_decode_port_rid(device_t dev, device_t child, int type,
85 int rid, bhnd_port_type *port_type, u_int *port, u_int *region)
91 bhnd_bus_null_get_region_addr(device_t dev, device_t child,
92 bhnd_port_type type, u_int port, u_int region, bhnd_addr_t *addr,
99 bhnd_bus_null_read_nvram_var(device_t dev, device_t child,
100 const char *name, void *buf, size_t *size)
108 * Returns true if @p child is serving as a host bridge for the bhnd
111 * The default implementation will walk the parent device tree until
112 * the root node is hit, returning false.
114 * @param dev The device whose child is being examined.
115 * @param child The child device.
117 METHOD bool is_hostb_device {
120 } DEFAULT bhnd_bus_null_is_hostb_device;
123 * Return true if the hardware components required by @p child are unpopulated
124 * or otherwise unusable.
126 * In some cases, enumerated devices may have pins that are left floating, or
127 * the hardware may otherwise be non-functional; this method allows a parent
128 * device to explicitly specify if a successfully enumerated @p child should
131 * @param dev The device whose child is being examined.
132 * @param child The child device.
134 METHOD bool is_hw_disabled {
137 } DEFAULT bhnd_bus_null_is_hw_disabled;
140 * Return the probe (and attach) order for @p child.
142 * All devices on the bhnd(4) bus will be probed, attached, or resumed in
143 * ascending order; they will be suspended, shutdown, and detached in
146 * The following device methods will be dispatched in ascending probe order
153 * The following device methods will be dispatched in descending probe order
156 * - DEVICE_SHUTDOWN()
160 * @param dev The device whose child is being examined.
161 * @param child The child device.
163 * Refer to BHND_PROBE_* and BHND_PROBE_ORDER_* for the standard set of
166 METHOD int get_probe_order {
169 } DEFAULT bhnd_bus_null_get_probe_order;
172 * Return the BHND chip identification for the parent bus.
174 * @param dev The device whose child is being examined.
175 * @param child The child device.
177 METHOD const struct bhnd_chipid * get_chipid {
180 } DEFAULT bhnd_bus_null_get_chipid;
183 * Reset the device's hardware core.
185 * @param dev The parent of @p child.
186 * @param child The device to be reset.
187 * @param flags Device-specific core flags to be supplied on reset.
190 * @retval non-zero error
192 METHOD int reset_core {
199 * Suspend a device hardware core.
201 * @param dev The parent of @p child.
202 * @param child The device to be reset.
205 * @retval non-zero error
207 METHOD int suspend_core {
213 * Allocate a bhnd resource.
215 * This method's semantics are functionally identical to the bus API of the same
216 * name; refer to BUS_ALLOC_RESOURCE for complete documentation.
218 METHOD struct bhnd_resource * alloc_resource {
227 } DEFAULT bhnd_bus_generic_alloc_resource;
230 * Release a bhnd resource.
232 * This method's semantics are functionally identical to the bus API of the same
233 * name; refer to BUS_RELEASE_RESOURCE for complete documentation.
235 METHOD int release_resource {
240 struct bhnd_resource *res;
241 } DEFAULT bhnd_bus_generic_release_resource;
244 * Activate a bhnd resource.
246 * This method's semantics are functionally identical to the bus API of the same
247 * name; refer to BUS_ACTIVATE_RESOURCE for complete documentation.
249 METHOD int activate_resource {
254 struct bhnd_resource *r;
255 } DEFAULT bhnd_bus_generic_activate_resource;
258 * Deactivate a bhnd resource.
260 * This method's semantics are functionally identical to the bus API of the same
261 * name; refer to BUS_DEACTIVATE_RESOURCE for complete documentation.
263 METHOD int deactivate_resource {
268 struct bhnd_resource *r;
269 } DEFAULT bhnd_bus_generic_deactivate_resource;
272 * Return true if @p region_num is a valid region on @p port_num of
273 * @p type attached to @p child.
275 * @param dev The device whose child is being examined.
276 * @param child The child device.
277 * @param type The port type being queried.
278 * @param port_num The port number being queried.
279 * @param region_num The region number being queried.
281 METHOD bool is_region_valid {
290 * Return the number of ports of type @p type attached to @p child.
292 * @param dev The device whose child is being examined.
293 * @param child The child device.
294 * @param type The port type being queried.
296 METHOD u_int get_port_count {
303 * Return the number of memory regions mapped to @p child @p port of
306 * @param dev The device whose child is being examined.
307 * @param child The child device.
308 * @param port The port number being queried.
309 * @param type The port type being queried.
311 METHOD u_int get_region_count {
319 * Return the SYS_RES_MEMORY resource-ID for a port/region pair attached to
322 * @param dev The bus device.
323 * @param child The bhnd child.
324 * @param port_type The port type.
325 * @param port_num The index of the child interconnect port.
326 * @param region_num The index of the port-mapped address region.
328 * @retval -1 No such port/region found.
330 METHOD int get_port_rid {
333 bhnd_port_type port_type;
336 } DEFAULT bhnd_bus_null_get_port_rid;
340 * Decode a port / region pair on @p child defined by @p type and @p rid.
342 * @param dev The bus device.
343 * @param child The bhnd child.
344 * @param type The resource type.
345 * @param rid The resource ID.
346 * @param[out] port_type The port's type.
347 * @param[out] port The port identifier.
348 * @param[out] region The identifier of the memory region on @p port.
351 * @retval non-zero No matching type/rid found.
353 METHOD int decode_port_rid {
358 bhnd_port_type *port_type;
361 } DEFAULT bhnd_bus_null_decode_port_rid;
364 * Get the address and size of @p region on @p port.
366 * @param dev The bus device.
367 * @param child The bhnd child.
368 * @param port_type The port type.
369 * @param port The port identifier.
370 * @param region The identifier of the memory region on @p port.
371 * @param[out] region_addr The region's base address.
372 * @param[out] region_size The region's size.
375 * @retval non-zero No matching port/region found.
377 METHOD int get_region_addr {
380 bhnd_port_type port_type;
383 bhnd_addr_t *region_addr;
384 bhnd_size_t *region_size;
385 } DEFAULT bhnd_bus_null_get_region_addr;
388 * Read an NVRAM variable.
390 * It is the responsibility of the bus to delegate this request to
391 * the appropriate NVRAM child device, or to a parent bus implementation.
393 * @param dev The bus device.
394 * @param child The requesting device.
395 * @param name The NVRAM variable name.
396 * @param[out] buf On success, the requested value will be written
397 * to this buffer. This argment may be NULL if
398 * the value is not desired.
399 * @param[in,out] size The capacity of @p buf. On success, will be set
400 * to the actual size of the requested value.
403 * @retval ENOENT The requested variable was not found.
404 * @retval ENOMEM If @p buf is non-NULL and a buffer of @p size is too
405 * small to hold the requested value.
406 * @retval non-zero If reading @p name otherwise fails, a regular unix
407 * error code will be returned.
409 METHOD int read_nvram_var {
415 } DEFAULT bhnd_bus_null_read_nvram_var;
418 /** An implementation of bus_read_1() compatible with bhnd_resource */
419 METHOD uint8_t read_1 {
422 struct bhnd_resource *r;
426 /** An implementation of bus_read_2() compatible with bhnd_resource */
427 METHOD uint16_t read_2 {
430 struct bhnd_resource *r;
434 /** An implementation of bus_read_4() compatible with bhnd_resource */
435 METHOD uint32_t read_4 {
438 struct bhnd_resource *r;
442 /** An implementation of bus_write_1() compatible with bhnd_resource */
443 METHOD void write_1 {
446 struct bhnd_resource *r;
451 /** An implementation of bus_write_2() compatible with bhnd_resource */
452 METHOD void write_2 {
455 struct bhnd_resource *r;
460 /** An implementation of bus_write_4() compatible with bhnd_resource */
461 METHOD void write_4 {
464 struct bhnd_resource *r;
469 /** An implementation of bus_barrier() compatible with bhnd_resource */
470 METHOD void barrier {
473 struct bhnd_resource *r;