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