Lines Matching +full:pci +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Helper routines to scan the device tree for PCI devices and busses
10 * Rework, based on alpha PCI code.
14 #include <linux/pci.h>
17 #include <asm/pci-bridge.h>
20 * get_int_prop - Decode a u32 from a device tree property
34 * pci_parse_of_flags - Parse the flags cell of a device tree PCI address
35 * @addr0: value of 1st cell of a device tree PCI address.
38 * PCI Bus Binding to IEEE Std 1275-1994
49 * t is 1 if the address is aliased (for non-relocatable I/O),
54 * 10 denotes 32-bit-address Memory Space
55 * 11 denotes 64-bit-address Memory Space
56 * bbbbbbbb is the 8-bit Bus Number
57 * ddddd is the 5-bit Device Number
58 * fff is the 3-bit Function Number
59 * rrrrrrrr is the 8-bit Register Number
95 * do a config space read, it will be force-enabled if needed in pci_parse_of_flags()
110 * of_pci_parse_addrs - Parse PCI addresses assigned in the device tree node
111 * @node: device tree node for the PCI device
112 * @dev: pci_dev structure for the device
114 * This function parses the 'assigned-addresses' property of a PCI devices'
117 static void of_pci_parse_addrs(struct device_node *node, struct pci_dev *dev) in of_pci_parse_addrs() argument
128 addrs = of_get_property(node, "assigned-addresses", &proplen); in of_pci_parse_addrs()
137 for (; proplen >= 20; proplen -= 20, addrs += 5) { in of_pci_parse_addrs()
151 res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2]; in of_pci_parse_addrs()
152 } else if (i == dev->rom_base_reg) { in of_pci_parse_addrs()
153 res = &dev->resource[PCI_ROM_RESOURCE]; in of_pci_parse_addrs()
156 printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i); in of_pci_parse_addrs()
159 res->flags = flags; in of_pci_parse_addrs()
161 res->flags |= IORESOURCE_UNSET; in of_pci_parse_addrs()
162 res->name = pci_name(dev); in of_pci_parse_addrs()
164 region.end = base + size - 1; in of_pci_parse_addrs()
165 pcibios_bus_to_resource(dev->bus, res, ®ion); in of_pci_parse_addrs()
170 * of_create_pci_dev - Given a device tree node on a pci bus, create a pci_dev
173 * @devfn: PCI function number, extracted from device tree by caller.
178 struct pci_dev *dev; in of_create_pci_dev() local
180 dev = pci_alloc_dev(bus); in of_create_pci_dev()
181 if (!dev) in of_create_pci_dev()
187 dev->dev.of_node = of_node_get(node); in of_create_pci_dev()
188 dev->dev.parent = bus->bridge; in of_create_pci_dev()
189 dev->dev.bus = &pci_bus_type; in of_create_pci_dev()
190 dev->devfn = devfn; in of_create_pci_dev()
191 dev->multifunction = 0; /* maybe a lie? */ in of_create_pci_dev()
192 dev->needs_freset = 0; /* pcie fundamental reset required */ in of_create_pci_dev()
193 set_pcie_port_type(dev); in of_create_pci_dev()
195 pci_dev_assign_slot(dev); in of_create_pci_dev()
196 dev->vendor = get_int_prop(node, "vendor-id", 0xffff); in of_create_pci_dev()
197 dev->device = get_int_prop(node, "device-id", 0xffff); in of_create_pci_dev()
198 dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0); in of_create_pci_dev()
199 dev->subsystem_device = get_int_prop(node, "subsystem-id", 0); in of_create_pci_dev()
201 dev->cfg_size = pci_cfg_space_size(dev); in of_create_pci_dev()
203 dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(bus), in of_create_pci_dev()
204 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); in of_create_pci_dev()
205 dev->class = get_int_prop(node, "class-code", 0); in of_create_pci_dev()
206 dev->revision = get_int_prop(node, "revision-id", 0); in of_create_pci_dev()
208 pr_debug(" class: 0x%x\n", dev->class); in of_create_pci_dev()
209 pr_debug(" revision: 0x%x\n", dev->revision); in of_create_pci_dev()
211 dev->current_state = PCI_UNKNOWN; /* unknown power state */ in of_create_pci_dev()
212 dev->error_state = pci_channel_io_normal; in of_create_pci_dev()
213 dev->dma_mask = 0xffffffff; in of_create_pci_dev()
216 pci_fixup_device(pci_fixup_early, dev); in of_create_pci_dev()
218 if (of_node_is_type(node, "pci") || of_node_is_type(node, "pciex")) { in of_create_pci_dev()
219 /* a PCI-PCI bridge */ in of_create_pci_dev()
220 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE; in of_create_pci_dev()
221 dev->rom_base_reg = PCI_ROM_ADDRESS1; in of_create_pci_dev()
222 set_pcie_hotplug_bridge(dev); in of_create_pci_dev()
224 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS; in of_create_pci_dev()
226 dev->hdr_type = PCI_HEADER_TYPE_NORMAL; in of_create_pci_dev()
227 dev->rom_base_reg = PCI_ROM_ADDRESS; in of_create_pci_dev()
229 dev->irq = 0; in of_create_pci_dev()
232 of_pci_parse_addrs(node, dev); in of_create_pci_dev()
236 pci_device_add(dev, bus); in of_create_pci_dev()
238 return dev; in of_create_pci_dev()
243 * of_scan_pci_bridge - Set up a PCI bridge and scan for child nodes
244 * @dev: pci_dev structure for the bridge
246 * of_scan_bus() calls this routine for each PCI bridge that it finds, and
250 void of_scan_pci_bridge(struct pci_dev *dev) in of_scan_pci_bridge() argument
252 struct device_node *node = dev->dev.of_node; in of_scan_pci_bridge()
264 /* parse bus-range property */ in of_scan_pci_bridge()
265 busrange = of_get_property(node, "bus-range", &len); in of_scan_pci_bridge()
267 printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %pOF\n", in of_scan_pci_bridge()
273 printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %pOF\n", in of_scan_pci_bridge()
278 bus = pci_find_bus(pci_domain_nr(dev->bus), in of_scan_pci_bridge()
281 bus = pci_add_new_bus(dev->bus, dev, in of_scan_pci_bridge()
284 printk(KERN_ERR "Failed to create pci bus for %pOF\n", in of_scan_pci_bridge()
290 bus->primary = dev->bus->number; in of_scan_pci_bridge()
293 bus->bridge_ctl = 0; in of_scan_pci_bridge()
296 /* PCI #address-cells == 3 and #size-cells == 2 always */ in of_scan_pci_bridge()
297 res = &dev->resource[PCI_BRIDGE_RESOURCES]; in of_scan_pci_bridge()
298 for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) { in of_scan_pci_bridge()
299 res->flags = 0; in of_scan_pci_bridge()
300 bus->resource[i] = res; in of_scan_pci_bridge()
304 for (; len >= 32; len -= 32, ranges += 8) { in of_scan_pci_bridge()
310 res = bus->resource[0]; in of_scan_pci_bridge()
311 if (res->flags) { in of_scan_pci_bridge()
312 printk(KERN_ERR "PCI: ignoring extra I/O range" in of_scan_pci_bridge()
317 if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) { in of_scan_pci_bridge()
318 printk(KERN_ERR "PCI: too many memory ranges" in of_scan_pci_bridge()
322 res = bus->resource[i]; in of_scan_pci_bridge()
325 res->flags = flags; in of_scan_pci_bridge()
327 region.end = region.start + size - 1; in of_scan_pci_bridge()
328 pcibios_bus_to_resource(dev->bus, res, ®ion); in of_scan_pci_bridge()
330 sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus), in of_scan_pci_bridge()
331 bus->number); in of_scan_pci_bridge()
332 pr_debug(" bus name: %s\n", bus->name); in of_scan_pci_bridge()
337 if (phb->controller_ops.probe_mode) in of_scan_pci_bridge()
338 mode = phb->controller_ops.probe_mode(bus); in of_scan_pci_bridge()
351 struct pci_dev *dev = NULL; in of_scan_pci_dev() local
367 /* Check if the PCI device is already there */ in of_scan_pci_dev()
368 dev = pci_get_slot(bus, devfn); in of_scan_pci_dev()
369 if (dev) { in of_scan_pci_dev()
370 pci_dev_put(dev); in of_scan_pci_dev()
371 return dev; in of_scan_pci_dev()
376 if (edev && (edev->mode & EEH_DEV_REMOVED)) in of_scan_pci_dev()
381 dev = of_create_pci_dev(dn, bus, devfn); in of_scan_pci_dev()
382 if (!dev) in of_scan_pci_dev()
385 pr_debug(" dev header type: %x\n", dev->hdr_type); in of_scan_pci_dev()
386 return dev; in of_scan_pci_dev()
390 * __of_scan_bus - given a PCI bus node, setup bus and scan for child devices
391 * @node: device tree node for the PCI bus
392 * @bus: pci_bus structure for the PCI bus
399 struct pci_dev *dev; in __of_scan_bus() local
402 node, bus->number); in __of_scan_bus()
406 dev = of_scan_pci_dev(bus, child); in __of_scan_bus()
407 if (!dev) in __of_scan_bus()
409 pr_debug(" dev header type: %x\n", dev->hdr_type); in __of_scan_bus()
419 for_each_pci_bridge(dev, bus) in __of_scan_bus()
420 of_scan_pci_bridge(dev); in __of_scan_bus()
424 * of_scan_bus - given a PCI bus node, setup bus and scan for child devices
425 * @node: device tree node for the PCI bus
426 * @bus: pci_bus structure for the PCI bus
435 * of_rescan_bus - given a PCI bus node, scan for child devices
436 * @node: device tree node for the PCI bus
437 * @bus: pci_bus structure for the PCI bus