Lines Matching +full:bus +full:- +full:range
1 /*-
33 #include <sys/bus.h>
66 int ap_bus; /* bios-assigned bus number */
67 int ap_addr; /* device/func of PCI-Host bridge */
73 static int acpi_pcib_acpi_probe(device_t bus);
74 static int acpi_pcib_acpi_attach(device_t bus);
79 static uint32_t acpi_pcib_read_config(device_t dev, u_int bus,
81 static void acpi_pcib_write_config(device_t dev, u_int bus,
107 static bus_dma_tag_t acpi_pcib_get_dma_tag(device_t bus, device_t child);
117 /* Bus interface */
161 root = (devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0; in acpi_pcib_acpi_probe()
166 device_set_desc(dev, "ACPI Host-PCI bridge"); in acpi_pcib_acpi_probe()
179 switch (res->Type) { in acpi_pcib_producer_handler()
187 if (res->Data.Address.ProducerConsumer != ACPI_PRODUCER) in acpi_pcib_producer_handler()
189 switch (res->Type) { in acpi_pcib_producer_handler()
191 min = res->Data.Address16.Address.Minimum; in acpi_pcib_producer_handler()
192 max = res->Data.Address16.Address.Maximum; in acpi_pcib_producer_handler()
193 length = res->Data.Address16.Address.AddressLength; in acpi_pcib_producer_handler()
196 min = res->Data.Address32.Address.Minimum; in acpi_pcib_producer_handler()
197 max = res->Data.Address32.Address.Maximum; in acpi_pcib_producer_handler()
198 length = res->Data.Address32.Address.AddressLength; in acpi_pcib_producer_handler()
201 min = res->Data.Address64.Address.Minimum; in acpi_pcib_producer_handler()
202 max = res->Data.Address64.Address.Maximum; in acpi_pcib_producer_handler()
203 length = res->Data.Address64.Address.AddressLength; in acpi_pcib_producer_handler()
206 KASSERT(res->Type == in acpi_pcib_producer_handler()
209 min = res->Data.ExtAddress64.Address.Minimum; in acpi_pcib_producer_handler()
210 max = res->Data.ExtAddress64.Address.Maximum; in acpi_pcib_producer_handler()
211 length = res->Data.ExtAddress64.Address.AddressLength; in acpi_pcib_producer_handler()
216 if (min + length - 1 != max && in acpi_pcib_producer_handler()
217 (res->Data.Address.MinAddressFixed != ACPI_ADDRESS_FIXED || in acpi_pcib_producer_handler()
218 res->Data.Address.MaxAddressFixed != ACPI_ADDRESS_FIXED)) in acpi_pcib_producer_handler()
221 switch (res->Data.Address.ResourceType) { in acpi_pcib_producer_handler()
224 if (res->Type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64) { in acpi_pcib_producer_handler()
225 if (res->Data.Address.Info.Mem.Caching == in acpi_pcib_producer_handler()
245 if (min + length - 1 != max) in acpi_pcib_producer_handler()
246 device_printf(sc->ap_dev, in acpi_pcib_producer_handler()
247 "Length mismatch for %d range: %jx vs %jx\n", type, in acpi_pcib_producer_handler()
248 (uintmax_t)(max - min + 1), (uintmax_t)length); in acpi_pcib_producer_handler()
251 device_printf(sc->ap_dev, in acpi_pcib_producer_handler()
252 "Ignoring %d range above 4GB (%#jx-%#jx)\n", in acpi_pcib_producer_handler()
257 device_printf(sc->ap_dev, in acpi_pcib_producer_handler()
258 "Truncating end of %d range above 4GB (%#jx-%#jx)\n", in acpi_pcib_producer_handler()
263 error = pcib_host_res_decodes(&sc->ap_host_res, type, min, max, in acpi_pcib_producer_handler()
266 panic("Failed to manage %d range (%#jx-%#jx): %d", in acpi_pcib_producer_handler()
281 rle = resource_list_find(&sc->ap_host_res.hr_rl, PCI_RES_BUS, 0); in get_decoded_bus_range()
284 *startp = rle->start; in get_decoded_bus_range()
285 *endp = rle->end; in get_decoded_bus_range()
305 sc->ap_dev = dev; in acpi_pcib_acpi_attach()
306 sc->ap_handle = acpi_get_handle(dev); in acpi_pcib_acpi_attach()
314 acpi_pcib_osc(dev, &sc->ap_osc_ctl, 0); in acpi_pcib_acpi_attach()
320 status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment); in acpi_pcib_acpi_attach()
323 device_printf(dev, "could not evaluate _SEG - %s\n", in acpi_pcib_acpi_attach()
328 sc->ap_segment = 0; in acpi_pcib_acpi_attach()
333 * PCI-Host bridge device from _ADR. Assume we don't have one if in acpi_pcib_acpi_attach()
336 status = acpi_GetInteger(sc->ap_handle, "_ADR", &sc->ap_addr); in acpi_pcib_acpi_attach()
339 device_printf(dev, "could not evaluate _ADR - %s\n", in acpi_pcib_acpi_attach()
341 sc->ap_addr = -1; in acpi_pcib_acpi_attach()
348 if (pcib_host_res_init(sc->ap_dev, &sc->ap_host_res) != 0) in acpi_pcib_acpi_attach()
351 status = AcpiWalkResources(sc->ap_handle, "_CRS", in acpi_pcib_acpi_attach()
354 device_printf(sc->ap_dev, "failed to parse resources: %s\n", in acpi_pcib_acpi_attach()
359 * Get our base bus number by evaluating _BBN. in acpi_pcib_acpi_attach()
360 * If this doesn't work, we assume we're bus number 0. in acpi_pcib_acpi_attach()
363 * meant to use a private configuration space mechanism for this bus, in acpi_pcib_acpi_attach()
367 * default PCI configuration space handlers can deal with this bus, in acpi_pcib_acpi_attach()
370 * XXX It seems many BIOS's with multiple Host-PCI bridges do not set in acpi_pcib_acpi_attach()
372 * if _BBN is zero and PCI bus 0 already exists, we try to read our in acpi_pcib_acpi_attach()
373 * bus number from the configuration registers at address _ADR. in acpi_pcib_acpi_attach()
375 * only needed for old single-domain machines. in acpi_pcib_acpi_attach()
377 status = acpi_GetInteger(sc->ap_handle, "_BBN", &sc->ap_bus); in acpi_pcib_acpi_attach()
380 device_printf(dev, "could not evaluate _BBN - %s\n", in acpi_pcib_acpi_attach()
385 sc->ap_bus = 0; in acpi_pcib_acpi_attach()
390 * If this is segment 0, the bus is zero, and PCI bus 0 already in acpi_pcib_acpi_attach()
391 * exists, read the bus number via PCI config space. in acpi_pcib_acpi_attach()
394 if (sc->ap_segment == 0 && sc->ap_bus == 0 && bus0_seen) { in acpi_pcib_acpi_attach()
396 if (sc->ap_addr != -1) { in acpi_pcib_acpi_attach()
397 /* XXX: We assume bus 0. */ in acpi_pcib_acpi_attach()
398 slot = ACPI_ADR_PCI_SLOT(sc->ap_addr); in acpi_pcib_acpi_attach()
399 func = ACPI_ADR_PCI_FUNC(sc->ap_addr); in acpi_pcib_acpi_attach()
404 device_printf(dev, "couldn't read bus number from cfg space\n"); in acpi_pcib_acpi_attach()
406 sc->ap_bus = busno; in acpi_pcib_acpi_attach()
414 * Host-PCI bridges in order and that as a result the next free in acpi_pcib_acpi_attach()
415 * bus number is our bus number. in acpi_pcib_acpi_attach()
419 * If we have a region of bus numbers, use the first in acpi_pcib_acpi_attach()
420 * number for our bus. in acpi_pcib_acpi_attach()
423 sc->ap_bus = start; in acpi_pcib_acpi_attach()
426 bus_res = pci_domain_alloc_bus(sc->ap_segment, dev, &rid, 0, in acpi_pcib_acpi_attach()
430 "could not allocate bus number\n"); in acpi_pcib_acpi_attach()
431 pcib_host_res_free(dev, &sc->ap_host_res); in acpi_pcib_acpi_attach()
434 sc->ap_bus = rman_get_start(bus_res); in acpi_pcib_acpi_attach()
435 pci_domain_release_bus(sc->ap_segment, dev, bus_res); in acpi_pcib_acpi_attach()
439 * If there is a decoded bus range, assume the bus number is in acpi_pcib_acpi_attach()
440 * the first value in the range. Warn if _BBN doesn't match. in acpi_pcib_acpi_attach()
443 if (sc->ap_bus != start) { in acpi_pcib_acpi_attach()
445 "WARNING: BIOS configured bus number (%d) is " in acpi_pcib_acpi_attach()
446 "not within decoded bus number range " in acpi_pcib_acpi_attach()
447 "(%ju - %ju).\n", in acpi_pcib_acpi_attach()
448 sc->ap_bus, (uintmax_t)start, (uintmax_t)end); in acpi_pcib_acpi_attach()
450 "Using range start (%ju) as bus number.\n", in acpi_pcib_acpi_attach()
452 sc->ap_bus = start; in acpi_pcib_acpi_attach()
457 /* If this is bus 0 on segment 0, note that it has been seen already. */ in acpi_pcib_acpi_attach()
458 if (sc->ap_segment == 0 && sc->ap_bus == 0) in acpi_pcib_acpi_attach()
461 acpi_pcib_fetch_prt(dev, &sc->ap_prt); in acpi_pcib_acpi_attach()
466 BUS_SPACE_MAXSIZE, 0, NULL, NULL, &sc->ap_dma_tag); in acpi_pcib_acpi_attach()
471 error = bus_dma_tag_set_domain(sc->ap_dma_tag, domain); in acpi_pcib_acpi_attach()
476 if (device_add_child(dev, "pci", -1) == NULL) { in acpi_pcib_acpi_attach()
477 bus_dma_tag_destroy(sc->ap_dma_tag); in acpi_pcib_acpi_attach()
478 sc->ap_dma_tag = NULL; in acpi_pcib_acpi_attach()
486 device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); in acpi_pcib_acpi_attach()
487 pcib_host_res_free(dev, &sc->ap_host_res); in acpi_pcib_acpi_attach()
501 *result = sc->ap_segment; in acpi_pcib_read_ivar()
504 *result = sc->ap_bus; in acpi_pcib_read_ivar()
507 *result = (uintptr_t)sc->ap_handle; in acpi_pcib_read_ivar()
510 *result = (uintptr_t)sc->ap_flags; in acpi_pcib_read_ivar()
525 sc->ap_bus = value; in acpi_pcib_write_ivar()
528 sc->ap_handle = (ACPI_HANDLE)value; in acpi_pcib_write_ivar()
531 sc->ap_flags = (int)value; in acpi_pcib_write_ivar()
538 acpi_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, in acpi_pcib_read_config() argument
543 return (pci_cfgregread(sc->ap_segment, bus, slot, func, reg, bytes)); in acpi_pcib_read_config()
547 acpi_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, in acpi_pcib_write_config() argument
552 pci_cfgregwrite(sc->ap_segment, bus, slot, func, reg, data, bytes); in acpi_pcib_write_config()
560 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); in acpi_pcib_acpi_route_interrupt()
567 device_t bus; in acpi_pcib_alloc_msi() local
569 bus = device_get_parent(pcib); in acpi_pcib_alloc_msi()
570 return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount, in acpi_pcib_alloc_msi()
577 device_t bus; in acpi_pcib_alloc_msix() local
579 bus = device_get_parent(pcib); in acpi_pcib_alloc_msix()
580 return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq)); in acpi_pcib_alloc_msix()
588 device_t bus, hostb; in acpi_pcib_map_msi() local
591 bus = device_get_parent(pcib); in acpi_pcib_map_msi()
592 error = PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data); in acpi_pcib_map_msi()
597 if (sc->ap_addr == -1) in acpi_pcib_map_msi()
599 /* XXX: Assumes all bridges are on bus 0. */ in acpi_pcib_map_msi()
600 hostb = pci_find_dbsf(sc->ap_segment, 0, ACPI_ADR_PCI_SLOT(sc->ap_addr), in acpi_pcib_map_msi()
601 ACPI_ADR_PCI_FUNC(sc->ap_addr)); in acpi_pcib_map_msi()
620 return (pci_domain_alloc_bus(sc->ap_segment, child, rid, start, end, in acpi_pcib_acpi_alloc_resource()
622 res = pcib_host_res_alloc(&sc->ap_host_res, child, type, rid, start, end, in acpi_pcib_acpi_alloc_resource()
626 * XXX: If this is a request for a specific range, assume it is in acpi_pcib_acpi_alloc_resource()
628 * do long-term is explicitly trust any firmware-configured in acpi_pcib_acpi_alloc_resource()
629 * resources during the initial bus scan on boot and then disable in acpi_pcib_acpi_alloc_resource()
632 if (res == NULL && start + count - 1 == end) in acpi_pcib_acpi_alloc_resource()
646 return (pci_domain_adjust_bus(sc->ap_segment, child, r, start, in acpi_pcib_acpi_adjust_resource()
648 return (pcib_host_res_adjust(&sc->ap_host_res, child, r, start, end)); in acpi_pcib_acpi_adjust_resource()
659 return (pci_domain_release_bus(sc->ap_segment, child, r)); in acpi_pcib_acpi_release_resource()
671 return (pci_domain_activate_bus(sc->ap_segment, child, r)); in acpi_pcib_acpi_activate_resource()
683 return (pci_domain_deactivate_bus(sc->ap_segment, child, r)); in acpi_pcib_acpi_deactivate_resource()
706 return (acpi_pcib_osc(pcib, &sc->ap_osc_ctl, osc_ctl)); in acpi_pcib_request_feature()
710 acpi_pcib_get_dma_tag(device_t bus, device_t child) in acpi_pcib_get_dma_tag() argument
714 sc = device_get_softc(bus); in acpi_pcib_get_dma_tag()
716 return (sc->ap_dma_tag); in acpi_pcib_get_dma_tag()