Lines Matching +full:irqs +full:- +full:map +full:- +full:range
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
81 * By default all VMD devices remap children MSI/MSI-X interrupts into their
99 * MSI-X can use different addresses, but we have limited number of MSI-X
104 "Maximum number of MSI-X vectors per device");
126 for (t = vmd_devs; t->vmd_name != NULL; t++) { in vmd_probe()
127 if (vid == t->vmd_vid && did == t->vmd_did) { in vmd_probe()
128 device_set_desc(dev, t->vmd_name); in vmd_probe()
142 if (sc->psc.bus.rman.rm_end != 0) in vmd_free()
143 rman_fini(&sc->psc.bus.rman); in vmd_free()
144 if (sc->psc.mem.rman.rm_end != 0) in vmd_free()
145 rman_fini(&sc->psc.mem.rman); in vmd_free()
146 while ((u = LIST_FIRST(&sc->vmd_users)) != NULL) { in vmd_free()
150 if (sc->vmd_irq != NULL) { in vmd_free()
151 for (i = 0; i < sc->vmd_msix_count; i++) { in vmd_free()
152 vi = &sc->vmd_irq[i]; in vmd_free()
153 if (vi->vi_res == NULL) in vmd_free()
155 bus_teardown_intr(sc->psc.dev, vi->vi_res, in vmd_free()
156 vi->vi_handle); in vmd_free()
157 bus_release_resource(sc->psc.dev, SYS_RES_IRQ, in vmd_free()
158 vi->vi_rid, vi->vi_res); in vmd_free()
161 free(sc->vmd_irq, M_DEVBUF); in vmd_free()
162 sc->vmd_irq = NULL; in vmd_free()
163 pci_release_msi(sc->psc.dev); in vmd_free()
165 if (sc->vmd_regs_res[i] != NULL) in vmd_free()
166 bus_release_resource(sc->psc.dev, SYS_RES_MEMORY, in vmd_free()
167 sc->vmd_regs_rid[i], sc->vmd_regs_res[i]); in vmd_free()
180 if (b < sc->vmd_bus_start || b > sc->vmd_bus_end) in vmd_read_config()
183 offset = ((b - sc->vmd_bus_start) << 20) + (s << 15) + (f << 12) + reg; in vmd_read_config()
187 return (bus_read_4(sc->vmd_regs_res[0], offset)); in vmd_read_config()
189 return (bus_read_2(sc->vmd_regs_res[0], offset)); in vmd_read_config()
191 return (bus_read_1(sc->vmd_regs_res[0], offset)); in vmd_read_config()
206 if (b < sc->vmd_bus_start || b > sc->vmd_bus_end) in vmd_write_config()
209 offset = ((b - sc->vmd_bus_start) << 20) + (s << 15) + (f << 12) + reg; in vmd_write_config()
213 return (bus_write_4(sc->vmd_regs_res[0], offset, val)); in vmd_write_config()
215 return (bus_write_2(sc->vmd_regs_res[0], offset, val)); in vmd_write_config()
217 return (bus_write_1(sc->vmd_regs_res[0], offset, val)); in vmd_write_config()
241 * handler to make PCI code setup and enable the MSI-X vector. in vmd_intr()
261 sc->psc.dev = dev; in vmd_attach()
262 sc->psc.domain = PCI_DOMAINMAX - device_get_unit(dev); in vmd_attach()
267 sc->vmd_regs_rid[i] = PCIR_BAR(j); in vmd_attach()
272 if ((sc->vmd_regs_res[i] = bus_alloc_resource_any(dev, in vmd_attach()
273 SYS_RES_MEMORY, &sc->vmd_regs_rid[i], RF_ACTIVE)) == NULL) { in vmd_attach()
281 for (t = vmd_devs; t->vmd_name != NULL; t++) { in vmd_attach()
282 if (vid == t->vmd_vid && did == t->vmd_did) in vmd_attach()
286 sc->vmd_bus_start = 0; in vmd_attach()
287 if ((t->flags & BUS_RESTRICT) && in vmd_attach()
291 sc->vmd_bus_start = 0; in vmd_attach()
294 sc->vmd_bus_start = 128; in vmd_attach()
297 sc->vmd_bus_start = 224; in vmd_attach()
304 sc->vmd_bus_end = MIN(PCI_BUSMAX, sc->vmd_bus_start + in vmd_attach()
305 (rman_get_size(sc->vmd_regs_res[0]) >> 20) - 1); in vmd_attach()
307 bus = &sc->psc.bus; in vmd_attach()
308 bus->sec = sc->vmd_bus_start; in vmd_attach()
309 bus->sub = sc->vmd_bus_end; in vmd_attach()
310 bus->dev = dev; in vmd_attach()
311 bus->rman.rm_start = 0; in vmd_attach()
312 bus->rman.rm_end = PCI_BUSMAX; in vmd_attach()
313 bus->rman.rm_type = RMAN_ARRAY; in vmd_attach()
315 bus->rman.rm_descr = strdup(buf, M_DEVBUF); in vmd_attach()
316 error = rman_init(&bus->rman); in vmd_attach()
319 bus->rman.rm_end = 0; in vmd_attach()
322 error = rman_manage_region(&bus->rman, sc->vmd_bus_start, in vmd_attach()
323 sc->vmd_bus_end); in vmd_attach()
329 w = &sc->psc.mem; in vmd_attach()
330 w->rman.rm_type = RMAN_ARRAY; in vmd_attach()
332 w->rman.rm_descr = strdup(buf, M_DEVBUF); in vmd_attach()
333 error = rman_init(&w->rman); in vmd_attach()
336 w->rman.rm_end = 0; in vmd_attach()
339 error = rman_manage_region(&w->rman, in vmd_attach()
340 rman_get_start(sc->vmd_regs_res[1]), in vmd_attach()
341 rman_get_end(sc->vmd_regs_res[1])); in vmd_attach()
346 error = rman_manage_region(&w->rman, in vmd_attach()
347 rman_get_start(sc->vmd_regs_res[2]) + 0x2000, in vmd_attach()
348 rman_get_end(sc->vmd_regs_res[2])); in vmd_attach()
354 LIST_INIT(&sc->vmd_users); in vmd_attach()
355 sc->vmd_fist_vector = (t->flags & VECTOR_OFFSET) ? 1 : 0; in vmd_attach()
356 sc->vmd_msix_count = pci_msix_count(dev); in vmd_attach()
357 if (vmd_bypass_msi && (t->flags & CAN_BYPASS_MSI)) { in vmd_attach()
358 sc->vmd_msix_count = 0; in vmd_attach()
360 } else if (pci_alloc_msix(dev, &sc->vmd_msix_count) == 0) { in vmd_attach()
361 sc->vmd_irq = malloc(sizeof(struct vmd_irq) * in vmd_attach()
362 sc->vmd_msix_count, M_DEVBUF, M_WAITOK | M_ZERO); in vmd_attach()
363 for (i = 0; i < sc->vmd_msix_count; i++) { in vmd_attach()
364 vi = &sc->vmd_irq[i]; in vmd_attach()
365 vi->vi_rid = i + 1; in vmd_attach()
366 vi->vi_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, in vmd_attach()
367 &vi->vi_rid, RF_ACTIVE | RF_SHAREABLE); in vmd_attach()
368 if (vi->vi_res == NULL) { in vmd_attach()
372 vi->vi_irq = rman_get_start(vi->vi_res); in vmd_attach()
373 if (bus_setup_intr(dev, vi->vi_res, INTR_TYPE_MISC | in vmd_attach()
374 INTR_MPSAFE, vmd_intr, NULL, vi, &vi->vi_handle)) { in vmd_attach()
377 vi->vi_rid, vi->vi_res); in vmd_attach()
378 vi->vi_res = NULL; in vmd_attach()
385 sc->vmd_dma_tag = bus_get_dma_tag(dev); in vmd_attach()
386 sc->psc.child = device_add_child(dev, "pci", DEVICE_UNIT_ANY); in vmd_attach()
404 if (sc->vmd_msix_count == 0) in vmd_detach()
415 return (sc->vmd_dma_tag); in vmd_get_dma_tag()
425 return (&sc->psc.mem.rman); in vmd_get_rman()
427 return (&sc->psc.bus.rman); in vmd_get_rman()
453 "allocated memory range (%#jx-%#jx) for rid %d of %s\n", in vmd_alloc_resource()
459 "allocated bus range (%ju-%ju) for rid %d of %s\n", in vmd_alloc_resource()
511 if (rman_get_start(sc->vmd_regs_res[i]) <= rman_get_start(r) && in vmd_find_parent_resource()
512 rman_get_end(sc->vmd_regs_res[i]) >= rman_get_end(r)) in vmd_find_parent_resource()
513 return (sc->vmd_regs_res[i]); in vmd_find_parent_resource()
520 struct resource_map_request *argsp, struct resource_map *map) in vmd_map_resource() argument
541 args.offset = start - rman_get_start(pres); in vmd_map_resource()
543 return (bus_map_resource(dev, pres, &args, map)); in vmd_map_resource()
548 struct resource_map *map) in vmd_unmap_resource() argument
556 return (bus_unmap_resource(dev, pres, map)); in vmd_unmap_resource()
569 int *irqs) in vmd_alloc_msi() argument
575 if (sc->vmd_msix_count == 0) { in vmd_alloc_msi()
577 child, count, maxcount, irqs)); in vmd_alloc_msi()
582 LIST_FOREACH(u, &sc->vmd_users, viu_link) { in vmd_alloc_msi()
583 if (u->viu_child == child) in vmd_alloc_msi()
587 for (i = sc->vmd_fist_vector; i < sc->vmd_msix_count; i++) { in vmd_alloc_msi()
588 if (best > sc->vmd_irq[i].vi_nusers) { in vmd_alloc_msi()
589 best = sc->vmd_irq[i].vi_nusers; in vmd_alloc_msi()
595 u->viu_child = child; in vmd_alloc_msi()
596 u->viu_vector = ibest; in vmd_alloc_msi()
597 LIST_INSERT_HEAD(&sc->vmd_users, u, viu_link); in vmd_alloc_msi()
598 sc->vmd_irq[ibest].vi_nusers += count; in vmd_alloc_msi()
601 irqs[i] = sc->vmd_irq[ibest].vi_irq; in vmd_alloc_msi()
606 vmd_release_msi(device_t dev, device_t child, int count, int *irqs) in vmd_release_msi() argument
611 if (sc->vmd_msix_count == 0) { in vmd_release_msi()
613 child, count, irqs)); in vmd_release_msi()
616 LIST_FOREACH(u, &sc->vmd_users, viu_link) { in vmd_release_msi()
617 if (u->viu_child == child) { in vmd_release_msi()
618 sc->vmd_irq[u->viu_vector].vi_nusers -= count; in vmd_release_msi()
634 if (sc->vmd_msix_count == 0) { in vmd_alloc_msix()
640 LIST_FOREACH(u, &sc->vmd_users, viu_link) { in vmd_alloc_msix()
641 if (u->viu_child == child) in vmd_alloc_msix()
647 for (i = sc->vmd_fist_vector; i < sc->vmd_msix_count; i++) { in vmd_alloc_msix()
648 if (best > sc->vmd_irq[i].vi_nusers) { in vmd_alloc_msix()
649 best = sc->vmd_irq[i].vi_nusers; in vmd_alloc_msix()
655 u->viu_child = child; in vmd_alloc_msix()
656 u->viu_vector = ibest; in vmd_alloc_msix()
657 LIST_INSERT_HEAD(&sc->vmd_users, u, viu_link); in vmd_alloc_msix()
658 sc->vmd_irq[ibest].vi_nusers++; in vmd_alloc_msix()
660 *irq = sc->vmd_irq[ibest].vi_irq; in vmd_alloc_msix()
670 if (sc->vmd_msix_count == 0) { in vmd_release_msix()
675 LIST_FOREACH(u, &sc->vmd_users, viu_link) { in vmd_release_msix()
676 if (u->viu_child == child && in vmd_release_msix()
677 sc->vmd_irq[u->viu_vector].vi_irq == irq) { in vmd_release_msix()
678 sc->vmd_irq[u->viu_vector].vi_nusers--; in vmd_release_msix()
693 if (sc->vmd_msix_count == 0) { in vmd_map_msi()
698 for (i = sc->vmd_fist_vector; i < sc->vmd_msix_count; i++) { in vmd_map_msi()
699 if (sc->vmd_irq[i].vi_irq == irq) in vmd_map_msi()
702 if (i >= sc->vmd_msix_count) in vmd_map_msi()
751 vmd_devs, nitems(vmd_devs) - 1);