xref: /openbmc/linux/drivers/video/aperture.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
17283f862SThomas Zimmermann // SPDX-License-Identifier: MIT
27283f862SThomas Zimmermann 
37283f862SThomas Zimmermann #include <linux/aperture.h>
47283f862SThomas Zimmermann #include <linux/device.h>
57283f862SThomas Zimmermann #include <linux/list.h>
67283f862SThomas Zimmermann #include <linux/mutex.h>
77283f862SThomas Zimmermann #include <linux/pci.h>
87283f862SThomas Zimmermann #include <linux/platform_device.h>
97283f862SThomas Zimmermann #include <linux/slab.h>
105e013761SThomas Zimmermann #include <linux/sysfb.h>
117283f862SThomas Zimmermann #include <linux/types.h>
127283f862SThomas Zimmermann #include <linux/vgaarb.h>
137283f862SThomas Zimmermann 
14482b1c7dSThomas Zimmermann #include <video/vga.h>
15482b1c7dSThomas Zimmermann 
167283f862SThomas Zimmermann /**
177283f862SThomas Zimmermann  * DOC: overview
187283f862SThomas Zimmermann  *
197283f862SThomas Zimmermann  * A graphics device might be supported by different drivers, but only one
207283f862SThomas Zimmermann  * driver can be active at any given time. Many systems load a generic
217283f862SThomas Zimmermann  * graphics drivers, such as EFI-GOP or VESA, early during the boot process.
227283f862SThomas Zimmermann  * During later boot stages, they replace the generic driver with a dedicated,
23*92ba6734SSui Jingfeng  * hardware-specific driver. To take over the device, the dedicated driver
247283f862SThomas Zimmermann  * first has to remove the generic driver. Aperture functions manage
257283f862SThomas Zimmermann  * ownership of framebuffer memory and hand-over between drivers.
267283f862SThomas Zimmermann  *
277283f862SThomas Zimmermann  * Graphics drivers should call aperture_remove_conflicting_devices()
287283f862SThomas Zimmermann  * at the top of their probe function. The function removes any generic
297283f862SThomas Zimmermann  * driver that is currently associated with the given framebuffer memory.
307283f862SThomas Zimmermann  * An example for a graphics device on the platform bus is shown below.
317283f862SThomas Zimmermann  *
327283f862SThomas Zimmermann  * .. code-block:: c
337283f862SThomas Zimmermann  *
347283f862SThomas Zimmermann  *	static int example_probe(struct platform_device *pdev)
357283f862SThomas Zimmermann  *	{
367283f862SThomas Zimmermann  *		struct resource *mem;
377283f862SThomas Zimmermann  *		resource_size_t base, size;
387283f862SThomas Zimmermann  *		int ret;
397283f862SThomas Zimmermann  *
407283f862SThomas Zimmermann  *		mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
417283f862SThomas Zimmermann  *		if (!mem)
427283f862SThomas Zimmermann  *			return -ENODEV;
437283f862SThomas Zimmermann  *		base = mem->start;
447283f862SThomas Zimmermann  *		size = resource_size(mem);
457283f862SThomas Zimmermann  *
467283f862SThomas Zimmermann  *		ret = aperture_remove_conflicting_devices(base, size, "example");
477283f862SThomas Zimmermann  *		if (ret)
487283f862SThomas Zimmermann  *			return ret;
497283f862SThomas Zimmermann  *
507283f862SThomas Zimmermann  *		// Initialize the hardware
517283f862SThomas Zimmermann  *		...
527283f862SThomas Zimmermann  *
537283f862SThomas Zimmermann  *		return 0;
547283f862SThomas Zimmermann  *	}
557283f862SThomas Zimmermann  *
567283f862SThomas Zimmermann  *	static const struct platform_driver example_driver = {
577283f862SThomas Zimmermann  *		.probe = example_probe,
587283f862SThomas Zimmermann  *		...
597283f862SThomas Zimmermann  *	};
607283f862SThomas Zimmermann  *
617283f862SThomas Zimmermann  * The given example reads the platform device's I/O-memory range from the
627283f862SThomas Zimmermann  * device instance. An active framebuffer will be located within this range.
637283f862SThomas Zimmermann  * The call to aperture_remove_conflicting_devices() releases drivers that
647283f862SThomas Zimmermann  * have previously claimed ownership of the range and are currently driving
657283f862SThomas Zimmermann  * output on the framebuffer. If successful, the new driver can take over
667283f862SThomas Zimmermann  * the device.
677283f862SThomas Zimmermann  *
687283f862SThomas Zimmermann  * While the given example uses a platform device, the aperture helpers work
697283f862SThomas Zimmermann  * with every bus that has an addressable framebuffer. In the case of PCI,
707283f862SThomas Zimmermann  * device drivers can also call aperture_remove_conflicting_pci_devices() and
717283f862SThomas Zimmermann  * let the function detect the apertures automatically. Device drivers without
727283f862SThomas Zimmermann  * knowledge of the framebuffer's location can call
737283f862SThomas Zimmermann  * aperture_remove_all_conflicting_devices(), which removes all known devices.
747283f862SThomas Zimmermann  *
757283f862SThomas Zimmermann  * Drivers that are susceptible to being removed by other drivers, such as
767283f862SThomas Zimmermann  * generic EFI or VESA drivers, have to register themselves as owners of their
777283f862SThomas Zimmermann  * framebuffer apertures. Ownership of the framebuffer memory is achieved
787283f862SThomas Zimmermann  * by calling devm_aperture_acquire_for_platform_device(). If successful, the
797283f862SThomas Zimmermann  * driver is the owner of the framebuffer range. The function fails if the
807283f862SThomas Zimmermann  * framebuffer is already owned by another driver. See below for an example.
817283f862SThomas Zimmermann  *
827283f862SThomas Zimmermann  * .. code-block:: c
837283f862SThomas Zimmermann  *
847283f862SThomas Zimmermann  *	static int generic_probe(struct platform_device *pdev)
857283f862SThomas Zimmermann  *	{
867283f862SThomas Zimmermann  *		struct resource *mem;
877283f862SThomas Zimmermann  *		resource_size_t base, size;
887283f862SThomas Zimmermann  *
897283f862SThomas Zimmermann  *		mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
907283f862SThomas Zimmermann  *		if (!mem)
917283f862SThomas Zimmermann  *			return -ENODEV;
927283f862SThomas Zimmermann  *		base = mem->start;
937283f862SThomas Zimmermann  *		size = resource_size(mem);
947283f862SThomas Zimmermann  *
957283f862SThomas Zimmermann  *		ret = devm_aperture_acquire_for_platform_device(pdev, base, size);
967283f862SThomas Zimmermann  *		if (ret)
977283f862SThomas Zimmermann  *			return ret;
987283f862SThomas Zimmermann  *
997283f862SThomas Zimmermann  *		// Initialize the hardware
1007283f862SThomas Zimmermann  *		...
1017283f862SThomas Zimmermann  *
1027283f862SThomas Zimmermann  *		return 0;
1037283f862SThomas Zimmermann  *	}
1047283f862SThomas Zimmermann  *
1057283f862SThomas Zimmermann  *	static int generic_remove(struct platform_device *)
1067283f862SThomas Zimmermann  *	{
1077283f862SThomas Zimmermann  *		// Hot-unplug the device
1087283f862SThomas Zimmermann  *		...
1097283f862SThomas Zimmermann  *
1107283f862SThomas Zimmermann  *		return 0;
1117283f862SThomas Zimmermann  *	}
1127283f862SThomas Zimmermann  *
1137283f862SThomas Zimmermann  *	static const struct platform_driver generic_driver = {
1147283f862SThomas Zimmermann  *		.probe = generic_probe,
1157283f862SThomas Zimmermann  *		.remove = generic_remove,
1167283f862SThomas Zimmermann  *		...
1177283f862SThomas Zimmermann  *	};
1187283f862SThomas Zimmermann  *
1197283f862SThomas Zimmermann  * The similar to the previous example, the generic driver claims ownership
1207283f862SThomas Zimmermann  * of the framebuffer memory from its probe function. This will fail if the
1217283f862SThomas Zimmermann  * memory range, or parts of it, is already owned by another driver.
1227283f862SThomas Zimmermann  *
1237283f862SThomas Zimmermann  * If successful, the generic driver is now subject to forced removal by
1247283f862SThomas Zimmermann  * another driver. This only works for platform drivers that support hot
1257283f862SThomas Zimmermann  * unplugging. When a driver calls aperture_remove_conflicting_devices()
1267283f862SThomas Zimmermann  * et al for the registered framebuffer range, the aperture helpers call
1277283f862SThomas Zimmermann  * platform_device_unregister() and the generic driver unloads itself. The
1287283f862SThomas Zimmermann  * generic driver also has to provide a remove function to make this work.
1297283f862SThomas Zimmermann  * Once hot unplugged from hardware, it may not access the device's
1307283f862SThomas Zimmermann  * registers, framebuffer memory, ROM, etc afterwards.
1317283f862SThomas Zimmermann  */
1327283f862SThomas Zimmermann 
1337283f862SThomas Zimmermann struct aperture_range {
1347283f862SThomas Zimmermann 	struct device *dev;
1357283f862SThomas Zimmermann 	resource_size_t base;
1367283f862SThomas Zimmermann 	resource_size_t size;
1377283f862SThomas Zimmermann 	struct list_head lh;
1387283f862SThomas Zimmermann 	void (*detach)(struct device *dev);
1397283f862SThomas Zimmermann };
1407283f862SThomas Zimmermann 
1417283f862SThomas Zimmermann static LIST_HEAD(apertures);
1427283f862SThomas Zimmermann static DEFINE_MUTEX(apertures_lock);
1437283f862SThomas Zimmermann 
overlap(resource_size_t base1,resource_size_t end1,resource_size_t base2,resource_size_t end2)1447283f862SThomas Zimmermann static bool overlap(resource_size_t base1, resource_size_t end1,
1457283f862SThomas Zimmermann 		    resource_size_t base2, resource_size_t end2)
1467283f862SThomas Zimmermann {
1477283f862SThomas Zimmermann 	return (base1 < end2) && (end1 > base2);
1487283f862SThomas Zimmermann }
1497283f862SThomas Zimmermann 
devm_aperture_acquire_release(void * data)1507283f862SThomas Zimmermann static void devm_aperture_acquire_release(void *data)
1517283f862SThomas Zimmermann {
1527283f862SThomas Zimmermann 	struct aperture_range *ap = data;
1537283f862SThomas Zimmermann 	bool detached = !ap->dev;
1547283f862SThomas Zimmermann 
1557283f862SThomas Zimmermann 	if (detached)
1567283f862SThomas Zimmermann 		return;
1577283f862SThomas Zimmermann 
1587283f862SThomas Zimmermann 	mutex_lock(&apertures_lock);
1597283f862SThomas Zimmermann 	list_del(&ap->lh);
1607283f862SThomas Zimmermann 	mutex_unlock(&apertures_lock);
1617283f862SThomas Zimmermann }
1627283f862SThomas Zimmermann 
devm_aperture_acquire(struct device * dev,resource_size_t base,resource_size_t size,void (* detach)(struct device *))1637283f862SThomas Zimmermann static int devm_aperture_acquire(struct device *dev,
1647283f862SThomas Zimmermann 				 resource_size_t base, resource_size_t size,
1657283f862SThomas Zimmermann 				 void (*detach)(struct device *))
1667283f862SThomas Zimmermann {
1677283f862SThomas Zimmermann 	size_t end = base + size;
1687283f862SThomas Zimmermann 	struct list_head *pos;
1697283f862SThomas Zimmermann 	struct aperture_range *ap;
1707283f862SThomas Zimmermann 
1717283f862SThomas Zimmermann 	mutex_lock(&apertures_lock);
1727283f862SThomas Zimmermann 
1737283f862SThomas Zimmermann 	list_for_each(pos, &apertures) {
1747283f862SThomas Zimmermann 		ap = container_of(pos, struct aperture_range, lh);
1757283f862SThomas Zimmermann 		if (overlap(base, end, ap->base, ap->base + ap->size)) {
1767283f862SThomas Zimmermann 			mutex_unlock(&apertures_lock);
1777283f862SThomas Zimmermann 			return -EBUSY;
1787283f862SThomas Zimmermann 		}
1797283f862SThomas Zimmermann 	}
1807283f862SThomas Zimmermann 
1817283f862SThomas Zimmermann 	ap = devm_kzalloc(dev, sizeof(*ap), GFP_KERNEL);
1827283f862SThomas Zimmermann 	if (!ap) {
1837283f862SThomas Zimmermann 		mutex_unlock(&apertures_lock);
1847283f862SThomas Zimmermann 		return -ENOMEM;
1857283f862SThomas Zimmermann 	}
1867283f862SThomas Zimmermann 
1877283f862SThomas Zimmermann 	ap->dev = dev;
1887283f862SThomas Zimmermann 	ap->base = base;
1897283f862SThomas Zimmermann 	ap->size = size;
1907283f862SThomas Zimmermann 	ap->detach = detach;
1917283f862SThomas Zimmermann 	INIT_LIST_HEAD(&ap->lh);
1927283f862SThomas Zimmermann 
1937283f862SThomas Zimmermann 	list_add(&ap->lh, &apertures);
1947283f862SThomas Zimmermann 
1957283f862SThomas Zimmermann 	mutex_unlock(&apertures_lock);
1967283f862SThomas Zimmermann 
1977283f862SThomas Zimmermann 	return devm_add_action_or_reset(dev, devm_aperture_acquire_release, ap);
1987283f862SThomas Zimmermann }
1997283f862SThomas Zimmermann 
aperture_detach_platform_device(struct device * dev)2007283f862SThomas Zimmermann static void aperture_detach_platform_device(struct device *dev)
2017283f862SThomas Zimmermann {
2027283f862SThomas Zimmermann 	struct platform_device *pdev = to_platform_device(dev);
2037283f862SThomas Zimmermann 
2047283f862SThomas Zimmermann 	/*
2057283f862SThomas Zimmermann 	 * Remove the device from the device hierarchy. This is the right thing
206*92ba6734SSui Jingfeng 	 * to do for firmware-based fb drivers, such as EFI, VESA or VGA. After
2077283f862SThomas Zimmermann 	 * the new driver takes over the hardware, the firmware device's state
2087283f862SThomas Zimmermann 	 * will be lost.
2097283f862SThomas Zimmermann 	 *
2107283f862SThomas Zimmermann 	 * For non-platform devices, a new callback would be required.
2117283f862SThomas Zimmermann 	 *
2127283f862SThomas Zimmermann 	 * If the aperture helpers ever need to handle native drivers, this call
2137283f862SThomas Zimmermann 	 * would only have to unplug the DRM device, so that the hardware device
2147283f862SThomas Zimmermann 	 * stays around after detachment.
2157283f862SThomas Zimmermann 	 */
2167283f862SThomas Zimmermann 	platform_device_unregister(pdev);
2177283f862SThomas Zimmermann }
2187283f862SThomas Zimmermann 
2197283f862SThomas Zimmermann /**
2207283f862SThomas Zimmermann  * devm_aperture_acquire_for_platform_device - Acquires ownership of an aperture
2217283f862SThomas Zimmermann  *                                             on behalf of a platform device.
2227283f862SThomas Zimmermann  * @pdev:	the platform device to own the aperture
2237283f862SThomas Zimmermann  * @base:	the aperture's byte offset in physical memory
2247283f862SThomas Zimmermann  * @size:	the aperture size in bytes
2257283f862SThomas Zimmermann  *
2267283f862SThomas Zimmermann  * Installs the given device as the new owner of the aperture. The function
2277283f862SThomas Zimmermann  * expects the aperture to be provided by a platform device. If another
2287283f862SThomas Zimmermann  * driver takes over ownership of the aperture, aperture helpers will then
2297283f862SThomas Zimmermann  * unregister the platform device automatically. All acquired apertures are
2307283f862SThomas Zimmermann  * released automatically when the underlying device goes away.
2317283f862SThomas Zimmermann  *
2327283f862SThomas Zimmermann  * The function fails if the aperture, or parts of it, is currently
2337283f862SThomas Zimmermann  * owned by another device. To evict current owners, callers should use
2347283f862SThomas Zimmermann  * remove_conflicting_devices() et al. before calling this function.
2357283f862SThomas Zimmermann  *
2367283f862SThomas Zimmermann  * Returns:
2377283f862SThomas Zimmermann  * 0 on success, or a negative errno value otherwise.
2387283f862SThomas Zimmermann  */
devm_aperture_acquire_for_platform_device(struct platform_device * pdev,resource_size_t base,resource_size_t size)2397283f862SThomas Zimmermann int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
2407283f862SThomas Zimmermann 					      resource_size_t base,
2417283f862SThomas Zimmermann 					      resource_size_t size)
2427283f862SThomas Zimmermann {
2437283f862SThomas Zimmermann 	return devm_aperture_acquire(&pdev->dev, base, size, aperture_detach_platform_device);
2447283f862SThomas Zimmermann }
2457283f862SThomas Zimmermann EXPORT_SYMBOL(devm_aperture_acquire_for_platform_device);
2467283f862SThomas Zimmermann 
aperture_detach_devices(resource_size_t base,resource_size_t size)2477283f862SThomas Zimmermann static void aperture_detach_devices(resource_size_t base, resource_size_t size)
2487283f862SThomas Zimmermann {
2497283f862SThomas Zimmermann 	resource_size_t end = base + size;
2507283f862SThomas Zimmermann 	struct list_head *pos, *n;
2517283f862SThomas Zimmermann 
2527283f862SThomas Zimmermann 	mutex_lock(&apertures_lock);
2537283f862SThomas Zimmermann 
2547283f862SThomas Zimmermann 	list_for_each_safe(pos, n, &apertures) {
2557283f862SThomas Zimmermann 		struct aperture_range *ap = container_of(pos, struct aperture_range, lh);
2567283f862SThomas Zimmermann 		struct device *dev = ap->dev;
2577283f862SThomas Zimmermann 
2587283f862SThomas Zimmermann 		if (WARN_ON_ONCE(!dev))
2597283f862SThomas Zimmermann 			continue;
2607283f862SThomas Zimmermann 
2617283f862SThomas Zimmermann 		if (!overlap(base, end, ap->base, ap->base + ap->size))
2627283f862SThomas Zimmermann 			continue;
2637283f862SThomas Zimmermann 
2647283f862SThomas Zimmermann 		ap->dev = NULL; /* detach from device */
2657283f862SThomas Zimmermann 		list_del(&ap->lh);
2667283f862SThomas Zimmermann 
2677283f862SThomas Zimmermann 		ap->detach(dev);
2687283f862SThomas Zimmermann 	}
2697283f862SThomas Zimmermann 
2707283f862SThomas Zimmermann 	mutex_unlock(&apertures_lock);
2717283f862SThomas Zimmermann }
2727283f862SThomas Zimmermann 
2737283f862SThomas Zimmermann /**
2747283f862SThomas Zimmermann  * aperture_remove_conflicting_devices - remove devices in the given range
2757283f862SThomas Zimmermann  * @base: the aperture's base address in physical memory
2767283f862SThomas Zimmermann  * @size: aperture size in bytes
2777283f862SThomas Zimmermann  * @name: a descriptive name of the requesting driver
2787283f862SThomas Zimmermann  *
2797283f862SThomas Zimmermann  * This function removes devices that own apertures within @base and @size.
2807283f862SThomas Zimmermann  *
2817283f862SThomas Zimmermann  * Returns:
2827283f862SThomas Zimmermann  * 0 on success, or a negative errno code otherwise
2837283f862SThomas Zimmermann  */
aperture_remove_conflicting_devices(resource_size_t base,resource_size_t size,const char * name)2847283f862SThomas Zimmermann int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
2857283f862SThomas Zimmermann 					const char *name)
2867283f862SThomas Zimmermann {
2877283f862SThomas Zimmermann 	/*
2885e013761SThomas Zimmermann 	 * If a driver asked to unregister a platform device registered by
2895e013761SThomas Zimmermann 	 * sysfb, then can be assumed that this is a driver for a display
2905e013761SThomas Zimmermann 	 * that is set up by the system firmware and has a generic driver.
2915e013761SThomas Zimmermann 	 *
2925e013761SThomas Zimmermann 	 * Drivers for devices that don't have a generic driver will never
2935e013761SThomas Zimmermann 	 * ask for this, so let's assume that a real driver for the display
2945e013761SThomas Zimmermann 	 * was already probed and prevent sysfb to register devices later.
2955e013761SThomas Zimmermann 	 */
2965e013761SThomas Zimmermann 	sysfb_disable();
2975e013761SThomas Zimmermann 
2985e013761SThomas Zimmermann 	aperture_detach_devices(base, size);
299482b1c7dSThomas Zimmermann 
300482b1c7dSThomas Zimmermann 	return 0;
301482b1c7dSThomas Zimmermann }
302482b1c7dSThomas Zimmermann EXPORT_SYMBOL(aperture_remove_conflicting_devices);
303482b1c7dSThomas Zimmermann 
304482b1c7dSThomas Zimmermann /**
305482b1c7dSThomas Zimmermann  * __aperture_remove_legacy_vga_devices - remove legacy VGA devices of a PCI devices
306482b1c7dSThomas Zimmermann  * @pdev: PCI device
307482b1c7dSThomas Zimmermann  *
308482b1c7dSThomas Zimmermann  * This function removes VGA devices provided by @pdev, such as a VGA
3097283f862SThomas Zimmermann  * framebuffer or a console. This is useful if you have a VGA-compatible
3107283f862SThomas Zimmermann  * PCI graphics device with framebuffers in non-BAR locations. Drivers
3117283f862SThomas Zimmermann  * should acquire ownership of those memory areas and afterwards call
3127283f862SThomas Zimmermann  * this helper to release remaining VGA devices.
3137283f862SThomas Zimmermann  *
3147283f862SThomas Zimmermann  * If your hardware has its framebuffers accessible via PCI BARS, use
3157283f862SThomas Zimmermann  * aperture_remove_conflicting_pci_devices() instead. The function will
3167283f862SThomas Zimmermann  * release any VGA devices automatically.
3177283f862SThomas Zimmermann  *
3187283f862SThomas Zimmermann  * WARNING: Apparently we must remove graphics drivers before calling
3197283f862SThomas Zimmermann  *          this helper. Otherwise the vga fbdev driver falls over if
3207283f862SThomas Zimmermann  *          we have vgacon configured.
3217283f862SThomas Zimmermann  *
3227283f862SThomas Zimmermann  * Returns:
3237283f862SThomas Zimmermann  * 0 on success, or a negative errno code otherwise
3247283f862SThomas Zimmermann  */
__aperture_remove_legacy_vga_devices(struct pci_dev * pdev)3257283f862SThomas Zimmermann int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev)
3267283f862SThomas Zimmermann {
3279d69ef18SThomas Zimmermann 	/* VGA framebuffer */
3287283f862SThomas Zimmermann 	aperture_detach_devices(VGA_FB_PHYS_BASE, VGA_FB_PHYS_SIZE);
3297283f862SThomas Zimmermann 
3307283f862SThomas Zimmermann 	/* VGA textmode console */
3319d69ef18SThomas Zimmermann 	return vga_remove_vgacon(pdev);
3329d69ef18SThomas Zimmermann }
3339d69ef18SThomas Zimmermann EXPORT_SYMBOL(__aperture_remove_legacy_vga_devices);
3349d69ef18SThomas Zimmermann 
3359d69ef18SThomas Zimmermann /**
3369d69ef18SThomas Zimmermann  * aperture_remove_conflicting_pci_devices - remove existing framebuffers for PCI devices
3379d69ef18SThomas Zimmermann  * @pdev: PCI device
3389d69ef18SThomas Zimmermann  * @name: a descriptive name of the requesting driver
3399d69ef18SThomas Zimmermann  *
3409d69ef18SThomas Zimmermann  * This function removes devices that own apertures within any of @pdev's
3419d69ef18SThomas Zimmermann  * memory bars. The function assumes that PCI device with shadowed ROM
3429d69ef18SThomas Zimmermann  * drives a primary display and therefore kicks out vga16fb as well.
3439d69ef18SThomas Zimmermann  *
344e0ba1a39SMichał Mirosław  * Returns:
3459d69ef18SThomas Zimmermann  * 0 on success, or a negative errno code otherwise
3467283f862SThomas Zimmermann  */
aperture_remove_conflicting_pci_devices(struct pci_dev * pdev,const char * name)3477283f862SThomas Zimmermann int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name)
3487283f862SThomas Zimmermann {
3497283f862SThomas Zimmermann 	bool primary = false;
3507283f862SThomas Zimmermann 	resource_size_t base, size;
3517283f862SThomas Zimmermann 	int bar, ret = 0;
3527283f862SThomas Zimmermann 
3537283f862SThomas Zimmermann 	if (pdev == vga_default_device())
3547283f862SThomas Zimmermann 		primary = true;
3557283f862SThomas Zimmermann 
3567283f862SThomas Zimmermann 	if (primary)
3577283f862SThomas Zimmermann 		sysfb_disable();
358 
359 	for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
360 		if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
361 			continue;
362 
363 		base = pci_resource_start(pdev, bar);
364 		size = pci_resource_len(pdev, bar);
365 		aperture_detach_devices(base, size);
366 	}
367 
368 	/*
369 	 * If this is the primary adapter, there could be a VGA device
370 	 * that consumes the VGA framebuffer I/O range. Remove this
371 	 * device as well.
372 	 */
373 	if (primary)
374 		ret = __aperture_remove_legacy_vga_devices(pdev);
375 
376 	return ret;
377 
378 }
379 EXPORT_SYMBOL(aperture_remove_conflicting_pci_devices);
380