Lines Matching +full:continue +full:- +full:on +full:- +full:error
1 /*-
2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
49 * @param[out] bhndb On success, the probed and attached bhndb bridge device.
50 * @param unit The device unit number, or -1 to select the next available unit
54 * @retval non-zero Failed to attach the bhndb device.
59 int error; in bhndb_attach_bridge() local
65 if (!(error = device_probe_and_attach(*bhndb))) in bhndb_attach_bridge()
71 return (error); in bhndb_attach_bridge()
84 /* Skip non-allocated resources */ in bhndb_do_suspend_resources()
85 if (rle->res == NULL) in bhndb_do_suspend_resources()
86 continue; in bhndb_do_suspend_resources()
88 BHNDB_SUSPEND_RESOURCE(device_get_parent(dev), dev, rle->type, in bhndb_do_suspend_resources()
89 rle->res); in bhndb_do_suspend_resources()
94 * Helper function for implementing BUS_RESUME_CHILD() on bridged
112 int error; in bhnd_generic_br_suspend_child() local
121 if ((error = bhnd_generic_suspend_child(dev, child))) in bhnd_generic_br_suspend_child()
122 return (error); in bhnd_generic_br_suspend_child()
136 * Helper function for implementing BUS_RESUME_CHILD() on bridged
153 int error; in bhnd_generic_br_resume_child() local
168 /* Skip non-allocated resources */ in bhnd_generic_br_resume_child()
169 if (rle->res == NULL) in bhnd_generic_br_resume_child()
170 continue; in bhnd_generic_br_resume_child()
172 error = BHNDB_RESUME_RESOURCE(device_get_parent(dev), dev, in bhnd_generic_br_resume_child()
173 rle->type, rle->res); in bhnd_generic_br_resume_child()
174 if (error) { in bhnd_generic_br_resume_child()
177 return (error); in bhnd_generic_br_resume_child()
182 if ((error = bhnd_generic_resume_child(dev, child))) { in bhnd_generic_br_resume_child()
187 return (error); in bhnd_generic_br_resume_child()
205 for (u_int i = 0; hr->resource_specs[i].type != -1; i++) { in bhndb_host_resource_for_range()
206 struct resource *r = hr->resources[i]; in bhndb_host_resource_for_range()
208 if (hr->resource_specs[i].type != type) in bhndb_host_resource_for_range()
209 continue; in bhndb_host_resource_for_range()
213 continue; in bhndb_host_resource_for_range()
215 if (rman_get_end(r) < (start + count - 1)) in bhndb_host_resource_for_range()
216 continue; in bhndb_host_resource_for_range()
239 rspecs = hr->resource_specs; in bhndb_host_resource_for_regwin()
240 for (u_int i = 0; rspecs[i].type != -1; i++) { in bhndb_host_resource_for_regwin()
241 if (win->res.type != rspecs[i].type) in bhndb_host_resource_for_regwin()
242 continue; in bhndb_host_resource_for_regwin()
244 if (win->res.rid != rspecs[i].rid) in bhndb_host_resource_for_regwin()
245 continue; in bhndb_host_resource_for_regwin()
248 return (hr->resources[i]); in bhndb_host_resource_for_regwin()
251 device_printf(hr->owner, "missing regwin resource spec " in bhndb_host_resource_for_regwin()
252 "(type=%d, rid=%d)\n", win->res.type, win->res.rid); in bhndb_host_resource_for_regwin()
273 int error; in bhndb_alloc_resources() local
285 r->dev = dev; in bhndb_alloc_resources()
286 r->cfg = cfg; in bhndb_alloc_resources()
287 r->res = NULL; in bhndb_alloc_resources()
288 r->min_prio = BHNDB_PRIORITY_NONE; in bhndb_alloc_resources()
289 STAILQ_INIT(&r->bus_regions); in bhndb_alloc_resources()
290 STAILQ_INIT(&r->bus_intrs); in bhndb_alloc_resources()
292 mtx_init(&r->dw_steal_mtx, device_get_nameunit(dev), in bhndb_alloc_resources()
296 r->ht_mem_rman.rm_start = 0; in bhndb_alloc_resources()
297 r->ht_mem_rman.rm_end = ~0; in bhndb_alloc_resources()
298 r->ht_mem_rman.rm_type = RMAN_ARRAY; in bhndb_alloc_resources()
299 r->ht_mem_rman.rm_descr = "BHNDB host memory"; in bhndb_alloc_resources()
300 if ((error = rman_init(&r->ht_mem_rman))) { in bhndb_alloc_resources()
301 device_printf(r->dev, "could not initialize ht_mem_rman\n"); in bhndb_alloc_resources()
307 r->br_mem_rman.rm_start = 0; in bhndb_alloc_resources()
308 r->br_mem_rman.rm_end = BUS_SPACE_MAXADDR_32BIT; in bhndb_alloc_resources()
309 r->br_mem_rman.rm_type = RMAN_ARRAY; in bhndb_alloc_resources()
310 r->br_mem_rman.rm_descr = "BHNDB bridged memory"; in bhndb_alloc_resources()
312 if ((error = rman_init(&r->br_mem_rman))) { in bhndb_alloc_resources()
313 device_printf(r->dev, "could not initialize br_mem_rman\n"); in bhndb_alloc_resources()
318 error = rman_manage_region(&r->br_mem_rman, 0, BUS_SPACE_MAXADDR_32BIT); in bhndb_alloc_resources()
319 if (error) { in bhndb_alloc_resources()
320 device_printf(r->dev, "could not configure br_mem_rman\n"); in bhndb_alloc_resources()
325 r->br_irq_rman.rm_start = 0; in bhndb_alloc_resources()
326 r->br_irq_rman.rm_end = RM_MAX_END; in bhndb_alloc_resources()
327 r->br_irq_rman.rm_type = RMAN_ARRAY; in bhndb_alloc_resources()
328 r->br_irq_rman.rm_descr = "BHNDB bridged interrupts"; in bhndb_alloc_resources()
330 if ((error = rman_init(&r->br_irq_rman))) { in bhndb_alloc_resources()
331 device_printf(r->dev, "could not initialize br_irq_rman\n"); in bhndb_alloc_resources()
336 error = rman_manage_region(&r->br_irq_rman, 0, RM_MAX_END); in bhndb_alloc_resources()
337 if (error) { in bhndb_alloc_resources()
338 device_printf(r->dev, "could not configure br_irq_rman\n"); in bhndb_alloc_resources()
344 r->dwa_count = bhndb_regwin_count(cfg->register_windows, in bhndb_alloc_resources()
346 if (r->dwa_count >= INT_MAX) { in bhndb_alloc_resources()
347 device_printf(r->dev, "max dynamic regwin count exceeded\n"); in bhndb_alloc_resources()
352 r->dw_alloc = malloc(sizeof(r->dw_alloc[0]) * r->dwa_count, M_BHND, in bhndb_alloc_resources()
354 if (r->dw_alloc == NULL) in bhndb_alloc_resources()
358 r->dwa_freelist = bit_alloc(r->dwa_count, M_BHND, M_NOWAIT); in bhndb_alloc_resources()
359 if (r->dwa_freelist == NULL) in bhndb_alloc_resources()
365 for (win = cfg->register_windows; in bhndb_alloc_resources()
366 win->win_type != BHNDB_REGWIN_T_INVALID; win++) in bhndb_alloc_resources()
370 /* Skip non-DYN windows */ in bhndb_alloc_resources()
371 if (win->win_type != BHNDB_REGWIN_T_DYN) in bhndb_alloc_resources()
372 continue; in bhndb_alloc_resources()
375 if (win->win_size == 0) { in bhndb_alloc_resources()
376 device_printf(r->dev, "ignoring zero-length dynamic " in bhndb_alloc_resources()
378 continue; in bhndb_alloc_resources()
380 last_window_size = win->win_size; in bhndb_alloc_resources()
381 } else if (last_window_size != win->win_size) { in bhndb_alloc_resources()
390 device_printf(r->dev, "devices that vend multiple " in bhndb_alloc_resources()
396 dwa = &r->dw_alloc[rnid]; in bhndb_alloc_resources()
397 dwa->win = win; in bhndb_alloc_resources()
398 dwa->parent_res = NULL; in bhndb_alloc_resources()
399 dwa->rnid = rnid; in bhndb_alloc_resources()
400 dwa->target = 0x0; in bhndb_alloc_resources()
402 LIST_INIT(&dwa->refs); in bhndb_alloc_resources()
407 error = bhndb_alloc_host_resources(&r->res, dev, parent_dev, r->cfg); in bhndb_alloc_resources()
408 if (error) { in bhndb_alloc_resources()
409 device_printf(r->dev, in bhndb_alloc_resources()
410 "could not allocate host resources on %s: %d\n", in bhndb_alloc_resources()
411 device_get_nameunit(parent_dev), error); in bhndb_alloc_resources()
417 for (size_t i = 0; i < r->dwa_count; i++) { in bhndb_alloc_resources()
421 dwa = &r->dw_alloc[i]; in bhndb_alloc_resources()
422 win = dwa->win; in bhndb_alloc_resources()
425 dwa->parent_res = bhndb_host_resource_for_regwin(r->res, win); in bhndb_alloc_resources()
426 if (dwa->parent_res == NULL) { in bhndb_alloc_resources()
427 device_printf(r->dev, "no host resource found for %u " in bhndb_alloc_resources()
430 win->win_type, in bhndb_alloc_resources()
431 (uintmax_t)win->win_offset, in bhndb_alloc_resources()
432 (uintmax_t)win->win_size); in bhndb_alloc_resources()
434 error = ENXIO; in bhndb_alloc_resources()
438 if (rman_get_size(dwa->parent_res) < win->win_offset + in bhndb_alloc_resources()
439 win->win_size) in bhndb_alloc_resources()
441 device_printf(r->dev, "resource %d too small for " in bhndb_alloc_resources()
443 rman_get_rid(dwa->parent_res), in bhndb_alloc_resources()
444 (unsigned long long) win->win_offset, in bhndb_alloc_resources()
445 (unsigned long long) win->win_size); in bhndb_alloc_resources()
447 error = EINVAL; in bhndb_alloc_resources()
453 for (u_int i = 0; r->res->resource_specs[i].type != -1; i++) { in bhndb_alloc_resources()
456 /* skip non-memory resources */ in bhndb_alloc_resources()
457 if (r->res->resource_specs[i].type != SYS_RES_MEMORY) in bhndb_alloc_resources()
458 continue; in bhndb_alloc_resources()
461 res = r->res->resources[i]; in bhndb_alloc_resources()
462 error = rman_manage_region(&r->ht_mem_rman, in bhndb_alloc_resources()
464 if (error) { in bhndb_alloc_resources()
465 device_printf(r->dev, in bhndb_alloc_resources()
467 "ht_mem_rman: %d\n", error); in bhndb_alloc_resources()
476 rman_fini(&r->ht_mem_rman); in bhndb_alloc_resources()
479 rman_fini(&r->br_mem_rman); in bhndb_alloc_resources()
482 rman_fini(&r->br_irq_rman); in bhndb_alloc_resources()
484 if (r->dw_alloc != NULL) in bhndb_alloc_resources()
485 free(r->dw_alloc, M_BHND); in bhndb_alloc_resources()
487 if (r->dwa_freelist != NULL) in bhndb_alloc_resources()
488 free(r->dwa_freelist, M_BHND); in bhndb_alloc_resources()
490 if (r->res != NULL) in bhndb_alloc_resources()
491 bhndb_release_host_resources(r->res); in bhndb_alloc_resources()
493 mtx_destroy(&r->dw_steal_mtx); in bhndb_alloc_resources()
507 * @param[out] dmat On success, the newly created DMA tag.
510 * @retval non-zero if creating the new DMA tag otherwise fails, a regular
511 * unix error code will be returned.
521 int error; in bhndb_dma_tag_create() local
527 dt_mask = (translation->addr_mask | translation->addrext_mask); in bhndb_dma_tag_create()
535 if (translation->addr_mask < maxsegsz) in bhndb_dma_tag_create()
536 maxsegsz = translation->addr_mask; in bhndb_dma_tag_create()
539 error = bus_dma_tag_create(parent_dmat, in bhndb_dma_tag_create()
547 if (error) { in bhndb_dma_tag_create()
549 error); in bhndb_dma_tag_create()
550 return (error); in bhndb_dma_tag_create()
576 for (int i = 0; i < br->dwa_count; i++) { in bhndb_free_resources()
577 dwa = &br->dw_alloc[i]; in bhndb_free_resources()
581 continue; in bhndb_free_resources()
583 device_printf(br->dev, in bhndb_free_resources()
584 "leaked dynamic register window %d\n", dwa->rnid); in bhndb_free_resources()
590 STAILQ_FOREACH(ih, &br->bus_intrs, ih_link) { in bhndb_free_resources()
591 device_printf(br->dev, "interrupt handler leaked %p\n", in bhndb_free_resources()
592 ih->ih_cookiep); in bhndb_free_resources()
601 if (br->res != NULL) in bhndb_free_resources()
602 bhndb_release_host_resources(br->res); in bhndb_free_resources()
605 for (size_t i = 0; i < br->dwa_count; i++) { in bhndb_free_resources()
606 dwa = &br->dw_alloc[i]; in bhndb_free_resources()
608 LIST_FOREACH_SAFE(dwr, &dwa->refs, dw_link, dwr_next) { in bhndb_free_resources()
615 STAILQ_FOREACH_SAFE(region, &br->bus_regions, link, r_next) { in bhndb_free_resources()
616 STAILQ_REMOVE(&br->bus_regions, region, bhndb_region, link); in bhndb_free_resources()
621 rman_fini(&br->ht_mem_rman); in bhndb_free_resources()
622 rman_fini(&br->br_mem_rman); in bhndb_free_resources()
623 rman_fini(&br->br_irq_rman); in bhndb_free_resources()
625 free(br->dw_alloc, M_BHND); in bhndb_free_resources()
626 free(br->dwa_freelist, M_BHND); in bhndb_free_resources()
628 mtx_destroy(&br->dw_steal_mtx); in bhndb_free_resources()
636 * On success, the caller assumes ownership of the allocated host resources,
639 * @param[out] resources On success, the allocated host resources.
655 int error; in bhndb_alloc_host_resources() local
660 hr->owner = parent_dev; in bhndb_alloc_host_resources()
661 hr->cfg = hwcfg; in bhndb_alloc_host_resources()
662 hr->resource_specs = NULL; in bhndb_alloc_host_resources()
663 hr->resources = NULL; in bhndb_alloc_host_resources()
664 hr->dma_tags = NULL; in bhndb_alloc_host_resources()
665 hr->num_dma_tags = 0; in bhndb_alloc_host_resources()
669 for (size_t i = 0; hwcfg->resource_specs[i].type != -1; i++) in bhndb_alloc_host_resources()
674 for (dt = hwcfg->dma_translations; dt != NULL && in bhndb_alloc_host_resources()
678 if ((dt->base_addr & dt->addr_mask) != 0) { in bhndb_alloc_host_resources()
681 (uintmax_t)dt->base_addr, (uintmax_t)dt->addr_mask); in bhndb_alloc_host_resources()
683 error = EINVAL; in bhndb_alloc_host_resources()
687 if ((dt->addrext_mask & dt->addr_mask) != 0) { in bhndb_alloc_host_resources()
690 (uintmax_t)dt->addrext_mask, in bhndb_alloc_host_resources()
691 (uintmax_t)dt->addr_mask); in bhndb_alloc_host_resources()
693 error = EINVAL; in bhndb_alloc_host_resources()
702 hr->dma_tags = malloc(sizeof(*hr->dma_tags) * ndt, M_BHND, in bhndb_alloc_host_resources()
705 error = bhndb_dma_tag_create(dev, parent_dmat, in bhndb_alloc_host_resources()
706 &hwcfg->dma_translations[i], &hr->dma_tags[i]); in bhndb_alloc_host_resources()
707 if (error) in bhndb_alloc_host_resources()
710 hr->num_dma_tags++; in bhndb_alloc_host_resources()
713 /* Allocate space for a non-const copy of our resource_spec in bhndb_alloc_host_resources()
716 hr->resource_specs = malloc(sizeof(hr->resource_specs[0]) * (nres + 1), in bhndb_alloc_host_resources()
721 hr->resource_specs[i] = hwcfg->resource_specs[i]; in bhndb_alloc_host_resources()
723 hr->resource_specs[nres].type = -1; in bhndb_alloc_host_resources()
726 hr->resources = malloc(sizeof(hr->resources[0]) * nres, M_BHND, in bhndb_alloc_host_resources()
730 error = bus_alloc_resources(hr->owner, hr->resource_specs, in bhndb_alloc_host_resources()
731 hr->resources); in bhndb_alloc_host_resources()
732 if (error) { in bhndb_alloc_host_resources()
734 "%s: %d\n", device_get_nameunit(parent_dev), error); in bhndb_alloc_host_resources()
742 if (hr->resource_specs != NULL) in bhndb_alloc_host_resources()
743 free(hr->resource_specs, M_BHND); in bhndb_alloc_host_resources()
745 if (hr->resources != NULL) in bhndb_alloc_host_resources()
746 free(hr->resources, M_BHND); in bhndb_alloc_host_resources()
748 for (size_t i = 0; i < hr->num_dma_tags; i++) in bhndb_alloc_host_resources()
749 bus_dma_tag_destroy(hr->dma_tags[i]); in bhndb_alloc_host_resources()
751 if (hr->dma_tags != NULL) in bhndb_alloc_host_resources()
752 free(hr->dma_tags, M_BHND); in bhndb_alloc_host_resources()
756 return (error); in bhndb_alloc_host_resources()
767 bus_release_resources(hr->owner, hr->resource_specs, hr->resources); in bhndb_release_host_resources()
769 for (size_t i = 0; i < hr->num_dma_tags; i++) in bhndb_release_host_resources()
770 bus_dma_tag_destroy(hr->dma_tags[i]); in bhndb_release_host_resources()
772 free(hr->resources, M_BHND); in bhndb_release_host_resources()
773 free(hr->resource_specs, M_BHND); in bhndb_release_host_resources()
774 free(hr->dma_tags, M_BHND); in bhndb_release_host_resources()
781 * This function uses a heuristic valid on all known PCI/PCIe/PCMCIA-bridged
784 * - The core must have a Broadcom vendor ID.
785 * - The core devclass must match the bridge type.
786 * - The core must be the first device on the bus with the bridged device
817 continue; in bhndb_find_hostb_core()
820 if (match != NULL && match_core_idx < match->core_idx) in bhndb_find_hostb_core()
821 continue; in bhndb_find_hostb_core()
824 match_core_idx = match->core_idx; in bhndb_find_hostb_core()
845 * @retval non-NULL success
858 isrc->is_owner = owner; in bhndb_alloc_intr_isrc()
859 isrc->is_rid = rid; in bhndb_alloc_intr_isrc()
860 isrc->is_res = bus_alloc_resource(owner, SYS_RES_IRQ, &isrc->is_rid, in bhndb_alloc_intr_isrc()
862 if (isrc->is_res == NULL) { in bhndb_alloc_intr_isrc()
878 bus_release_resource(isrc->is_owner, SYS_RES_IRQ, isrc->is_rid, in bhndb_free_intr_isrc()
879 isrc->is_res); in bhndb_free_intr_isrc()
890 * @retval non-NULL success
900 ih->ih_owner = owner; in bhndb_alloc_intr_handler()
901 ih->ih_res = r; in bhndb_alloc_intr_handler()
902 ih->ih_isrc = isrc; in bhndb_alloc_intr_handler()
903 ih->ih_cookiep = NULL; in bhndb_alloc_intr_handler()
904 ih->ih_active = false; in bhndb_alloc_intr_handler()
918 KASSERT(!ih->ih_active, ("free of active interrupt handler %p", in bhndb_free_intr_handler()
919 ih->ih_cookiep)); in bhndb_free_intr_handler()
934 KASSERT(!ih->ih_active, ("duplicate registration of interrupt " in bhndb_register_intr_handler()
935 "handler %p", ih->ih_cookiep)); in bhndb_register_intr_handler()
936 KASSERT(ih->ih_cookiep != NULL, ("missing cookiep")); in bhndb_register_intr_handler()
938 ih->ih_active = true; in bhndb_register_intr_handler()
939 STAILQ_INSERT_HEAD(&br->bus_intrs, ih, ih_link); in bhndb_register_intr_handler()
952 KASSERT(ih->ih_active, ("duplicate deregistration of interrupt " in bhndb_deregister_intr_handler()
953 "handler %p", ih->ih_cookiep)); in bhndb_deregister_intr_handler()
958 STAILQ_REMOVE(&br->bus_intrs, ih, bhndb_intr_handler, ih_link); in bhndb_deregister_intr_handler()
959 ih->ih_active = false; in bhndb_deregister_intr_handler()
967 * @param cookiep The interrupt handler's bus-assigned cookiep value.
974 STAILQ_FOREACH(ih, &br->bus_intrs, ih_link) { in bhndb_find_intr_handler()
991 * @param[out] start On success, the minimum supported start address.
992 * @param[out] end On success, the maximum supported end address.
1008 STAILQ_FOREACH(ih, &br->bus_intrs, ih_link) { in bhndb_find_resource_limits()
1009 if (ih->ih_res == r) in bhndb_find_resource_limits()
1010 continue; in bhndb_find_resource_limits()
1024 *start = dynamic->target; in bhndb_find_resource_limits()
1025 *end = dynamic->target + dynamic->win->win_size - 1; in bhndb_find_resource_limits()
1032 if (sregion != NULL && sregion->static_regwin != NULL) { in bhndb_find_resource_limits()
1033 *start = sregion->addr; in bhndb_find_resource_limits()
1034 *end = sregion->addr + sregion->size - 1; in bhndb_find_resource_limits()
1044 device_printf(br->dev, "unknown resource type: %d\n", in bhndb_find_resource_limits()
1063 * @retval non-zero if adding the bus region fails.
1085 STAILQ_INSERT_HEAD(&br->bus_regions, reg, link); in bhndb_add_resource_region()
1108 if (region->static_regwin == NULL) in bhndb_has_static_region_mapping()
1112 r_addr += region->size; in bhndb_has_static_region_mapping()
1139 STAILQ_FOREACH(region, &br->bus_regions, link) { in bhndb_find_resource_region()
1141 if (addr < region->addr) in bhndb_find_resource_region()
1142 continue; in bhndb_find_resource_region()
1144 if (addr + size > region->addr + region->size) in bhndb_find_resource_region()
1145 continue; in bhndb_find_resource_region()
1165 LIST_FOREACH(rentry, &dwa->refs, dw_link) { in bhndb_dw_find_resource_entry()
1166 struct resource *dw_res = rentry->dw_res; in bhndb_dw_find_resource_entry()
1174 continue; in bhndb_dw_find_resource_entry()
1198 for (size_t i = 0; i < br->dwa_count; i++) { in bhndb_dw_find_resource()
1199 dwa = &br->dw_alloc[i]; in bhndb_dw_find_resource()
1203 continue; in bhndb_dw_find_resource()
1233 for (size_t i = 0; i < br->dwa_count; i++) { in bhndb_dw_find_mapping()
1234 dwr = &br->dw_alloc[i]; in bhndb_dw_find_mapping()
1235 win = dwr->win; in bhndb_dw_find_mapping()
1238 if (addr < dwr->target) in bhndb_dw_find_mapping()
1239 continue; in bhndb_dw_find_mapping()
1241 if (addr + size > dwr->target + win->win_size) in bhndb_dw_find_mapping()
1242 continue; in bhndb_dw_find_mapping()
1269 ("double-retain of dynamic window for same resource")); in bhndb_dw_retain()
1272 * within a non-sleepable lock */ in bhndb_dw_retain()
1277 rentry->dw_res = res; in bhndb_dw_retain()
1278 LIST_INSERT_HEAD(&dwa->refs, rentry, dw_link); in bhndb_dw_retain()
1281 bit_set(br->dwa_freelist, dwa->rnid); in bhndb_dw_retain()
1309 if (LIST_EMPTY(&dwa->refs)) in bhndb_dw_release()
1310 bit_clear(br->dwa_freelist, dwa->rnid); in bhndb_dw_release()
1321 * @param dev The device on which to issue the BHNDB_SET_WINDOW_ADDR() request.
1328 * @retval non-zero no usable register window available.
1336 int error; in bhndb_dw_set_addr() local
1338 rw = dwa->win; in bhndb_dw_set_addr()
1340 KASSERT(bhndb_dw_is_free(br, dwa) || mtx_owned(&br->dw_steal_mtx), in bhndb_dw_set_addr()
1341 ("attempting to set the target address on an in-use window")); in bhndb_dw_set_addr()
1343 /* Page-align the target address */ in bhndb_dw_set_addr()
1344 offset = addr % rw->win_size; in bhndb_dw_set_addr()
1345 dwa->target = addr - offset; in bhndb_dw_set_addr()
1348 if (rw->win_size - offset < size) in bhndb_dw_set_addr()
1352 error = BHNDB_SET_WINDOW_ADDR(dev, dwa->win, dwa->target); in bhndb_dw_set_addr()
1353 if (error) { in bhndb_dw_set_addr()
1354 dwa->target = 0x0; in bhndb_dw_set_addr()
1355 return (error); in bhndb_dw_set_addr()
1362 * Steal an in-use allocation record from @p br, returning the record's current
1363 * target in @p saved on success.
1375 * @retval non-NULL success
1384 ("attempting to steal an in-use window while free windows remain")); in bhndb_dw_steal()
1387 if (br->dwa_count == 0) in bhndb_dw_steal()
1395 * stealing an in-use existing register window. in bhndb_dw_steal()
1397 mtx_lock_spin(&br->dw_steal_mtx); in bhndb_dw_steal()
1399 dw_stolen = &br->dw_alloc[0]; in bhndb_dw_steal()
1400 *saved = dw_stolen->target; in bhndb_dw_steal()
1407 * @param dev The device on which to issue a BHNDB_SET_WINDOW_ADDR() request.
1416 int error; in bhndb_dw_return_stolen() local
1418 mtx_assert(&br->dw_steal_mtx, MA_OWNED); in bhndb_dw_return_stolen()
1420 error = bhndb_dw_set_addr(dev, br, dwa, saved, 0); in bhndb_dw_return_stolen()
1421 if (error) { in bhndb_dw_return_stolen()
1423 (uintmax_t)saved, error); in bhndb_dw_return_stolen()
1426 mtx_unlock_spin(&br->dw_steal_mtx); in bhndb_dw_return_stolen()
1444 for (rw = table; rw->win_type != BHNDB_REGWIN_T_INVALID; rw++) { in bhndb_regwin_count()
1445 if (type == BHNDB_REGWIN_T_INVALID || rw->win_type == type) in bhndb_regwin_count()
1468 for (rw = table; rw->win_type != BHNDB_REGWIN_T_INVALID; rw++) in bhndb_regwin_find_type()
1470 if (rw->win_type == type && rw->win_size >= min_size) in bhndb_regwin_find_type()
1482 * @param unit The required core unit, or -1.
1499 for (rw = table; rw->win_type != BHNDB_REGWIN_T_INVALID; rw++) in bhndb_regwin_find_core()
1503 /* Match on core, port, and region attributes */ in bhndb_regwin_find_core()
1504 if (rw->win_type != BHNDB_REGWIN_T_CORE) in bhndb_regwin_find_core()
1505 continue; in bhndb_regwin_find_core()
1507 if (rw->d.core.class != class) in bhndb_regwin_find_core()
1508 continue; in bhndb_regwin_find_core()
1510 if (unit != -1 && rw->d.core.unit != unit) in bhndb_regwin_find_core()
1511 continue; in bhndb_regwin_find_core()
1513 if (rw->d.core.port_type != port_type) in bhndb_regwin_find_core()
1514 continue; in bhndb_regwin_find_core()
1516 if (rw->d.core.port != port) in bhndb_regwin_find_core()
1517 continue; in bhndb_regwin_find_core()
1519 if (rw->d.core.region != region) in bhndb_regwin_find_core()
1520 continue; in bhndb_regwin_find_core()
1524 if (rw->d.core.offset > offset) in bhndb_regwin_find_core()
1525 continue; in bhndb_regwin_find_core()
1527 rw_offset = offset - rw->d.core.offset; in bhndb_regwin_find_core()
1529 if (rw->win_size < rw_offset) in bhndb_regwin_find_core()
1530 continue; in bhndb_regwin_find_core()
1532 if (rw->win_size - rw_offset < min_size) in bhndb_regwin_find_core()
1533 continue; in bhndb_regwin_find_core()
1545 * - BHND_REGWIN_T_CORE
1546 * - BHND_REGWIN_T_DYN
1550 * @param unit The required core unit, or -1.
1573 /* Fall back on a generic dynamic window */ in bhndb_regwin_find_best()
1589 if (regw->win_type != BHNDB_REGWIN_T_CORE) in bhndb_regwin_match_core()
1593 if (bhnd_core_class(core) != regw->d.core.class) in bhndb_regwin_match_core()
1597 if (core->unit != regw->d.core.unit) in bhndb_regwin_match_core()
1617 for (hp = table; hp->ports != NULL; hp++) { in bhndb_hw_priority_find_core()
1618 if (bhnd_core_matches(core, &hp->match)) in bhndb_hw_priority_find_core()
1645 for (u_int i = 0; i < hp->num_ports; i++) { in bhndb_hw_priorty_find_port()
1646 const struct bhndb_port_priority *pp = &hp->ports[i]; in bhndb_hw_priorty_find_port()
1648 if (pp->type != port_type) in bhndb_hw_priorty_find_port()
1649 continue; in bhndb_hw_priorty_find_port()
1651 if (pp->port != port) in bhndb_hw_priorty_find_port()
1652 continue; in bhndb_hw_priorty_find_port()
1654 if (pp->region != region) in bhndb_hw_priorty_find_port()
1655 continue; in bhndb_hw_priorty_find_port()