2 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.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 * 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.
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.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
36 #include <dev/bhnd/bhndvar.h>
37 #include <dev/bhnd/bhnd_erom.h>
40 * Allocate and return a new device enumeration table parser.
42 * @param cls The parser class for which an instance will be
44 * @param parent The parent device from which EROM resources should
46 * @param rid The resource ID to be used when allocating EROM
48 * @param cid The device's chip identifier.
50 * @retval non-NULL success
51 * @retval NULL if an error occured allocating or initializing the
55 bhnd_erom_alloc(bhnd_erom_class_t *cls, const struct bhnd_chipid *cid,
56 device_t parent, int rid)
61 erom = (bhnd_erom_t *)kobj_create((kobj_class_t)cls, M_BHND,
64 if ((error = BHND_EROM_INIT(erom, cid, parent, rid))) {
65 printf("error initializing %s parser at %#jx with "
66 "rid %d: %d\n", cls->name, (uintmax_t)cid->enum_addr, rid,
69 kobj_delete((kobj_t)erom, M_BHND);
77 * Perform static initialization of aa device enumeration table parser using
78 * the provided bus space tag and handle.
80 * This may be used to initialize a caller-allocated erom instance state
81 * during early boot, prior to malloc availability.
83 * @param cls The parser class for which an instance will be
85 * @param erom The erom parser instance to initialize.
86 * @param esize The total available number of bytes allocated for
87 * @p erom. If this is less than is required by @p cls,
88 * ENOMEM will be returned.
89 * @param cid The device's chip identifier.
90 * @param bst Bus space tag.
91 * @param bsh Bus space handle mapping the device enumeration
95 * @retval ENOMEM if @p esize is smaller than required by @p cls.
96 * @retval non-zero if an error occurs initializing the EROM parser,
97 * a regular unix error code will be returned.
100 bhnd_erom_init_static(bhnd_erom_class_t *cls, bhnd_erom_t *erom, size_t esize,
101 const struct bhnd_chipid *cid, bus_space_tag_t bst, bus_space_handle_t bsh)
105 kcls = (kobj_class_t)cls;
107 /* Verify allocation size */
108 if (kcls->size > esize)
111 /* Perform instance initialization */
112 kobj_init_static((kobj_t)erom, kcls);
113 return (BHND_EROM_INIT_STATIC(erom, cid, bst, bsh));
117 * Release any resources held by a @p erom parser previously
118 * initialized via bhnd_erom_init_static().
120 * @param erom An erom parser instance previously initialized via
121 * bhnd_erom_init_static().
124 bhnd_erom_fini_static(bhnd_erom_t *erom)
126 return (BHND_EROM_FINI(erom));
130 * Release all resources held by a @p erom parser previously
131 * allocated via bhnd_erom_alloc().
133 * @param erom An erom parser instance previously allocated via
137 bhnd_erom_free(bhnd_erom_t *erom)
139 BHND_EROM_FINI(erom);
140 kobj_delete((kobj_t)erom, M_BHND);