2 # Copyright (c) 2016-2017 Landon Fuller <landon@landonf.org>
3 # Copyright (c) 2017 The FreeBSD Foundation
6 # Portions of this software were developed by Landon Fuller
7 # under sponsorship from the FreeBSD Foundation.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
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.
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.
31 #include <sys/param.h>
34 #include <machine/bus.h>
36 #include <machine/resource.h>
38 #include <dev/bhnd/bhnd.h>
39 #include <dev/bhnd/bhnd_erom_types.h>
44 # bhnd(4) device enumeration.
46 # Provides a common parser interface to the incompatible device enumeration
47 # tables used by bhnd(4) buses.
51 /* forward declarations */
56 * Probe to see if this device enumeration class supports the bhnd bus at
57 * @p addr, returning a standard newbus device probe result (see BUS_PROBE_*)
58 * and the probed chip identification.
60 * @param cls The erom class to probe.
61 * @param eio A bus I/O instance, configured with a mapping of
63 * @param base_addr Address of the first bus core.
64 * @param hint Hint used to identify the device. If chipset
65 * supports standard chip identification registers
66 * within the first core, this parameter should be
68 * @param[out] cid On success, the probed chip identifier.
70 * @retval 0 if this is the only possible device enumeration
71 * parser for the probed bus.
72 * @retval negative if the probe succeeds, a negative value should be
73 * returned; the parser returning the highest negative
74 * value will be selected to handle device enumeration.
75 * @retval ENXIO If the bhnd bus type is not handled by this parser.
76 * @retval positive if an error occurs during probing, a regular unix error
77 * code should be returned.
79 STATICMETHOD int probe {
80 bhnd_erom_class_t *cls;
81 struct bhnd_erom_io *eio;
82 const struct bhnd_chipid *hint;
83 struct bhnd_chipid *cid;
87 * Initialize a device enumeration table parser.
89 * @param erom The erom parser to initialize.
90 * @param cid The device's chip identifier.
91 * @param eio The bus I/O instance to use when reading the device
92 * enumeration table. On success, the erom parser assumes
93 * ownership of this instance.
95 * @retval non-zero if an error occurs initializing the EROM parser,
96 * a regular unix error code will be returned.
100 const struct bhnd_chipid *cid;
101 struct bhnd_erom_io *eio;
105 * Release all resources held by @p erom.
107 * @param erom An erom parser instance previously initialized via
108 * BHND_EROM_INIT() or BHND_EROM_INIT_STATIC().
115 * Parse all cores descriptors, returning the array in @p cores and the count
118 * The memory allocated for the table must be freed via
119 * BHND_EROM_FREE_CORE_TABLE().
121 * @param erom The erom parser to be queried.
122 * @param[out] cores The table of parsed core descriptors.
123 * @param[out] num_cores The number of core records in @p cores.
126 * @retval non-zero if an error occurs, a regular unix error code will
129 METHOD int get_core_table {
131 struct bhnd_core_info **cores;
136 * Free any memory allocated in a previous call to BHND_EROM_GET_CORE_TABLE().
138 * @param erom The erom parser instance.
139 * @param cores A core table allocated by @p erom.
141 METHOD void free_core_table {
143 struct bhnd_core_info *cores;
147 * Locate the first core table entry in @p erom that matches @p desc.
149 * @param erom The erom parser to be queried.
150 * @param desc A core match descriptor.
151 * @param[out] core On success, the matching core info record.
154 * @retval ENOENT No core matching @p desc was found.
155 * @retval non-zero Reading or parsing failed.
157 METHOD int lookup_core {
159 const struct bhnd_core_match *desc;
160 struct bhnd_core_info *core;
164 * Locate the first core table entry in @p erom that matches @p desc,
165 * and return the specified port region's base address and size.
167 * If a core matching @p desc is not found, or the requested port region
168 * is not mapped to the matching core, ENOENT is returned.
170 * @param erom The erom parser to be queried.
171 * @param desc A core match descriptor.
172 * @param type The port type to search for.
173 * @param port The port to search for.
174 * @param region The port region to search for.
175 * @param[out] core If not NULL, will be populated with the matched core
176 * info record on success.
177 * @param[out] addr On success, the base address of the port region.
178 * @param[out] size On success, the total size of the port region.
181 * @retval ENOENT No core matching @p desc was found.
182 * @retval ENOENT No port region matching @p type, @p port, and @p region
184 * @retval non-zero Reading or parsing failed.
186 METHOD int lookup_core_addr {
188 const struct bhnd_core_match *desc;
192 struct bhnd_core_info *core;
198 * Enumerate and print all EROM table entries.
200 * @param erom The erom parser to be enumerated.
203 * @retval non-zero If an error occurs reading the EROM table, a regular
204 * unix error code will be returned.