| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ugen.c,v 1.171.2.1 2024/04/16 18:45:39 martin Exp $ */ | | 1 | /* $NetBSD: ugen.c,v 1.171.2.2 2024/04/16 18:59:49 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Lennart Augustsson (lennart@augustsson.net) at | | 8 | * by Lennart Augustsson (lennart@augustsson.net) at |
9 | * Carlstedt Research & Technology. | | 9 | * Carlstedt Research & Technology. |
10 | * | | 10 | * |
11 | * Copyright (c) 2006 BBN Technologies Corp. All rights reserved. | | 11 | * Copyright (c) 2006 BBN Technologies Corp. All rights reserved. |
12 | * Effort sponsored in part by the Defense Advanced Research Projects | | 12 | * Effort sponsored in part by the Defense Advanced Research Projects |
13 | * Agency (DARPA) and the Department of the Interior National Business | | 13 | * Agency (DARPA) and the Department of the Interior National Business |
14 | * Center under agreement number NBCHC050166. | | 14 | * Center under agreement number NBCHC050166. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | __KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.171.2.1 2024/04/16 18:45:39 martin Exp $"); | | 40 | __KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.171.2.2 2024/04/16 18:59:49 martin Exp $"); |
41 | | | 41 | |
42 | #ifdef _KERNEL_OPT | | 42 | #ifdef _KERNEL_OPT |
43 | #include "opt_compat_netbsd.h" | | 43 | #include "opt_compat_netbsd.h" |
44 | #include "opt_usb.h" | | 44 | #include "opt_usb.h" |
45 | #endif | | 45 | #endif |
46 | | | 46 | |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <sys/systm.h> | | 48 | #include <sys/systm.h> |
49 | #include <sys/kernel.h> | | 49 | #include <sys/kernel.h> |
50 | #include <sys/kmem.h> | | 50 | #include <sys/kmem.h> |
51 | #include <sys/device.h> | | 51 | #include <sys/device.h> |
52 | #include <sys/ioctl.h> | | 52 | #include <sys/ioctl.h> |
53 | #include <sys/conf.h> | | 53 | #include <sys/conf.h> |
| @@ -219,32 +219,38 @@ ugenif_get_unit(struct ugen_softc *sc) | | | @@ -219,32 +219,38 @@ ugenif_get_unit(struct ugen_softc *sc) |
219 | unsigned i; | | 219 | unsigned i; |
220 | | | 220 | |
221 | mutex_enter(&ugenif.lock); | | 221 | mutex_enter(&ugenif.lock); |
222 | for (i = 0, sc0 = RB_TREE_MIN(&ugenif.tree); | | 222 | for (i = 0, sc0 = RB_TREE_MIN(&ugenif.tree); |
223 | sc0 != NULL && i == sc0->sc_unit; | | 223 | sc0 != NULL && i == sc0->sc_unit; |
224 | i++, sc0 = RB_TREE_NEXT(&ugenif.tree, sc0)) | | 224 | i++, sc0 = RB_TREE_NEXT(&ugenif.tree, sc0)) |
225 | KASSERT(i < UINT_MAX); | | 225 | KASSERT(i < UINT_MAX); |
226 | KASSERT(rb_tree_find_node(&ugenif.tree, &i) == NULL); | | 226 | KASSERT(rb_tree_find_node(&ugenif.tree, &i) == NULL); |
227 | sc->sc_unit = i; | | 227 | sc->sc_unit = i; |
228 | sc0 = rb_tree_insert_node(&ugenif.tree, sc); | | 228 | sc0 = rb_tree_insert_node(&ugenif.tree, sc); |
229 | KASSERT(sc0 == sc); | | 229 | KASSERT(sc0 == sc); |
230 | KASSERT(rb_tree_find_node(&ugenif.tree, &i) == sc); | | 230 | KASSERT(rb_tree_find_node(&ugenif.tree, &i) == sc); |
231 | mutex_exit(&ugenif.lock); | | 231 | mutex_exit(&ugenif.lock); |
| | | 232 | |
| | | 233 | prop_dictionary_set_uint(device_properties(sc->sc_dev), |
| | | 234 | "ugen-unit", sc->sc_unit); |
232 | } | | 235 | } |
233 | | | 236 | |
234 | static void | | 237 | static void |
235 | ugenif_put_unit(struct ugen_softc *sc) | | 238 | ugenif_put_unit(struct ugen_softc *sc) |
236 | { | | 239 | { |
237 | | | 240 | |
| | | 241 | prop_dictionary_remove(device_properties(sc->sc_dev), |
| | | 242 | "ugen-unit"); |
| | | 243 | |
238 | mutex_enter(&ugenif.lock); | | 244 | mutex_enter(&ugenif.lock); |
239 | KASSERT(rb_tree_find_node(&ugenif.tree, &sc->sc_unit) == sc); | | 245 | KASSERT(rb_tree_find_node(&ugenif.tree, &sc->sc_unit) == sc); |
240 | rb_tree_remove_node(&ugenif.tree, sc); | | 246 | rb_tree_remove_node(&ugenif.tree, sc); |
241 | sc->sc_unit = -1; | | 247 | sc->sc_unit = -1; |
242 | mutex_exit(&ugenif.lock); | | 248 | mutex_exit(&ugenif.lock); |
243 | } | | 249 | } |
244 | | | 250 | |
245 | static struct ugen_softc * | | 251 | static struct ugen_softc * |
246 | ugenif_acquire(unsigned unit) | | 252 | ugenif_acquire(unsigned unit) |
247 | { | | 253 | { |
248 | struct ugen_softc *sc; | | 254 | struct ugen_softc *sc; |
249 | | | 255 | |
250 | mutex_enter(&ugenif.lock); | | 256 | mutex_enter(&ugenif.lock); |