Lines Matching +full:pci +full:- +full:domain
1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/pci.h>
33 /* zpci_bus_prepare_device - Prepare a zPCI function for scanning
36 * The PCI resources for the function are set up and added to its zbus and the
38 * a PCI bus created. If an error occurs the zPCI function is not enabled.
57 if (!zdev->has_resources) { in zpci_bus_prepare_device()
60 if (zdev->bars[i].res) in zpci_bus_prepare_device()
61 pci_bus_add_resource(zdev->zbus->bus, zdev->bars[i].res, 0); in zpci_bus_prepare_device()
68 /* zpci_bus_scan_device - Scan a single device adding it to the PCI core
71 * Scans the PCI function making it available to the common PCI code.
84 pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn); in zpci_bus_scan_device()
86 return -ENODEV; in zpci_bus_scan_device()
95 /* zpci_bus_remove_device - Removes the given zdev from the PCI core
96 * @zdev: the zdev to be removed from the PCI core
101 * API but is removed from the common code PCI bus, making it
106 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_remove_device()
109 if (!zdev->zbus->bus) in zpci_bus_remove_device()
112 pdev = pci_get_slot(zbus->bus, zdev->devfn); in zpci_bus_remove_device()
115 pdev->error_state = pci_channel_io_perm_failure; in zpci_bus_remove_device()
116 if (pdev->is_virtfn) { in zpci_bus_remove_device()
117 zpci_iov_remove_virtfn(pdev, zdev->vfn); in zpci_bus_remove_device()
128 /* zpci_bus_scan_bus - Scan all configured zPCI functions on the bus
131 * Enables and scans all PCI functions on the bus making them available to the
132 * common PCI code. If a PCI function fails to be initialized an error will be
143 zdev = zbus->function[devfn]; in zpci_bus_scan_bus()
144 if (zdev && zdev->state == ZPCI_FN_STATE_CONFIGURED) { in zpci_bus_scan_bus()
147 ret = -EIO; in zpci_bus_scan_bus()
152 pci_scan_child_bus(zbus->bus); in zpci_bus_scan_bus()
153 pci_bus_add_devices(zbus->bus); in zpci_bus_scan_bus()
159 /* zpci_bus_scan_busses - Scan all registered busses
176 /* zpci_bus_create_pci_bus - Create the PCI bus associated with this zbus
178 * @fr: PCI root function that will determine the bus's domain, and bus speeed
179 * @ops: the pci operations
181 * The PCI function @fr determines the domain (its UID), multifunction property
189 int domain; in zpci_bus_create_pci_bus() local
191 domain = zpci_alloc_domain((u16)fr->uid); in zpci_bus_create_pci_bus()
192 if (domain < 0) in zpci_bus_create_pci_bus()
193 return domain; in zpci_bus_create_pci_bus()
195 zbus->domain_nr = domain; in zpci_bus_create_pci_bus()
196 zbus->multifunction = fr->rid_available; in zpci_bus_create_pci_bus()
197 zbus->max_bus_speed = fr->max_bus_speed; in zpci_bus_create_pci_bus()
200 * Note that the zbus->resources are taken over and zbus->resources in zpci_bus_create_pci_bus()
203 bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources); in zpci_bus_create_pci_bus()
205 zpci_free_domain(zbus->domain_nr); in zpci_bus_create_pci_bus()
206 return -EFAULT; in zpci_bus_create_pci_bus()
209 zbus->bus = bus; in zpci_bus_create_pci_bus()
218 if (zbus->bus) { in zpci_bus_release()
220 pci_stop_root_bus(zbus->bus); in zpci_bus_release()
222 zpci_free_domain(zbus->domain_nr); in zpci_bus_release()
223 pci_free_resource_list(&zbus->resources); in zpci_bus_release()
225 pci_remove_root_bus(zbus->bus); in zpci_bus_release()
230 list_del(&zbus->bus_next); in zpci_bus_release()
237 kref_put(&zbus->kref, zpci_bus_release); in zpci_bus_put()
246 if (pchid == zbus->pchid) { in zpci_bus_get()
247 kref_get(&zbus->kref); in zpci_bus_get()
265 zbus->pchid = pchid; in zpci_bus_alloc()
266 INIT_LIST_HEAD(&zbus->bus_next); in zpci_bus_alloc()
268 list_add_tail(&zbus->bus_next, &zbus_list); in zpci_bus_alloc()
271 kref_init(&zbus->kref); in zpci_bus_alloc()
272 INIT_LIST_HEAD(&zbus->resources); in zpci_bus_alloc()
274 zbus->bus_resource.start = 0; in zpci_bus_alloc()
275 zbus->bus_resource.end = ZPCI_BUS_NR; in zpci_bus_alloc()
276 zbus->bus_resource.flags = IORESOURCE_BUS; in zpci_bus_alloc()
277 pci_add_resource(&zbus->resources, &zbus->bus_resource); in zpci_bus_alloc()
287 * With pdev->no_vf_scan the common PCI probing code does not in pcibios_bus_add_device()
290 if (zdev->vfn) { in pcibios_bus_add_device()
291 zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn); in pcibios_bus_add_device()
292 pdev->no_command_memory = 1; in pcibios_bus_add_device()
298 int rc = -EINVAL; in zpci_bus_add_device()
300 if (zbus->function[zdev->devfn]) { in zpci_bus_add_device()
301 pr_err("devfn %04x is already assigned\n", zdev->devfn); in zpci_bus_add_device()
305 zdev->zbus = zbus; in zpci_bus_add_device()
306 zbus->function[zdev->devfn] = zdev; in zpci_bus_add_device()
309 if (zbus->multifunction && !zdev->rid_available) { in zpci_bus_add_device()
316 zdev->has_hp_slot = 1; in zpci_bus_add_device()
321 zbus->function[zdev->devfn] = NULL; in zpci_bus_add_device()
322 zdev->zbus = NULL; in zpci_bus_add_device()
323 zpci_nb_devices--; in zpci_bus_add_device()
330 int rc = -EBADF; in zpci_bus_device_register()
333 pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n", in zpci_bus_device_register()
334 zdev->fid, ZPCI_NR_DEVICES); in zpci_bus_device_register()
335 return -ENOSPC; in zpci_bus_device_register()
338 if (zdev->devfn >= ZPCI_FUNCTIONS_PER_BUS) in zpci_bus_device_register()
339 return -EINVAL; in zpci_bus_device_register()
341 if (!s390_pci_no_rid && zdev->rid_available) in zpci_bus_device_register()
342 zbus = zpci_bus_get(zdev->pchid); in zpci_bus_device_register()
345 zbus = zpci_bus_alloc(zdev->pchid); in zpci_bus_device_register()
347 return -ENOMEM; in zpci_bus_device_register()
350 if (!zbus->bus) { in zpci_bus_device_register()
351 /* The UID of the first PCI function registered with a zpci_bus in zpci_bus_device_register()
352 * is used as the domain number for that bus. Currently there in zpci_bus_device_register()
353 * is exactly one zpci_bus per domain. in zpci_bus_device_register()
367 pr_err("Adding PCI function %08x failed\n", zdev->fid); in zpci_bus_device_register()
374 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_device_unregister()
376 zpci_nb_devices--; in zpci_bus_device_unregister()
377 zbus->function[zdev->devfn] = NULL; in zpci_bus_device_unregister()