Lines Matching +full:sc +full:- +full:resource

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
147 "Clear firmware-assigned resources for PCI-PCI bridge I/O windows.");
150 * Get the corresponding window if this resource from a child device was
151 * sub-allocated from one of our window resource managers.
154 pcib_get_resource_window(struct pcib_softc *sc, struct resource *r) in pcib_get_resource_window() argument
158 if (rman_is_region_manager(r, &sc->io.rman)) in pcib_get_resource_window()
159 return (&sc->io); in pcib_get_resource_window()
164 rman_is_region_manager(r, &sc->pmem.rman)) in pcib_get_resource_window()
165 return (&sc->pmem); in pcib_get_resource_window()
166 if (rman_is_region_manager(r, &sc->mem.rman)) in pcib_get_resource_window()
167 return (&sc->mem); in pcib_get_resource_window()
174 * Is a resource from a child device sub-allocated from one of our
175 * resource managers?
178 pcib_is_resource_managed(struct pcib_softc *sc, struct resource *r) in pcib_is_resource_managed() argument
182 return (rman_is_region_manager(r, &sc->bus.rman)); in pcib_is_resource_managed()
183 return (pcib_get_resource_window(sc, r) != NULL); in pcib_is_resource_managed()
190 return (pw->valid && pw->base < pw->limit); in pcib_is_window_open()
195 * handle for the resource, we could pass RF_ACTIVE up to the PCI bus
196 * when allocating the resource windows and rely on the PCI bus driver
200 pcib_activate_window(struct pcib_softc *sc, int type) in pcib_activate_window() argument
203 PCI_ENABLE_IO(device_get_parent(sc->dev), sc->dev, type); in pcib_activate_window()
207 pcib_write_windows(struct pcib_softc *sc, int mask) in pcib_write_windows() argument
212 dev = sc->dev; in pcib_write_windows()
213 if (sc->io.valid && mask & WIN_IO) { in pcib_write_windows()
217 sc->io.base >> 16, 2); in pcib_write_windows()
219 sc->io.limit >> 16, 2); in pcib_write_windows()
221 pci_write_config(dev, PCIR_IOBASEL_1, sc->io.base >> 8, 1); in pcib_write_windows()
222 pci_write_config(dev, PCIR_IOLIMITL_1, sc->io.limit >> 8, 1); in pcib_write_windows()
226 pci_write_config(dev, PCIR_MEMBASE_1, sc->mem.base >> 16, 2); in pcib_write_windows()
227 pci_write_config(dev, PCIR_MEMLIMIT_1, sc->mem.limit >> 16, 2); in pcib_write_windows()
230 if (sc->pmem.valid && mask & WIN_PMEM) { in pcib_write_windows()
234 sc->pmem.base >> 32, 4); in pcib_write_windows()
236 sc->pmem.limit >> 32, 4); in pcib_write_windows()
238 pci_write_config(dev, PCIR_PMBASEL_1, sc->pmem.base >> 16, 2); in pcib_write_windows()
239 pci_write_config(dev, PCIR_PMLIMITL_1, sc->pmem.limit >> 16, 2); in pcib_write_windows()
248 pcib_is_isa_range(struct pcib_softc *sc, rman_res_t start, rman_res_t end, in pcib_is_isa_range() argument
253 if (!(sc->bridgectl & PCIB_BCR_ISA_ENABLE)) in pcib_is_isa_range()
257 if (start + count - 1 != end) in pcib_is_isa_range()
264 /* Check for overlap with 0x000 - 0x0ff as a special case. */ in pcib_is_isa_range()
282 device_printf(sc->dev, in pcib_is_isa_range()
283 "I/O range %#jx-%#jx overlaps with an ISA alias\n", start, in pcib_is_isa_range()
289 pcib_add_window_resources(struct pcib_window *w, struct resource **res, in pcib_add_window_resources()
292 struct resource **newarray; in pcib_add_window_resources()
295 newarray = malloc(sizeof(struct resource *) * (w->count + count), in pcib_add_window_resources()
297 if (w->res != NULL) in pcib_add_window_resources()
298 bcopy(w->res, newarray, sizeof(struct resource *) * w->count); in pcib_add_window_resources()
299 bcopy(res, newarray + w->count, sizeof(struct resource *) * count); in pcib_add_window_resources()
300 free(w->res, M_DEVBUF); in pcib_add_window_resources()
301 w->res = newarray; in pcib_add_window_resources()
302 w->count += count; in pcib_add_window_resources()
305 error = rman_manage_region(&w->rman, rman_get_start(res[i]), in pcib_add_window_resources()
308 panic("Failed to add resource to rman"); in pcib_add_window_resources()
322 * of the next non-alias range. As a special case, addresses in pcib_walk_nonisa_ranges()
323 * in the range 0x000 - 0x0ff should also be skipped since in pcib_walk_nonisa_ranges()
355 struct resource **res;
356 struct pcib_softc *sc; member
368 if (as->error != 0) in alloc_ranges()
371 w = &as->sc->io; in alloc_ranges()
372 rid = w->reg; in alloc_ranges()
374 device_printf(as->sc->dev, in alloc_ranges()
375 "allocating non-ISA range %#jx-%#jx\n", start, end); in alloc_ranges()
376 as->res[as->count] = bus_alloc_resource(as->sc->dev, SYS_RES_IOPORT, in alloc_ranges()
377 &rid, start, end, end - start + 1, RF_ACTIVE | RF_UNMAPPED); in alloc_ranges()
378 if (as->res[as->count] == NULL) in alloc_ranges()
379 as->error = ENXIO; in alloc_ranges()
381 as->count++; in alloc_ranges()
385 pcib_alloc_nonisa_ranges(struct pcib_softc *sc, rman_res_t start, rman_res_t end) in pcib_alloc_nonisa_ranges() argument
395 as.res = malloc(sizeof(struct resource *) * new_count, M_DEVBUF, in pcib_alloc_nonisa_ranges()
397 as.sc = sc; in pcib_alloc_nonisa_ranges()
403 bus_release_resource(sc->dev, SYS_RES_IOPORT, in pcib_alloc_nonisa_ranges()
404 sc->io.reg, as.res[i]); in pcib_alloc_nonisa_ranges()
411 pcib_add_window_resources(&sc->io, as.res, as.count); in pcib_alloc_nonisa_ranges()
417 pcib_alloc_window(struct pcib_softc *sc, struct pcib_window *w, int type, in pcib_alloc_window() argument
420 struct resource *res; in pcib_alloc_window()
426 w->rman.rm_start = 0; in pcib_alloc_window()
427 w->rman.rm_end = max_address; in pcib_alloc_window()
428 w->rman.rm_type = RMAN_ARRAY; in pcib_alloc_window()
430 device_get_nameunit(sc->dev), w->name); in pcib_alloc_window()
431 w->rman.rm_descr = strdup(buf, M_DEVBUF); in pcib_alloc_window()
432 error = rman_init(&w->rman); in pcib_alloc_window()
435 device_get_nameunit(sc->dev), w->name); in pcib_alloc_window()
440 if (w->base > max_address || w->limit > max_address) { in pcib_alloc_window()
441 device_printf(sc->dev, in pcib_alloc_window()
442 "initial %s window has too many bits, ignoring\n", w->name); in pcib_alloc_window()
445 if (type == SYS_RES_IOPORT && sc->bridgectl & PCIB_BCR_ISA_ENABLE) in pcib_alloc_window()
446 (void)pcib_alloc_nonisa_ranges(sc, w->base, w->limit); in pcib_alloc_window()
448 rid = w->reg; in pcib_alloc_window()
449 res = bus_alloc_resource(sc->dev, type, &rid, w->base, w->limit, in pcib_alloc_window()
450 w->limit - w->base + 1, flags | RF_ACTIVE | RF_UNMAPPED); in pcib_alloc_window()
454 if (w->res == NULL) { in pcib_alloc_window()
455 device_printf(sc->dev, in pcib_alloc_window()
456 "failed to allocate initial %s window: %#jx-%#jx\n", in pcib_alloc_window()
457 w->name, (uintmax_t)w->base, (uintmax_t)w->limit); in pcib_alloc_window()
458 w->base = max_address; in pcib_alloc_window()
459 w->limit = 0; in pcib_alloc_window()
460 pcib_write_windows(sc, w->mask); in pcib_alloc_window()
463 pcib_activate_window(sc, type); in pcib_alloc_window()
470 pcib_probe_windows(struct pcib_softc *sc) in pcib_probe_windows() argument
476 dev = sc->dev; in pcib_probe_windows()
486 * If 'val' is zero, then only 16-bits of I/O space in pcib_probe_windows()
491 sc->io.valid = 1; in pcib_probe_windows()
495 sc->io.valid = 1; in pcib_probe_windows()
498 if (sc->io.valid) { in pcib_probe_windows()
499 sc->io.reg = PCIR_IOBASEL_1; in pcib_probe_windows()
500 sc->io.step = 12; in pcib_probe_windows()
501 sc->io.mask = WIN_IO; in pcib_probe_windows()
502 sc->io.name = "I/O port"; in pcib_probe_windows()
504 sc->io.base = PCI_PPBIOBASE( in pcib_probe_windows()
506 sc->io.limit = PCI_PPBIOLIMIT( in pcib_probe_windows()
511 sc->io.base = PCI_PPBIOBASE(0, val); in pcib_probe_windows()
512 sc->io.limit = PCI_PPBIOLIMIT(0, in pcib_probe_windows()
516 pcib_alloc_window(sc, &sc->io, SYS_RES_IOPORT, 0, max); in pcib_probe_windows()
520 sc->mem.valid = 1; in pcib_probe_windows()
521 sc->mem.reg = PCIR_MEMBASE_1; in pcib_probe_windows()
522 sc->mem.step = 20; in pcib_probe_windows()
523 sc->mem.mask = WIN_MEM; in pcib_probe_windows()
524 sc->mem.name = "memory"; in pcib_probe_windows()
525 sc->mem.base = PCI_PPBMEMBASE(0, in pcib_probe_windows()
527 sc->mem.limit = PCI_PPBMEMLIMIT(0, in pcib_probe_windows()
529 pcib_alloc_window(sc, &sc->mem, SYS_RES_MEMORY, 0, 0xffffffff); in pcib_probe_windows()
535 * If 'val' is zero, then only 32-bits of memory space in pcib_probe_windows()
540 sc->pmem.valid = 1; in pcib_probe_windows()
544 sc->pmem.valid = 1; in pcib_probe_windows()
547 if (sc->pmem.valid) { in pcib_probe_windows()
548 sc->pmem.reg = PCIR_PMBASEL_1; in pcib_probe_windows()
549 sc->pmem.step = 20; in pcib_probe_windows()
550 sc->pmem.mask = WIN_PMEM; in pcib_probe_windows()
551 sc->pmem.name = "prefetch"; in pcib_probe_windows()
553 sc->pmem.base = PCI_PPBMEMBASE( in pcib_probe_windows()
555 sc->pmem.limit = PCI_PPBMEMLIMIT( in pcib_probe_windows()
560 sc->pmem.base = PCI_PPBMEMBASE(0, val); in pcib_probe_windows()
561 sc->pmem.limit = PCI_PPBMEMLIMIT(0, in pcib_probe_windows()
565 pcib_alloc_window(sc, &sc->pmem, SYS_RES_MEMORY, in pcib_probe_windows()
571 pcib_release_window(struct pcib_softc *sc, struct pcib_window *w, int type) in pcib_release_window() argument
576 if (!w->valid) in pcib_release_window()
579 dev = sc->dev; in pcib_release_window()
580 error = rman_fini(&w->rman); in pcib_release_window()
582 device_printf(dev, "failed to release %s rman\n", w->name); in pcib_release_window()
585 free(__DECONST(char *, w->rman.rm_descr), M_DEVBUF); in pcib_release_window()
587 for (i = 0; i < w->count; i++) { in pcib_release_window()
588 error = bus_free_resource(dev, type, w->res[i]); in pcib_release_window()
591 "failed to release %s resource: %d\n", w->name, in pcib_release_window()
594 free(w->res, M_DEVBUF); in pcib_release_window()
598 pcib_free_windows(struct pcib_softc *sc) in pcib_free_windows() argument
601 pcib_release_window(sc, &sc->pmem, SYS_RES_MEMORY); in pcib_free_windows()
602 pcib_release_window(sc, &sc->mem, SYS_RES_MEMORY); in pcib_free_windows()
603 pcib_release_window(sc, &sc->io, SYS_RES_IOPORT); in pcib_free_windows()
608 * initialize the resource manager for the secondary bus range. Note
621 bus->sub_reg = PCIR_SUBBUS_1; in pcib_setup_secbus()
625 bus->sub_reg = PCIR_SUBBUS_2; in pcib_setup_secbus()
630 bus->sec = pci_read_config(dev, sec_reg, 1); in pcib_setup_secbus()
631 bus->sub = pci_read_config(dev, bus->sub_reg, 1); in pcib_setup_secbus()
632 bus->dev = dev; in pcib_setup_secbus()
633 bus->rman.rm_start = 0; in pcib_setup_secbus()
634 bus->rman.rm_end = PCI_BUSMAX; in pcib_setup_secbus()
635 bus->rman.rm_type = RMAN_ARRAY; in pcib_setup_secbus()
637 bus->rman.rm_descr = strdup(buf, M_DEVBUF); in pcib_setup_secbus()
638 error = rman_init(&bus->rman); in pcib_setup_secbus()
648 bus->res = bus_alloc_resource_anywhere(dev, PCI_RES_BUS, &rid, in pcib_setup_secbus()
650 if (bus->res == NULL) { in pcib_setup_secbus()
655 bus->res = bus_alloc_resource_anywhere(dev, PCI_RES_BUS, &rid, in pcib_setup_secbus()
657 } else if (rman_get_size(bus->res) < min_count) in pcib_setup_secbus()
662 (void)bus_adjust_resource(dev, PCI_RES_BUS, bus->res, in pcib_setup_secbus()
663 rman_get_start(bus->res), rman_get_start(bus->res) + in pcib_setup_secbus()
664 min_count - 1); in pcib_setup_secbus()
667 * Add the initial resource to the rman. in pcib_setup_secbus()
669 if (bus->res != NULL) { in pcib_setup_secbus()
670 error = rman_manage_region(&bus->rman, rman_get_start(bus->res), in pcib_setup_secbus()
671 rman_get_end(bus->res)); in pcib_setup_secbus()
673 panic("Failed to add resource to rman"); in pcib_setup_secbus()
674 bus->sec = rman_get_start(bus->res); in pcib_setup_secbus()
675 bus->sub = rman_get_end(bus->res); in pcib_setup_secbus()
684 error = rman_fini(&bus->rman); in pcib_free_secbus()
689 free(__DECONST(char *, bus->rman.rm_descr), M_DEVBUF); in pcib_free_secbus()
691 error = bus_free_resource(dev, PCI_RES_BUS, bus->res); in pcib_free_secbus()
694 "failed to release bus numbers resource: %d\n", error); in pcib_free_secbus()
697 static struct resource *
701 struct resource *res; in pcib_suballoc_bus()
703 res = rman_reserve_resource(&bus->rman, start, end, count, flags, in pcib_suballoc_bus()
709 device_printf(bus->dev, in pcib_suballoc_bus()
710 "allocated bus range (%ju-%ju) for rid %d of %s\n", in pcib_suballoc_bus()
729 old_end = rman_get_end(bus->res); in pcib_grow_subbus()
731 error = bus_adjust_resource(bus->dev, PCI_RES_BUS, bus->res, in pcib_grow_subbus()
732 rman_get_start(bus->res), new_end); in pcib_grow_subbus()
736 device_printf(bus->dev, "grew bus range to %ju-%ju\n", in pcib_grow_subbus()
737 rman_get_start(bus->res), rman_get_end(bus->res)); in pcib_grow_subbus()
738 error = rman_manage_region(&bus->rman, old_end + 1, in pcib_grow_subbus()
739 rman_get_end(bus->res)); in pcib_grow_subbus()
741 panic("Failed to add resource to rman"); in pcib_grow_subbus()
742 bus->sub = rman_get_end(bus->res); in pcib_grow_subbus()
743 pci_write_config(bus->dev, bus->sub_reg, bus->sub, 1); in pcib_grow_subbus()
747 struct resource *
751 struct resource *res; in pcib_alloc_subbus()
767 if (rman_last_free_region(&bus->rman, &start_free, &end_free) != 0 || in pcib_alloc_subbus()
768 end_free != bus->sub) in pcib_alloc_subbus()
769 start_free = bus->sub + 1; in pcib_alloc_subbus()
772 new_end = start_free + count - 1; in pcib_alloc_subbus()
781 /* Finally, attempt to grow the existing resource. */ in pcib_alloc_subbus()
783 device_printf(bus->dev, in pcib_alloc_subbus()
785 printf("\tback candidate range: %ju-%ju\n", start_free, in pcib_alloc_subbus()
796 * PCI-express HotPlug support.
801 "Enable support for native PCI-express HotPlug.");
806 "Attention Button delay for PCI-express Eject.");
809 pcib_probe_hotplug(struct pcib_softc *sc) in pcib_probe_hotplug() argument
818 dev = sc->dev; in pcib_probe_hotplug()
825 sc->pcie_slot_cap = pcie_read_config(dev, PCIER_SLOT_CAP, 4); in pcib_probe_hotplug()
827 if ((sc->pcie_slot_cap & PCIEM_SLOT_CAP_HPC) == 0) in pcib_probe_hotplug()
842 if ((sc->pcie_slot_cap & PCIEM_SLOT_CAP_MRLSP) != 0) { in pcib_probe_hotplug()
861 sc->flags |= PCIB_HOTPLUG; in pcib_probe_hotplug()
873 pcib_pcie_hotplug_command(struct pcib_softc *sc, uint16_t val, uint16_t mask) in pcib_pcie_hotplug_command() argument
878 dev = sc->dev; in pcib_pcie_hotplug_command()
880 if (sc->flags & PCIB_HOTPLUG_CMD_PENDING) in pcib_pcie_hotplug_command()
888 device_printf(dev, "HotPlug command: %04x -> %04x\n", ctl, new); in pcib_pcie_hotplug_command()
890 if (!(sc->pcie_slot_cap & PCIEM_SLOT_CAP_NCCS) && in pcib_pcie_hotplug_command()
892 sc->flags |= PCIB_HOTPLUG_CMD_PENDING; in pcib_pcie_hotplug_command()
895 &sc->pcie_cc_task, hz); in pcib_pcie_hotplug_command()
900 pcib_pcie_hotplug_command_completed(struct pcib_softc *sc) in pcib_pcie_hotplug_command_completed() argument
904 dev = sc->dev; in pcib_pcie_hotplug_command_completed()
908 if (!(sc->flags & PCIB_HOTPLUG_CMD_PENDING)) in pcib_pcie_hotplug_command_completed()
910 taskqueue_cancel_timeout(taskqueue_bus, &sc->pcie_cc_task, NULL); in pcib_pcie_hotplug_command_completed()
911 sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; in pcib_pcie_hotplug_command_completed()
912 wakeup(sc); in pcib_pcie_hotplug_command_completed()
921 pcib_hotplug_inserted(struct pcib_softc *sc) in pcib_hotplug_inserted() argument
925 if (sc->flags & PCIB_DETACHING) in pcib_hotplug_inserted()
929 if ((sc->pcie_slot_sta & PCIEM_SLOT_STA_PDS) == 0) in pcib_hotplug_inserted()
933 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_PCP && in pcib_hotplug_inserted()
934 sc->pcie_slot_sta & PCIEM_SLOT_STA_PFD) in pcib_hotplug_inserted()
938 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_MRLSP && in pcib_hotplug_inserted()
939 (sc->pcie_slot_sta & PCIEM_SLOT_STA_MRLSS) != 0) in pcib_hotplug_inserted()
946 * Returns -1 if the card is fully inserted, powered, and ready for
950 pcib_hotplug_present(struct pcib_softc *sc) in pcib_hotplug_present() argument
954 if (!pcib_hotplug_inserted(sc)) in pcib_hotplug_present()
958 if (!(sc->pcie_link_sta & PCIEM_LINK_STA_DL_ACTIVE)) in pcib_hotplug_present()
961 return (-1); in pcib_hotplug_present()
967 "Enable support for PCI-express Electromechanical Interlock.");
970 pcib_pcie_hotplug_update(struct pcib_softc *sc, uint16_t val, uint16_t mask, in pcib_pcie_hotplug_update() argument
976 if ((sc->pcie_slot_sta & (PCIEM_SLOT_STA_PDC | PCIEM_SLOT_STA_PDS)) == in pcib_pcie_hotplug_update()
978 sc->flags &= ~PCIB_DETACHING; in pcib_pcie_hotplug_update()
980 card_inserted = pcib_hotplug_inserted(sc); in pcib_pcie_hotplug_update()
983 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_PIP) { in pcib_pcie_hotplug_update()
987 else if (sc->flags & PCIB_DETACH_PENDING) in pcib_pcie_hotplug_update()
994 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_PCP) { in pcib_pcie_hotplug_update()
1008 if ((sc->pcie_slot_cap & PCIEM_SLOT_CAP_EIP) && in pcib_pcie_hotplug_update()
1011 ei_engaged = (sc->pcie_slot_sta & PCIEM_SLOT_STA_EIS) != 0; in pcib_pcie_hotplug_update()
1023 !(sc->pcie_link_sta & PCIEM_LINK_STA_DL_ACTIVE) && in pcib_pcie_hotplug_update()
1024 sc->pcie_slot_sta & in pcib_pcie_hotplug_update()
1027 device_printf(sc->dev, in pcib_pcie_hotplug_update()
1031 &sc->pcie_dll_task, hz); in pcib_pcie_hotplug_update()
1032 } else if (sc->pcie_link_sta & PCIEM_LINK_STA_DL_ACTIVE) in pcib_pcie_hotplug_update()
1033 taskqueue_cancel_timeout(taskqueue_bus, &sc->pcie_dll_task, in pcib_pcie_hotplug_update()
1036 pcib_pcie_hotplug_command(sc, val, mask); in pcib_pcie_hotplug_update()
1044 (pcib_hotplug_present(sc) != 0) != (sc->child != NULL)) in pcib_pcie_hotplug_update()
1045 taskqueue_enqueue(taskqueue_bus, &sc->pcie_hp_task); in pcib_pcie_hotplug_update()
1051 struct pcib_softc *sc; in pcib_pcie_intr_hotplug() local
1055 sc = arg; in pcib_pcie_intr_hotplug()
1056 dev = sc->dev; in pcib_pcie_intr_hotplug()
1057 PCIB_HP_LOCK(sc); in pcib_pcie_intr_hotplug()
1058 old_slot_sta = sc->pcie_slot_sta; in pcib_pcie_intr_hotplug()
1059 sc->pcie_slot_sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); in pcib_pcie_intr_hotplug()
1062 pcie_write_config(dev, PCIER_SLOT_STA, sc->pcie_slot_sta, 2); in pcib_pcie_intr_hotplug()
1066 sc->pcie_slot_sta); in pcib_pcie_intr_hotplug()
1068 if (sc->pcie_slot_sta & PCIEM_SLOT_STA_ABP) { in pcib_pcie_intr_hotplug()
1069 if (sc->flags & PCIB_DETACH_PENDING) { in pcib_pcie_intr_hotplug()
1072 sc->flags &= ~PCIB_DETACH_PENDING; in pcib_pcie_intr_hotplug()
1074 &sc->pcie_ab_task, NULL); in pcib_pcie_intr_hotplug()
1081 sc->flags |= PCIB_DETACH_PENDING; in pcib_pcie_intr_hotplug()
1083 &sc->pcie_ab_task, pcie_hp_detach_timeout, in pcib_pcie_intr_hotplug()
1086 sc->flags |= PCIB_DETACHING; in pcib_pcie_intr_hotplug()
1090 if (sc->pcie_slot_sta & PCIEM_SLOT_STA_PFD) in pcib_pcie_intr_hotplug()
1092 if (sc->pcie_slot_sta & PCIEM_SLOT_STA_MRLSC) in pcib_pcie_intr_hotplug()
1094 sc->pcie_slot_sta & PCIEM_SLOT_STA_MRLSS ? "open" : in pcib_pcie_intr_hotplug()
1096 if (bootverbose && sc->pcie_slot_sta & PCIEM_SLOT_STA_PDC) in pcib_pcie_intr_hotplug()
1098 sc->pcie_slot_sta & PCIEM_SLOT_STA_PDS ? "card present" : in pcib_pcie_intr_hotplug()
1100 if (sc->pcie_slot_sta & PCIEM_SLOT_STA_CC) in pcib_pcie_intr_hotplug()
1101 pcib_pcie_hotplug_command_completed(sc); in pcib_pcie_intr_hotplug()
1102 if (sc->pcie_slot_sta & PCIEM_SLOT_STA_DLLSC) { in pcib_pcie_intr_hotplug()
1103 sc->pcie_link_sta = pcie_read_config(dev, PCIER_LINK_STA, 2); in pcib_pcie_intr_hotplug()
1107 sc->pcie_link_sta & PCIEM_LINK_STA_DL_ACTIVE ? in pcib_pcie_intr_hotplug()
1111 pcib_pcie_hotplug_update(sc, 0, 0, true); in pcib_pcie_intr_hotplug()
1112 PCIB_HP_UNLOCK(sc); in pcib_pcie_intr_hotplug()
1118 struct pcib_softc *sc; in pcib_pcie_hotplug_task() local
1121 sc = context; in pcib_pcie_hotplug_task()
1122 PCIB_HP_LOCK(sc); in pcib_pcie_hotplug_task()
1123 dev = sc->dev; in pcib_pcie_hotplug_task()
1124 if (pcib_hotplug_present(sc) != 0) { in pcib_pcie_hotplug_task()
1125 if (sc->child == NULL) { in pcib_pcie_hotplug_task()
1126 sc->child = device_add_child(dev, "pci", DEVICE_UNIT_ANY); in pcib_pcie_hotplug_task()
1130 if (sc->child != NULL) { in pcib_pcie_hotplug_task()
1131 if (device_delete_child(dev, sc->child) == 0) in pcib_pcie_hotplug_task()
1132 sc->child = NULL; in pcib_pcie_hotplug_task()
1135 PCIB_HP_UNLOCK(sc); in pcib_pcie_hotplug_task()
1141 struct pcib_softc *sc = arg; in pcib_pcie_ab_timeout() local
1143 PCIB_HP_LOCK(sc); in pcib_pcie_ab_timeout()
1144 if (sc->flags & PCIB_DETACH_PENDING) { in pcib_pcie_ab_timeout()
1145 sc->flags |= PCIB_DETACHING; in pcib_pcie_ab_timeout()
1146 sc->flags &= ~PCIB_DETACH_PENDING; in pcib_pcie_ab_timeout()
1147 pcib_pcie_hotplug_update(sc, 0, 0, true); in pcib_pcie_ab_timeout()
1149 PCIB_HP_UNLOCK(sc); in pcib_pcie_ab_timeout()
1155 struct pcib_softc *sc = arg; in pcib_pcie_cc_timeout() local
1156 device_t dev = sc->dev; in pcib_pcie_cc_timeout()
1159 PCIB_HP_LOCK(sc); in pcib_pcie_cc_timeout()
1163 sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; in pcib_pcie_cc_timeout()
1167 pcib_pcie_intr_hotplug(sc); in pcib_pcie_cc_timeout()
1169 PCIB_HP_UNLOCK(sc); in pcib_pcie_cc_timeout()
1175 struct pcib_softc *sc = arg; in pcib_pcie_dll_timeout() local
1176 device_t dev = sc->dev; in pcib_pcie_dll_timeout()
1179 PCIB_HP_LOCK(sc); in pcib_pcie_dll_timeout()
1184 sc->flags |= PCIB_DETACHING; in pcib_pcie_dll_timeout()
1185 pcib_pcie_hotplug_update(sc, 0, 0, true); in pcib_pcie_dll_timeout()
1186 } else if (sta != sc->pcie_link_sta) { in pcib_pcie_dll_timeout()
1189 pcib_pcie_intr_hotplug(sc); in pcib_pcie_dll_timeout()
1191 PCIB_HP_UNLOCK(sc); in pcib_pcie_dll_timeout()
1195 pcib_alloc_pcie_irq(struct pcib_softc *sc) in pcib_alloc_pcie_irq() argument
1200 rid = -1; in pcib_alloc_pcie_irq()
1201 dev = sc->dev; in pcib_alloc_pcie_irq()
1204 * For simplicity, only use MSI-X if there is a single message. in pcib_alloc_pcie_irq()
1211 sc->pcie_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in pcib_alloc_pcie_irq()
1213 if (sc->pcie_mem == NULL) { in pcib_alloc_pcie_irq()
1215 "Failed to allocate BAR for MSI-X table\n"); in pcib_alloc_pcie_irq()
1233 sc->pcie_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in pcib_alloc_pcie_irq()
1235 if (sc->pcie_irq == NULL) { in pcib_alloc_pcie_irq()
1237 "Failed to allocate interrupt for PCI-e events\n"); in pcib_alloc_pcie_irq()
1243 error = bus_setup_intr(dev, sc->pcie_irq, INTR_TYPE_MISC|INTR_MPSAFE, in pcib_alloc_pcie_irq()
1244 NULL, pcib_pcie_intr_hotplug, sc, &sc->pcie_ihand); in pcib_alloc_pcie_irq()
1246 device_printf(dev, "Failed to setup PCI-e interrupt handler\n"); in pcib_alloc_pcie_irq()
1247 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->pcie_irq); in pcib_alloc_pcie_irq()
1256 pcib_release_pcie_irq(struct pcib_softc *sc) in pcib_release_pcie_irq() argument
1261 dev = sc->dev; in pcib_release_pcie_irq()
1262 error = bus_teardown_intr(dev, sc->pcie_irq, sc->pcie_ihand); in pcib_release_pcie_irq()
1265 error = bus_free_resource(dev, SYS_RES_IRQ, sc->pcie_irq); in pcib_release_pcie_irq()
1271 if (sc->pcie_mem != NULL) in pcib_release_pcie_irq()
1272 error = bus_free_resource(dev, SYS_RES_MEMORY, sc->pcie_mem); in pcib_release_pcie_irq()
1277 pcib_setup_hotplug(struct pcib_softc *sc) in pcib_setup_hotplug() argument
1282 dev = sc->dev; in pcib_setup_hotplug()
1283 TASK_INIT(&sc->pcie_hp_task, 0, pcib_pcie_hotplug_task, sc); in pcib_setup_hotplug()
1284 TIMEOUT_TASK_INIT(taskqueue_bus, &sc->pcie_ab_task, 0, in pcib_setup_hotplug()
1285 pcib_pcie_ab_timeout, sc); in pcib_setup_hotplug()
1286 TIMEOUT_TASK_INIT(taskqueue_bus, &sc->pcie_cc_task, 0, in pcib_setup_hotplug()
1287 pcib_pcie_cc_timeout, sc); in pcib_setup_hotplug()
1288 TIMEOUT_TASK_INIT(taskqueue_bus, &sc->pcie_dll_task, 0, in pcib_setup_hotplug()
1289 pcib_pcie_dll_timeout, sc); in pcib_setup_hotplug()
1290 sc->pcie_hp_lock = bus_topo_mtx(); in pcib_setup_hotplug()
1293 if (pcib_alloc_pcie_irq(sc) != 0) in pcib_setup_hotplug()
1296 sc->pcie_link_sta = pcie_read_config(dev, PCIER_LINK_STA, 2); in pcib_setup_hotplug()
1297 sc->pcie_slot_sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); in pcib_setup_hotplug()
1300 pcie_write_config(dev, PCIER_SLOT_STA, sc->pcie_slot_sta, 2); in pcib_setup_hotplug()
1301 sc->pcie_slot_sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); in pcib_setup_hotplug()
1308 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_APB) in pcib_setup_hotplug()
1310 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_PCP) in pcib_setup_hotplug()
1312 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_MRLSP) in pcib_setup_hotplug()
1314 if (!(sc->pcie_slot_cap & PCIEM_SLOT_CAP_NCCS)) in pcib_setup_hotplug()
1318 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_AIP) { in pcib_setup_hotplug()
1323 pcib_pcie_hotplug_update(sc, val, mask, false); in pcib_setup_hotplug()
1327 pcib_detach_hotplug(struct pcib_softc *sc) in pcib_detach_hotplug() argument
1333 if (sc->flags & PCIB_DETACH_PENDING) { in pcib_detach_hotplug()
1334 sc->flags &= ~PCIB_DETACH_PENDING; in pcib_detach_hotplug()
1335 taskqueue_cancel_timeout(taskqueue_bus, &sc->pcie_ab_task, in pcib_detach_hotplug()
1338 sc->flags |= PCIB_DETACHING; in pcib_detach_hotplug()
1340 if (sc->flags & PCIB_HOTPLUG_CMD_PENDING) { in pcib_detach_hotplug()
1341 taskqueue_cancel_timeout(taskqueue_bus, &sc->pcie_cc_task, in pcib_detach_hotplug()
1343 tsleep(sc, 0, "hpcmd", hz); in pcib_detach_hotplug()
1344 sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; in pcib_detach_hotplug()
1354 if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_AIP) { in pcib_detach_hotplug()
1359 pcib_pcie_hotplug_update(sc, val, mask, false); in pcib_detach_hotplug()
1361 error = pcib_release_pcie_irq(sc); in pcib_detach_hotplug()
1364 taskqueue_drain(taskqueue_bus, &sc->pcie_hp_task); in pcib_detach_hotplug()
1365 taskqueue_drain_timeout(taskqueue_bus, &sc->pcie_ab_task); in pcib_detach_hotplug()
1366 taskqueue_drain_timeout(taskqueue_bus, &sc->pcie_cc_task); in pcib_detach_hotplug()
1367 taskqueue_drain_timeout(taskqueue_bus, &sc->pcie_dll_task); in pcib_detach_hotplug()
1376 pcib_cfg_restore(struct pcib_softc *sc) in pcib_cfg_restore() argument
1378 pcib_write_windows(sc, WIN_IO | WIN_MEM | WIN_PMEM); in pcib_cfg_restore()
1389 device_set_desc(dev, "PCI-PCI bridge"); in pcib_probe()
1390 return(-10000); in pcib_probe()
1398 struct pcib_softc *sc; in pcib_attach_common() local
1403 sc = device_get_softc(dev); in pcib_attach_common()
1404 sc->dev = dev; in pcib_attach_common()
1409 sc->domain = pci_get_domain(dev); in pcib_attach_common()
1410 sc->bridgectl = pci_read_config(dev, PCIR_BRIDGECTL_1, 2); in pcib_attach_common()
1416 sc->pribus = pci_get_bus(dev); in pcib_attach_common()
1417 pci_write_config(dev, PCIR_PRIBUS_1, sc->pribus, 1); in pcib_attach_common()
1425 CTLFLAG_RD, &sc->domain, 0, "Domain number"); in pcib_attach_common()
1427 CTLFLAG_RD, &sc->pribus, 0, "Primary bus number"); in pcib_attach_common()
1429 CTLFLAG_RD, &sc->bus.sec, 0, "Secondary bus number"); in pcib_attach_common()
1431 CTLFLAG_RD, &sc->bus.sub, 0, "Subordinate bus number"); in pcib_attach_common()
1438 * The i82380FB mobile docking controller is a PCI-PCI bridge, in pcib_attach_common()
1447 sc->flags |= PCIB_SUBTRACTIVE; in pcib_attach_common()
1452 sc->flags |= PCIB_DISABLE_MSI; in pcib_attach_common()
1455 sc->flags |= PCIB_DISABLE_MSIX; in pcib_attach_common()
1458 * Intel 815, 845 and other chipsets say they are PCI-PCI bridges, in pcib_attach_common()
1460 * BA/CA/DB and E) PCI bridges are HUB-PCI bridges, in Intelese. in pcib_attach_common()
1467 sc->flags |= PCIB_SUBTRACTIVE; in pcib_attach_common()
1470 pcib_probe_hotplug(sc); in pcib_attach_common()
1472 pcib_setup_secbus(dev, &sc->bus, 1); in pcib_attach_common()
1473 pcib_probe_windows(sc); in pcib_attach_common()
1475 if (sc->flags & PCIB_HOTPLUG) in pcib_attach_common()
1476 pcib_setup_hotplug(sc); in pcib_attach_common()
1479 device_printf(dev, " domain %d\n", sc->domain); in pcib_attach_common()
1480 device_printf(dev, " secondary bus %d\n", sc->bus.sec); in pcib_attach_common()
1481 device_printf(dev, " subordinate bus %d\n", sc->bus.sub); in pcib_attach_common()
1482 if (pcib_is_window_open(&sc->io)) in pcib_attach_common()
1483 device_printf(dev, " I/O decode 0x%jx-0x%jx\n", in pcib_attach_common()
1484 (uintmax_t)sc->io.base, (uintmax_t)sc->io.limit); in pcib_attach_common()
1485 if (pcib_is_window_open(&sc->mem)) in pcib_attach_common()
1486 device_printf(dev, " memory decode 0x%jx-0x%jx\n", in pcib_attach_common()
1487 (uintmax_t)sc->mem.base, (uintmax_t)sc->mem.limit); in pcib_attach_common()
1488 if (pcib_is_window_open(&sc->pmem)) in pcib_attach_common()
1489 device_printf(dev, " prefetched decode 0x%jx-0x%jx\n", in pcib_attach_common()
1490 (uintmax_t)sc->pmem.base, (uintmax_t)sc->pmem.limit); in pcib_attach_common()
1491 if (sc->bridgectl & (PCIB_BCR_ISA_ENABLE | PCIB_BCR_VGA_ENABLE) || in pcib_attach_common()
1492 sc->flags & PCIB_SUBTRACTIVE) { in pcib_attach_common()
1495 if (sc->bridgectl & PCIB_BCR_ISA_ENABLE) { in pcib_attach_common()
1499 if (sc->bridgectl & PCIB_BCR_VGA_ENABLE) { in pcib_attach_common()
1503 if (sc->flags & PCIB_SUBTRACTIVE) in pcib_attach_common()
1519 pcib_present(struct pcib_softc *sc) in pcib_present() argument
1522 if (sc->flags & PCIB_HOTPLUG) in pcib_present()
1523 return (pcib_hotplug_present(sc) != 0); in pcib_present()
1531 struct pcib_softc *sc; in pcib_attach_child() local
1533 sc = device_get_softc(dev); in pcib_attach_child()
1534 if (sc->bus.sec == 0) { in pcib_attach_child()
1540 if (!pcib_present(sc)) { in pcib_attach_child()
1546 sc->child = device_add_child(dev, "pci", DEVICE_UNIT_ANY); in pcib_attach_child()
1562 struct pcib_softc *sc; in pcib_detach() local
1565 sc = device_get_softc(dev); in pcib_detach()
1570 if (sc->flags & PCIB_HOTPLUG) { in pcib_detach()
1571 error = pcib_detach_hotplug(sc); in pcib_detach()
1579 pcib_free_windows(sc); in pcib_detach()
1580 pcib_free_secbus(dev, &sc->bus); in pcib_detach()
1617 struct pcib_softc *sc = device_get_softc(dev); in pcib_child_present() local
1621 if (retval != 0 && sc->flags & PCIB_HOTPLUG) in pcib_child_present()
1622 retval = pcib_hotplug_present(sc); in pcib_child_present()
1632 struct pcib_softc *sc = device_get_softc(dev); in pcib_read_ivar() local
1636 *result = sc->domain; in pcib_read_ivar()
1639 *result = sc->bus.sec; in pcib_read_ivar()
1659 * Attempt to allocate a resource from the existing resources assigned
1662 static struct resource *
1663 pcib_suballoc_resource(struct pcib_softc *sc, struct pcib_window *w, in pcib_suballoc_resource() argument
1667 struct resource *res; in pcib_suballoc_resource()
1672 res = rman_reserve_resource(&w->rman, start, end, count, in pcib_suballoc_resource()
1678 device_printf(sc->dev, in pcib_suballoc_resource()
1679 "allocated %s range (%#jx-%#jx) for rid %x of %s\n", in pcib_suballoc_resource()
1680 w->name, rman_get_start(res), rman_get_end(res), *rid, in pcib_suballoc_resource()
1695 /* Allocate a fresh resource range for an unconfigured window. */
1697 pcib_alloc_new_window(struct pcib_softc *sc, struct pcib_window *w, int type, in pcib_alloc_new_window() argument
1700 struct resource *res; in pcib_alloc_new_window()
1709 * was larger than the non-aliased range size of 0x100 our in pcib_alloc_new_window()
1713 if (type == SYS_RES_IOPORT && sc->bridgectl & PCIB_BCR_ISA_ENABLE && in pcib_alloc_new_window()
1715 for (base = 0xf000; (long)base >= 0; base -= 0x1000) { in pcib_alloc_new_window()
1721 * window that overlaps are the non-alias in pcib_alloc_new_window()
1725 if (start + count > limit - 0x400) in pcib_alloc_new_window()
1730 * 0 is 0x400-0x4ff. in pcib_alloc_new_window()
1732 if (end - count + 1 < 0x400) in pcib_alloc_new_window()
1735 if (end - count + 1 < base) in pcib_alloc_new_window()
1739 if (pcib_alloc_nonisa_ranges(sc, base, limit) == 0) { in pcib_alloc_new_window()
1740 w->base = base; in pcib_alloc_new_window()
1741 w->limit = limit; in pcib_alloc_new_window()
1748 wmask = ((rman_res_t)1 << w->step) - 1; in pcib_alloc_new_window()
1749 if (RF_ALIGNMENT(flags) < w->step) { in pcib_alloc_new_window()
1751 flags |= RF_ALIGNMENT_LOG2(w->step); in pcib_alloc_new_window()
1755 count = roundup2(count, (rman_res_t)1 << w->step); in pcib_alloc_new_window()
1756 rid = w->reg; in pcib_alloc_new_window()
1757 res = bus_alloc_resource(sc->dev, type, &rid, start, end, count, in pcib_alloc_new_window()
1762 pcib_activate_window(sc, type); in pcib_alloc_new_window()
1763 w->base = rman_get_start(res); in pcib_alloc_new_window()
1764 w->limit = rman_get_end(res); in pcib_alloc_new_window()
1770 pcib_expand_window(struct pcib_softc *sc, struct pcib_window *w, int type, in pcib_expand_window() argument
1773 struct resource *res; in pcib_expand_window()
1776 KASSERT(base <= w->base && limit >= w->limit, in pcib_expand_window()
1783 KASSERT(limit == w->limit || base == w->base, in pcib_expand_window()
1788 * window behind an ISA-enabled bridge. Since I/O windows in pcib_expand_window()
1792 * existing resource. in pcib_expand_window()
1794 if (type == SYS_RES_IOPORT && sc->bridgectl & PCIB_BCR_ISA_ENABLE && in pcib_expand_window()
1795 (limit <= 65535 || (base <= 65535 && base != w->base))) { in pcib_expand_window()
1796 KASSERT(limit == w->limit || limit <= 65535, in pcib_expand_window()
1799 if (base != w->base) in pcib_expand_window()
1800 error = pcib_alloc_nonisa_ranges(sc, base, w->base - 1); in pcib_expand_window()
1802 error = pcib_alloc_nonisa_ranges(sc, w->limit + 1, in pcib_expand_window()
1805 w->base = base; in pcib_expand_window()
1806 w->limit = limit; in pcib_expand_window()
1812 * Find the existing resource to adjust. Usually there is only one, in pcib_expand_window()
1813 * but for an ISA-enabled bridge we might be growing the I/O window in pcib_expand_window()
1814 * above 64k and need to find the existing resource that maps all in pcib_expand_window()
1817 for (i = 0; i < w->count; i++) { in pcib_expand_window()
1818 if (rman_get_end(w->res[i]) == w->limit) in pcib_expand_window()
1821 KASSERT(i != w->count, ("did not find existing resource")); in pcib_expand_window()
1822 res = w->res[i]; in pcib_expand_window()
1825 * Usually the resource we found should match the window's in pcib_expand_window()
1826 * existing range. The one exception is the ISA-enabled case in pcib_expand_window()
1827 * mentioned above in which case the resource should start at in pcib_expand_window()
1830 if (type == SYS_RES_IOPORT && sc->bridgectl & PCIB_BCR_ISA_ENABLE && in pcib_expand_window()
1831 w->base <= 65535) { in pcib_expand_window()
1833 ("existing resource mismatch")); in pcib_expand_window()
1836 KASSERT(w->base == rman_get_start(res), in pcib_expand_window()
1837 ("existing resource mismatch")); in pcib_expand_window()
1841 error = bus_adjust_resource(sc->dev, type, res, force_64k_base ? in pcib_expand_window()
1846 /* Add the newly allocated region to the resource manager. */ in pcib_expand_window()
1847 if (w->base != base) { in pcib_expand_window()
1848 error = rman_manage_region(&w->rman, base, w->base - 1); in pcib_expand_window()
1849 w->base = base; in pcib_expand_window()
1851 error = rman_manage_region(&w->rman, w->limit + 1, limit); in pcib_expand_window()
1852 w->limit = limit; in pcib_expand_window()
1856 device_printf(sc->dev, in pcib_expand_window()
1857 "failed to expand %s resource manager\n", w->name); in pcib_expand_window()
1858 (void)bus_adjust_resource(sc->dev, type, res, force_64k_base ? in pcib_expand_window()
1859 rman_get_start(res) : w->base, w->limit); in pcib_expand_window()
1865 * Attempt to grow a window to make room for a given resource request.
1868 pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type, in pcib_grow_window() argument
1875 * Clamp the desired resource range to the maximum address in pcib_grow_window()
1881 if (!w->valid) in pcib_grow_window()
1883 if (sc->bridgectl & PCIB_BCR_ISA_ENABLE && count > 0x100 && in pcib_grow_window()
1886 if (end > w->rman.rm_end) in pcib_grow_window()
1887 end = w->rman.rm_end; in pcib_grow_window()
1888 if (start + count - 1 > end || start + count < start) in pcib_grow_window()
1890 wmask = ((rman_res_t)1 << w->step) - 1; in pcib_grow_window()
1893 * If there is no resource at all, just try to allocate enough in pcib_grow_window()
1894 * aligned space for this resource. in pcib_grow_window()
1896 if (w->res == NULL) { in pcib_grow_window()
1897 error = pcib_alloc_new_window(sc, w, type, start, end, count, in pcib_grow_window()
1901 device_printf(sc->dev, in pcib_grow_window()
1902 "failed to allocate initial %s window (%#jx-%#jx,%#jx)\n", in pcib_grow_window()
1903 w->name, start, end, count); in pcib_grow_window()
1907 device_printf(sc->dev, in pcib_grow_window()
1908 "allocated initial %s window of %#jx-%#jx\n", in pcib_grow_window()
1909 w->name, (uintmax_t)w->base, (uintmax_t)w->limit); in pcib_grow_window()
1926 * non-alias ranges when it is grown in either direction. in pcib_grow_window()
1928 * XXX: Special case: if w->res is completely empty and the in pcib_grow_window()
1929 * request size is larger than w->res, we should find the in pcib_grow_window()
1930 * optimal aligned buffer containing w->res and allocate that. in pcib_grow_window()
1933 device_printf(sc->dev, in pcib_grow_window()
1934 "attempting to grow %s window for (%#jx-%#jx,%#jx)\n", in pcib_grow_window()
1935 w->name, start, end, count); in pcib_grow_window()
1937 if (start < w->base) { in pcib_grow_window()
1938 if (rman_first_free_region(&w->rman, &start_free, &end_free) != in pcib_grow_window()
1939 0 || start_free != w->base) in pcib_grow_window()
1940 end_free = w->base; in pcib_grow_window()
1945 end_free &= ~(align - 1); in pcib_grow_window()
1946 end_free--; in pcib_grow_window()
1947 front = end_free - (count - 1); in pcib_grow_window()
1950 * The resource would now be allocated at (front, in pcib_grow_window()
1958 printf("\tfront candidate range: %#jx-%#jx\n", in pcib_grow_window()
1961 front = w->base - front; in pcib_grow_window()
1966 if (end > w->limit) { in pcib_grow_window()
1967 if (rman_last_free_region(&w->rman, &start_free, &end_free) != in pcib_grow_window()
1968 0 || end_free != w->limit) in pcib_grow_window()
1969 start_free = w->limit + 1; in pcib_grow_window()
1975 back = start_free + count - 1; in pcib_grow_window()
1978 * The resource would now be allocated at (start_free, in pcib_grow_window()
1986 printf("\tback candidate range: %#jx-%#jx\n", in pcib_grow_window()
1989 back -= w->limit; in pcib_grow_window()
2002 error = pcib_expand_window(sc, w, type, w->base - front, in pcib_grow_window()
2003 w->limit); in pcib_grow_window()
2008 error = pcib_expand_window(sc, w, type, w->base, in pcib_grow_window()
2009 w->limit + back); in pcib_grow_window()
2019 device_printf(sc->dev, "grew %s window to %#jx-%#jx\n", in pcib_grow_window()
2020 w->name, (uintmax_t)w->base, (uintmax_t)w->limit); in pcib_grow_window()
2024 KASSERT((w->base & wmask) == 0, ("start address is not aligned")); in pcib_grow_window()
2025 KASSERT((w->limit & wmask) == wmask, ("end address is not aligned")); in pcib_grow_window()
2026 pcib_write_windows(sc, w->mask); in pcib_grow_window()
2031 * We have to trap resource allocation requests and ensure that the bridge
2034 static struct resource *
2038 struct pcib_softc *sc; in pcib_alloc_resource() local
2039 struct resource *r; in pcib_alloc_resource()
2041 sc = device_get_softc(dev); in pcib_alloc_resource()
2046 * the resource windows and are passed up to the parent. in pcib_alloc_resource()
2050 if (sc->bridgectl & PCIB_BCR_VGA_ENABLE) in pcib_alloc_resource()
2059 return (pcib_alloc_subbus(&sc->bus, child, rid, start, end, in pcib_alloc_resource()
2062 if (pcib_is_isa_range(sc, start, end, count)) in pcib_alloc_resource()
2064 r = pcib_suballoc_resource(sc, &sc->io, child, type, rid, start, in pcib_alloc_resource()
2066 if (r != NULL || (sc->flags & PCIB_SUBTRACTIVE) != 0) in pcib_alloc_resource()
2068 if (pcib_grow_window(sc, &sc->io, type, start, end, count, in pcib_alloc_resource()
2070 r = pcib_suballoc_resource(sc, &sc->io, child, type, in pcib_alloc_resource()
2083 r = pcib_suballoc_resource(sc, &sc->pmem, child, type, in pcib_alloc_resource()
2088 r = pcib_suballoc_resource(sc, &sc->mem, child, type, rid, in pcib_alloc_resource()
2090 if (r != NULL || (sc->flags & PCIB_SUBTRACTIVE) != 0) in pcib_alloc_resource()
2093 if (pcib_grow_window(sc, &sc->pmem, type, start, end, in pcib_alloc_resource()
2095 r = pcib_suballoc_resource(sc, &sc->pmem, child, in pcib_alloc_resource()
2101 if (pcib_grow_window(sc, &sc->mem, type, start, end, count, in pcib_alloc_resource()
2103 r = pcib_suballoc_resource(sc, &sc->mem, child, type, in pcib_alloc_resource()
2115 if (sc->flags & PCIB_SUBTRACTIVE && r == NULL) in pcib_alloc_resource()
2122 pcib_adjust_resource(device_t bus, device_t child, struct resource *r, in pcib_adjust_resource()
2125 struct pcib_softc *sc; in pcib_adjust_resource() local
2130 sc = device_get_softc(bus); in pcib_adjust_resource()
2134 * If the resource wasn't sub-allocated from one of our region in pcib_adjust_resource()
2137 if (!pcib_is_resource_managed(sc, r)) in pcib_adjust_resource()
2142 * If our bus range isn't big enough to grow the sub-allocation in pcib_adjust_resource()
2148 if (start >= sc->bus.sec && end > sc->bus.sub) { in pcib_adjust_resource()
2149 error = pcib_grow_subbus(&sc->bus, end); in pcib_adjust_resource()
2155 * Resource is managed and not a secondary bus number, must in pcib_adjust_resource()
2158 w = pcib_get_resource_window(sc, r); in pcib_adjust_resource()
2160 ("%s: no window for resource (%#jx-%#jx) type %d", in pcib_adjust_resource()
2164 * If our window isn't big enough to grow the sub-allocation in pcib_adjust_resource()
2167 if (start < w->base || end > w->limit) { in pcib_adjust_resource()
2168 wmask = ((rman_res_t)1 << w->step) - 1; in pcib_adjust_resource()
2169 error = pcib_expand_window(sc, w, type, in pcib_adjust_resource()
2170 MIN(start & ~wmask, w->base), in pcib_adjust_resource()
2171 MAX(end | wmask, w->limit)); in pcib_adjust_resource()
2175 device_printf(sc->dev, in pcib_adjust_resource()
2176 "grew %s window to %#jx-%#jx\n", in pcib_adjust_resource()
2177 w->name, (uintmax_t)w->base, in pcib_adjust_resource()
2178 (uintmax_t)w->limit); in pcib_adjust_resource()
2179 pcib_write_windows(sc, w->mask); in pcib_adjust_resource()
2187 pcib_release_resource(device_t dev, device_t child, struct resource *r) in pcib_release_resource()
2189 struct pcib_softc *sc; in pcib_release_resource() local
2192 sc = device_get_softc(dev); in pcib_release_resource()
2193 if (pcib_is_resource_managed(sc, r)) { in pcib_release_resource()
2205 pcib_activate_resource(device_t dev, device_t child, struct resource *r) in pcib_activate_resource()
2207 struct pcib_softc *sc = device_get_softc(dev); in pcib_activate_resource() local
2211 if (!pcib_is_resource_managed(sc, r)) in pcib_activate_resource()
2233 pcib_deactivate_resource(device_t dev, device_t child, struct resource *r) in pcib_deactivate_resource()
2235 struct pcib_softc *sc = device_get_softc(dev); in pcib_deactivate_resource() local
2239 if (!pcib_is_resource_managed(sc, r)) in pcib_deactivate_resource()
2255 static struct resource *
2256 pcib_find_parent_resource(struct pcib_window *w, struct resource *r) in pcib_find_parent_resource()
2258 for (int i = 0; i < w->count; i++) { in pcib_find_parent_resource()
2259 if (rman_get_start(w->res[i]) <= rman_get_start(r) && in pcib_find_parent_resource()
2260 rman_get_end(w->res[i]) >= rman_get_end(r)) in pcib_find_parent_resource()
2261 return (w->res[i]); in pcib_find_parent_resource()
2267 pcib_map_resource(device_t dev, device_t child, struct resource *r, in pcib_map_resource()
2270 struct pcib_softc *sc = device_get_softc(dev); in pcib_map_resource() local
2273 struct resource *pres; in pcib_map_resource()
2277 w = pcib_get_resource_window(sc, r); in pcib_map_resource()
2294 args.offset = start - rman_get_start(pres); in pcib_map_resource()
2300 pcib_unmap_resource(device_t dev, device_t child, struct resource *r, in pcib_unmap_resource()
2303 struct pcib_softc *sc = device_get_softc(dev); in pcib_unmap_resource() local
2305 struct resource *pres; in pcib_unmap_resource()
2307 w = pcib_get_resource_window(sc, r); in pcib_unmap_resource()
2319 * to the non-ARI slot/function. The downstream port will convert it back in
2325 struct pcib_softc *sc; in pcib_xlate_ari() local
2328 sc = device_get_softc(pcib); in pcib_xlate_ari()
2331 if (sc->flags & PCIB_ENABLE_ARI) { in pcib_xlate_ari()
2333 ("Non-zero slot number with ARI enabled!")); in pcib_xlate_ari()
2340 pcib_enable_ari(struct pcib_softc *sc, uint32_t pcie_pos) in pcib_enable_ari() argument
2344 ctl2 = pci_read_config(sc->dev, pcie_pos + PCIER_DEVICE_CTL2, 4); in pcib_enable_ari()
2346 pci_write_config(sc->dev, pcie_pos + PCIER_DEVICE_CTL2, ctl2, 4); in pcib_enable_ari()
2348 sc->flags |= PCIB_ENABLE_ARI; in pcib_enable_ari()
2379 struct pcib_softc *sc; in pcib_ari_maxslots() local
2381 sc = device_get_softc(dev); in pcib_ari_maxslots()
2383 if (sc->flags & PCIB_ENABLE_ARI) in pcib_ari_maxslots()
2392 struct pcib_softc *sc; in pcib_ari_maxfuncs() local
2394 sc = device_get_softc(dev); in pcib_ari_maxfuncs()
2396 if (sc->flags & PCIB_ENABLE_ARI) in pcib_ari_maxfuncs()
2406 struct pcib_softc *sc; in pcib_ari_decode_rid() local
2408 sc = device_get_softc(pcib); in pcib_ari_decode_rid()
2411 if (sc->flags & PCIB_ENABLE_ARI) { in pcib_ari_decode_rid()
2427 struct pcib_softc *sc; in pcib_read_config() local
2429 sc = device_get_softc(dev); in pcib_read_config()
2430 if (!pcib_present(sc)) { in pcib_read_config()
2450 struct pcib_softc *sc; in pcib_write_config() local
2452 sc = device_get_softc(dev); in pcib_write_config()
2453 if (!pcib_present(sc)) in pcib_write_config()
2473 * The PCI standard defines a swizzle of the child-side device/intpin to in pcib_route_interrupt()
2474 * the parent-side intpin as follows. in pcib_route_interrupt()
2477 * child_intpin = intpin on child bus slot (0-3) in pcib_route_interrupt()
2478 * parent_intpin = intpin on parent bus slot (0-3) in pcib_route_interrupt()
2482 parent_intpin = (pci_get_slot(dev) + (pin - 1)) % 4; in pcib_route_interrupt()
2492 pci_get_slot(dev), 'A' + pin - 1, intnum); in pcib_route_interrupt()
2497 /* Pass request to alloc MSI/MSI-X messages up to the parent bridge. */
2501 struct pcib_softc *sc = device_get_softc(pcib); in pcib_alloc_msi() local
2504 if (sc->flags & PCIB_DISABLE_MSI) in pcib_alloc_msi()
2511 /* Pass request to release MSI/MSI-X messages up to the parent bridge. */
2521 /* Pass request to alloc an MSI-X message up to the parent bridge. */
2525 struct pcib_softc *sc = device_get_softc(pcib); in pcib_alloc_msix() local
2528 if (sc->flags & PCIB_DISABLE_MSIX) in pcib_alloc_msix()
2534 /* Pass request to release an MSI-X message up to the parent bridge. */
2544 /* Pass request to map MSI/MSI-X message up to parent bridge. */
2574 struct pcib_softc *sc; in pcib_ari_enabled() local
2576 sc = device_get_softc(pcib); in pcib_ari_enabled()
2578 return ((sc->flags & PCIB_ENABLE_ARI) != 0); in pcib_ari_enabled()
2585 struct pcib_softc *sc; in pcib_ari_get_id() local
2594 sc = device_get_softc(pcib); in pcib_ari_get_id()
2596 if (sc->flags & PCIB_ENABLE_ARI) { in pcib_ari_get_id()
2619 struct pcib_softc *sc; in pcib_try_enable_ari() local
2626 sc = device_get_softc(pcib); in pcib_try_enable_ari()
2664 pcib_enable_ari(sc, pcie_pos); in pcib_try_enable_ari()
2694 * the firmware overrides the method of PCI-PCI bridges. in pcib_request_feature()
2734 if (pdinfo->cfg.pcie.pcie_location != 0 && in pcib_reset_child()
2735 (pdinfo->cfg.pcie.pcie_type == PCIEM_TYPE_DOWNSTREAM_PORT || in pcib_reset_child()
2736 pdinfo->cfg.pcie.pcie_type == PCIEM_TYPE_ROOT_PORT)) { in pcib_reset_child()
2740 pdinfo->cfg.pcie.pcie_location); in pcib_reset_child()