Lines Matching +full:pci +full:- +full:iommu
1 // SPDX-License-Identifier: GPL-2.0
2 /* pci.c: UltraSparc PCI controller support.
8 * OF tree based PCI bus probing taken from the PowerPC port
18 #include <linux/pci.h>
35 /* List of all PCI controllers found in the system. */
42 volatile int pci_poke_cpu = -1;
63 pci_poke_cpu = -1; in pci_config_read8()
85 pci_poke_cpu = -1; in pci_config_read16()
107 pci_poke_cpu = -1; in pci_config_read32()
128 pci_poke_cpu = -1; in pci_config_write8()
147 pci_poke_cpu = -1; in pci_config_write16()
166 pci_poke_cpu = -1; in pci_config_write32()
202 /* The of_device layer has translated all of the assigned-address properties
214 addrs = of_get_property(node, "assigned-addresses", &proplen); in pci_parse_of_addrs()
220 op_res = &op->resource[0]; in pci_parse_of_addrs()
221 for (; proplen >= 20; proplen -= 20, addrs += 5, op_res++) { in pci_parse_of_addrs()
232 op_res->start, op_res->end, i); in pci_parse_of_addrs()
235 res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2]; in pci_parse_of_addrs()
236 } else if (i == dev->rom_base_reg) { in pci_parse_of_addrs()
237 res = &dev->resource[PCI_ROM_RESOURCE]; in pci_parse_of_addrs()
243 res->start = op_res->start; in pci_parse_of_addrs()
244 res->end = op_res->end; in pci_parse_of_addrs()
245 res->flags = flags; in pci_parse_of_addrs()
246 res->name = pci_name(dev); in pci_parse_of_addrs()
252 static void pci_init_dev_archdata(struct dev_archdata *sd, void *iommu, in pci_init_dev_archdata() argument
257 sd->iommu = iommu; in pci_init_dev_archdata()
258 sd->stc = stc; in pci_init_dev_archdata()
259 sd->host_controller = host_controller; in pci_init_dev_archdata()
260 sd->op = op; in pci_init_dev_archdata()
261 sd->numa_node = numa_node; in pci_init_dev_archdata()
278 sd = &dev->dev.archdata; in of_create_pci_dev()
279 pci_init_dev_archdata(sd, pbm->iommu, &pbm->stc, pbm, op, in of_create_pci_dev()
280 pbm->numa_node); in of_create_pci_dev()
281 sd = &op->dev.archdata; in of_create_pci_dev()
282 sd->iommu = pbm->iommu; in of_create_pci_dev()
283 sd->stc = &pbm->stc; in of_create_pci_dev()
284 sd->numa_node = pbm->numa_node; in of_create_pci_dev()
293 dev->sysdata = node; in of_create_pci_dev()
294 dev->dev.parent = bus->bridge; in of_create_pci_dev()
295 dev->dev.bus = &pci_bus_type; in of_create_pci_dev()
296 dev->dev.of_node = of_node_get(node); in of_create_pci_dev()
297 dev->devfn = devfn; in of_create_pci_dev()
298 dev->multifunction = 0; /* maybe a lie? */ in of_create_pci_dev()
302 dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff); in of_create_pci_dev()
303 dev->device = of_getintprop_default(node, "device-id", 0xffff); in of_create_pci_dev()
304 dev->subsystem_vendor = in of_create_pci_dev()
305 of_getintprop_default(node, "subsystem-vendor-id", 0); in of_create_pci_dev()
306 dev->subsystem_device = in of_create_pci_dev()
307 of_getintprop_default(node, "subsystem-id", 0); in of_create_pci_dev()
309 dev->cfg_size = pci_cfg_space_size(dev); in of_create_pci_dev()
318 dev->class = class >> 8; in of_create_pci_dev()
319 dev->revision = class & 0xff; in of_create_pci_dev()
321 dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(bus), in of_create_pci_dev()
322 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); in of_create_pci_dev()
328 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) in of_create_pci_dev()
331 dev->current_state = PCI_UNKNOWN; /* unknown power state */ in of_create_pci_dev()
332 dev->error_state = pci_channel_io_normal; in of_create_pci_dev()
333 dev->dma_mask = 0xffffffff; in of_create_pci_dev()
335 if (of_node_name_eq(node, "pci")) { in of_create_pci_dev()
336 /* a PCI-PCI bridge */ in of_create_pci_dev()
337 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE; in of_create_pci_dev()
338 dev->rom_base_reg = PCI_ROM_ADDRESS1; in of_create_pci_dev()
340 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS; in of_create_pci_dev()
342 dev->hdr_type = PCI_HEADER_TYPE_NORMAL; in of_create_pci_dev()
343 dev->rom_base_reg = PCI_ROM_ADDRESS; in of_create_pci_dev()
345 dev->irq = sd->op->archdata.irqs[0]; in of_create_pci_dev()
346 if (dev->irq == 0xffffffff) in of_create_pci_dev()
347 dev->irq = PCI_IRQ_NONE; in of_create_pci_dev()
351 dev->vendor, dev->device, dev->hdr_type, dev->class); in of_create_pci_dev()
353 pci_parse_of_addrs(sd->op, node, dev); in of_create_pci_dev()
382 /* Cook up fake bus resources for SUNW,simba PCI bridges which lack
396 res = bus->resource[0]; in apb_fake_ranges()
397 res->flags = IORESOURCE_IO; in apb_fake_ranges()
399 region.end = (last << 21) + ((1 << 21) - 1); in apb_fake_ranges()
400 pcibios_bus_to_resource(dev->bus, res, ®ion); in apb_fake_ranges()
404 res = bus->resource[1]; in apb_fake_ranges()
405 res->flags = IORESOURCE_MEM; in apb_fake_ranges()
407 region.end = (last << 29) + ((1 << 29) - 1); in apb_fake_ranges()
408 pcibios_bus_to_resource(dev->bus, res, ®ion); in apb_fake_ranges()
432 /* parse bus-range property */ in of_scan_pci_bridge()
433 busrange = of_get_property(node, "bus-range", &len); in of_scan_pci_bridge()
435 pci_info(dev, "Can't get bus-range for PCI-PCI bridge %pOF\n", in of_scan_pci_bridge()
441 pci_info(dev, " Bridge bus range [%u --> %u]\n", in of_scan_pci_bridge()
452 bus = pci_add_new_bus(dev->bus, dev, busrange[0]); in of_scan_pci_bridge()
454 pci_err(dev, "Failed to create pci bus for %pOF\n", in of_scan_pci_bridge()
459 bus->primary = dev->bus->number; in of_scan_pci_bridge()
461 bus->bridge_ctl = 0; in of_scan_pci_bridge()
468 /* PCI #address-cells == 3 and #size-cells == 2 always */ in of_scan_pci_bridge()
469 res = &dev->resource[PCI_BRIDGE_RESOURCES]; in of_scan_pci_bridge()
470 for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) { in of_scan_pci_bridge()
471 res->flags = 0; in of_scan_pci_bridge()
472 bus->resource[i] = res; in of_scan_pci_bridge()
483 for (; len >= 32; len -= 32, ranges += 8) { in of_scan_pci_bridge()
497 /* On PCI-Express systems, PCI bridges that have no devices downstream in of_scan_pci_bridge()
498 * have a bogus size value where the first 32-bit cell is 0xffffffff. in of_scan_pci_bridge()
508 res = bus->resource[0]; in of_scan_pci_bridge()
509 if (res->flags) { in of_scan_pci_bridge()
515 if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) { in of_scan_pci_bridge()
520 res = bus->resource[i]; in of_scan_pci_bridge()
524 res->flags = flags; in of_scan_pci_bridge()
526 region.end = region.start + size - 1; in of_scan_pci_bridge()
532 pcibios_bus_to_resource(dev->bus, res, ®ion); in of_scan_pci_bridge()
535 sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus), in of_scan_pci_bridge()
536 bus->number); in of_scan_pci_bridge()
538 pci_info(dev, " bus name: %s\n", bus->name); in of_scan_pci_bridge()
554 node, bus->number); in pci_of_scan_bus()
556 prev_devfn = -1; in pci_of_scan_bus()
567 * which list PCI devices twice. On the V100 in pci_of_scan_bus()
580 pci_info(dev, "dev header type: %x\n", dev->hdr_type); in pci_of_scan_bus()
594 dp = pdev->dev.of_node; in show_pciobppath_attr()
607 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_bus_register_of_sysfs()
615 err = sysfs_create_file(&dev->dev.kobj, &dev_attr_obppath.attr); in pci_bus_register_of_sysfs()
618 list_for_each_entry(child_bus, &bus->children, node) in pci_bus_register_of_sysfs()
627 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in pci_claim_legacy_resources()
634 p->name = "Video RAM area"; in pci_claim_legacy_resources()
635 p->flags = IORESOURCE_MEM | IORESOURCE_BUSY; in pci_claim_legacy_resources()
639 pcibios_bus_to_resource(dev->bus, p, ®ion); in pci_claim_legacy_resources()
650 p, conflict->name, conflict); in pci_claim_legacy_resources()
666 list_for_each_entry(dev, &bus->devices, bus_list) { in pci_claim_bus_resources()
671 if (r->parent || !r->start || !r->flags) in pci_claim_bus_resources()
684 list_for_each_entry(child_bus, &bus->children, node) in pci_claim_bus_resources()
692 struct device_node *node = pbm->op->dev.of_node; in pci_scan_one_pbm()
695 printk("PCI: Scanning PBM %pOF\n", node); in pci_scan_one_pbm()
697 pci_add_resource_offset(&resources, &pbm->io_space, in pci_scan_one_pbm()
698 pbm->io_offset); in pci_scan_one_pbm()
699 pci_add_resource_offset(&resources, &pbm->mem_space, in pci_scan_one_pbm()
700 pbm->mem_offset); in pci_scan_one_pbm()
701 if (pbm->mem64_space.flags) in pci_scan_one_pbm()
702 pci_add_resource_offset(&resources, &pbm->mem64_space, in pci_scan_one_pbm()
703 pbm->mem64_offset); in pci_scan_one_pbm()
704 pbm->busn.start = pbm->pci_first_busno; in pci_scan_one_pbm()
705 pbm->busn.end = pbm->pci_last_busno; in pci_scan_one_pbm()
706 pbm->busn.flags = IORESOURCE_BUS; in pci_scan_one_pbm()
707 pci_add_resource(&resources, &pbm->busn); in pci_scan_one_pbm()
708 bus = pci_create_root_bus(parent, pbm->pci_first_busno, pbm->pci_ops, in pci_scan_one_pbm()
739 if (res->flags & IORESOURCE_IO) in pcibios_enable_device()
741 if (res->flags & IORESOURCE_MEM) in pcibios_enable_device()
746 pci_info(dev, "enabling device (%04x -> %04x)\n", oldcmd, cmd); in pcibios_enable_device()
752 /* Platform support for /proc/bus/pci/X/Y mmap()s. */
755 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; in pci_iobar_pfn()
759 return -EINVAL; in pci_iobar_pfn()
761 vma->vm_pgoff += (ioaddr + pbm->io_space.start) >> PAGE_SHIFT; in pci_iobar_pfn()
769 struct pci_pbm_info *pbm = pbus->sysdata; in pcibus_to_node()
771 return pbm->numa_node; in pcibus_to_node()
776 /* Return the domain number for this pci bus */
780 struct pci_pbm_info *pbm = pbus->sysdata; in pci_domain_nr()
784 ret = -ENXIO; in pci_domain_nr()
786 ret = pbm->index; in pci_domain_nr()
796 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; in arch_setup_msi_irq()
799 if (!pbm->setup_msi_irq) in arch_setup_msi_irq()
800 return -EINVAL; in arch_setup_msi_irq()
802 return pbm->setup_msi_irq(&irq, pdev, desc); in arch_setup_msi_irq()
809 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; in arch_teardown_msi_irq()
811 if (pbm->teardown_msi_irq) in arch_teardown_msi_irq()
812 pbm->teardown_msi_irq(irq, pdev); in arch_teardown_msi_irq()
816 /* ALI sound chips generate 31-bits of DMA, a special register
821 struct iommu *iommu = dev->archdata.iommu; in ali_sound_dma_hack() local
828 if (to_pci_dev(dev)->vendor != PCI_VENDOR_ID_AL || in ali_sound_dma_hack()
829 to_pci_dev(dev)->device != PCI_DEVICE_ID_AL_M5451 || in ali_sound_dma_hack()
838 if (iommu->dma_addr_mask & 0x80000000) in ali_sound_dma_hack()
854 * "User" addresses are shown in /sys/devices/pci.../.../resource in pci_resource_to_user()
855 * and /proc/bus/pci/devices and used as mmap offsets for in pci_resource_to_user()
856 * /proc/bus/pci/BB/DD.F files (see proc_bus_pci_mmap()). in pci_resource_to_user()
858 * On sparc, these are PCI bus addresses, i.e., raw BAR values. in pci_resource_to_user()
860 pcibios_resource_to_bus(pdev->bus, ®ion, (struct resource *) rp); in pci_resource_to_user()
878 if (dev->is_virtfn) { in pcibios_device_add()
881 pdev = dev->physfn; in pcibios_device_add()
882 psd = &pdev->dev.archdata; in pcibios_device_add()
883 pci_init_dev_archdata(&dev->dev.archdata, psd->iommu, in pcibios_device_add()
884 psd->stc, psd->host_controller, NULL, in pcibios_device_add()
885 psd->numa_node); in pcibios_device_add()
907 list_for_each_entry(pdev, &pbus->devices, bus_list) { in pcie_bus_slot_names()
913 slot_num = of_get_property(pdev->dev.of_node, in pcie_bus_slot_names()
914 "physical-slot#", &len); in pcie_bus_slot_names()
923 pr_err("PCI: pci_create_slot returned %ld.\n", in pcie_bus_slot_names()
927 list_for_each_entry(bus, &pbus->children, node) in pcie_bus_slot_names()
941 prop = of_get_property(node, "slot-names", &len); in pci_bus_slot_names()
945 mask = prop->slot_mask; in pci_bus_slot_names()
946 sp = prop->names; in pci_bus_slot_names()
984 pdev = list_first_entry(&pbus->devices, struct pci_dev, in of_pci_slot_init()
991 if (pbus->self) { in of_pci_slot_init()
993 /* PCI->PCI bridge */ in of_pci_slot_init()
994 node = pbus->self->dev.of_node; in of_pci_slot_init()
997 struct pci_pbm_info *pbm = pbus->sysdata; in of_pci_slot_init()
999 /* Host PCI controller */ in of_pci_slot_init()
1000 node = pbm->op->dev.of_node; in of_pci_slot_init()