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.
52 if (!zdev->has_resources) { in zpci_bus_prepare_device()
55 if (zdev->bars[i].res) in zpci_bus_prepare_device()
56 pci_bus_add_resource(zdev->zbus->bus, zdev->bars[i].res, 0); in zpci_bus_prepare_device()
63 /* zpci_bus_scan_device - Scan a single device adding it to the PCI core
66 * Scans the PCI function making it available to the common PCI code.
79 pdev = pci_scan_single_device(zdev->zbus->bus, zdev->devfn); in zpci_bus_scan_device()
81 return -ENODEV; in zpci_bus_scan_device()
90 /* zpci_bus_remove_device - Removes the given zdev from the PCI core
91 * @zdev: the zdev to be removed from the PCI core
96 * API but is removed from the common code PCI bus, making it
101 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_remove_device()
104 if (!zdev->zbus->bus) in zpci_bus_remove_device()
107 pdev = pci_get_slot(zbus->bus, zdev->devfn); in zpci_bus_remove_device()
110 pdev->error_state = pci_channel_io_perm_failure; in zpci_bus_remove_device()
111 if (pdev->is_virtfn) { in zpci_bus_remove_device()
112 zpci_iov_remove_virtfn(pdev, zdev->vfn); in zpci_bus_remove_device()
123 /* zpci_bus_scan_bus - Scan all configured zPCI functions on the bus
126 * Enables and scans all PCI functions on the bus making them available to the
127 * common PCI code. If a PCI function fails to be initialized an error will be
138 zdev = zbus->function[devfn]; in zpci_bus_scan_bus()
139 if (zdev && zdev->state == ZPCI_FN_STATE_CONFIGURED) { in zpci_bus_scan_bus()
142 ret = -EIO; in zpci_bus_scan_bus()
147 pci_scan_child_bus(zbus->bus); in zpci_bus_scan_bus()
148 pci_bus_add_devices(zbus->bus); in zpci_bus_scan_bus()
154 /* zpci_bus_scan_busses - Scan all registered busses
171 /* zpci_bus_create_pci_bus - Create the PCI bus associated with this zbus
173 * @fr: PCI root function that will determine the bus's domain, and bus speeed
174 * @ops: the pci operations
176 * The PCI function @fr determines the domain (its UID), multifunction property
184 int domain; in zpci_bus_create_pci_bus() local
186 domain = zpci_alloc_domain((u16)fr->uid); in zpci_bus_create_pci_bus()
187 if (domain < 0) in zpci_bus_create_pci_bus()
188 return domain; in zpci_bus_create_pci_bus()
190 zbus->domain_nr = domain; in zpci_bus_create_pci_bus()
191 zbus->multifunction = fr->rid_available; in zpci_bus_create_pci_bus()
192 zbus->max_bus_speed = fr->max_bus_speed; in zpci_bus_create_pci_bus()
195 * Note that the zbus->resources are taken over and zbus->resources in zpci_bus_create_pci_bus()
198 bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources); in zpci_bus_create_pci_bus()
200 zpci_free_domain(zbus->domain_nr); in zpci_bus_create_pci_bus()
201 return -EFAULT; in zpci_bus_create_pci_bus()
204 zbus->bus = bus; in zpci_bus_create_pci_bus()
213 if (zbus->bus) { in zpci_bus_release()
215 pci_stop_root_bus(zbus->bus); in zpci_bus_release()
217 zpci_free_domain(zbus->domain_nr); in zpci_bus_release()
218 pci_free_resource_list(&zbus->resources); in zpci_bus_release()
220 pci_remove_root_bus(zbus->bus); in zpci_bus_release()
225 list_del(&zbus->bus_next); in zpci_bus_release()
232 kref_put(&zbus->kref, zpci_bus_release); in zpci_bus_put()
241 if (pchid == zbus->pchid) { in zpci_bus_get()
242 kref_get(&zbus->kref); in zpci_bus_get()
260 zbus->pchid = pchid; in zpci_bus_alloc()
261 INIT_LIST_HEAD(&zbus->bus_next); in zpci_bus_alloc()
263 list_add_tail(&zbus->bus_next, &zbus_list); in zpci_bus_alloc()
266 kref_init(&zbus->kref); in zpci_bus_alloc()
267 INIT_LIST_HEAD(&zbus->resources); in zpci_bus_alloc()
269 zbus->bus_resource.start = 0; in zpci_bus_alloc()
270 zbus->bus_resource.end = ZPCI_BUS_NR; in zpci_bus_alloc()
271 zbus->bus_resource.flags = IORESOURCE_BUS; in zpci_bus_alloc()
272 pci_add_resource(&zbus->resources, &zbus->bus_resource); in zpci_bus_alloc()
282 * With pdev->no_vf_scan the common PCI probing code does not in pcibios_bus_add_device()
285 if (zdev->vfn) { in pcibios_bus_add_device()
286 zpci_iov_setup_virtfn(zdev->zbus, pdev, zdev->vfn); in pcibios_bus_add_device()
287 pdev->no_command_memory = 1; in pcibios_bus_add_device()
293 int rc = -EINVAL; in zpci_bus_add_device()
295 if (zbus->function[zdev->devfn]) { in zpci_bus_add_device()
296 pr_err("devfn %04x is already assigned\n", zdev->devfn); in zpci_bus_add_device()
300 zdev->zbus = zbus; in zpci_bus_add_device()
301 zbus->function[zdev->devfn] = zdev; in zpci_bus_add_device()
304 if (zbus->multifunction && !zdev->rid_available) { in zpci_bus_add_device()
311 zdev->has_hp_slot = 1; in zpci_bus_add_device()
316 zbus->function[zdev->devfn] = NULL; in zpci_bus_add_device()
317 zdev->zbus = NULL; in zpci_bus_add_device()
318 zpci_nb_devices--; in zpci_bus_add_device()
325 int rc = -EBADF; in zpci_bus_device_register()
328 pr_warn("Adding PCI function %08x failed because the configured limit of %d is reached\n", in zpci_bus_device_register()
329 zdev->fid, ZPCI_NR_DEVICES); in zpci_bus_device_register()
330 return -ENOSPC; in zpci_bus_device_register()
333 if (zdev->devfn >= ZPCI_FUNCTIONS_PER_BUS) in zpci_bus_device_register()
334 return -EINVAL; in zpci_bus_device_register()
336 if (!s390_pci_no_rid && zdev->rid_available) in zpci_bus_device_register()
337 zbus = zpci_bus_get(zdev->pchid); in zpci_bus_device_register()
340 zbus = zpci_bus_alloc(zdev->pchid); in zpci_bus_device_register()
342 return -ENOMEM; in zpci_bus_device_register()
345 if (!zbus->bus) { in zpci_bus_device_register()
346 /* The UID of the first PCI function registered with a zpci_bus in zpci_bus_device_register()
347 * is used as the domain number for that bus. Currently there in zpci_bus_device_register()
348 * is exactly one zpci_bus per domain. in zpci_bus_device_register()
362 pr_err("Adding PCI function %08x failed\n", zdev->fid); in zpci_bus_device_register()
369 struct zpci_bus *zbus = zdev->zbus; in zpci_bus_device_unregister()
371 zpci_nb_devices--; in zpci_bus_device_unregister()
372 zbus->function[zdev->devfn] = NULL; in zpci_bus_device_unregister()