xref: /freebsd/sys/dev/bhnd/bhndb/bhnd_bhndb.c (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1 /*-
2  * Copyright (c) 2015-2016 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  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  */
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/bus.h>
36 #include <sys/module.h>
37 
38 #include <dev/bhnd/bhnd_ids.h>
39 #include <dev/bhnd/bhnd.h>
40 
41 #include "bhndbvar.h"
42 
43 /*
44  * bhnd(4) driver mix-in providing a shared common methods for
45  * bhnd devices attached via a bhndb bridge.
46  */
47 
48 static int
49 bhnd_bhndb_read_board_info(device_t dev, device_t child,
50     struct bhnd_board_info *info)
51 {
52 	int	error;
53 
54 	/* Initialize with NVRAM-derived values */
55 	if ((error = bhnd_bus_generic_read_board_info(dev, child, info)))
56 		return (error);
57 
58 	/* Let the bridge fill in any additional data */
59 	return (BHNDB_POPULATE_BOARD_INFO(device_get_parent(dev), dev, info));
60 }
61 
62 static bhnd_attach_type
63 bhnd_bhndb_get_attach_type(device_t dev, device_t child)
64 {
65 	/* It's safe to assume that a bridged device is always an adapter */
66 	return (BHND_ATTACH_ADAPTER);
67 }
68 
69 static device_method_t bhnd_bhndb_methods[] = {
70 	/* BHND interface */
71 	DEVMETHOD(bhnd_bus_get_attach_type,	bhnd_bhndb_get_attach_type),
72 	DEVMETHOD(bhnd_bus_read_board_info,	bhnd_bhndb_read_board_info),
73 
74 	DEVMETHOD_END
75 };
76 
77 DEFINE_CLASS_0(bhnd, bhnd_bhndb_driver, bhnd_bhndb_methods, 0);
78