Skip to contentSkip to conversation

SimpleDRM Driver

PATCH In review David Herrmann 3 participants 15 messages Sep 1, 2013 – Oct 2, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover SimpleDRM Driver

Hi

With the upcoming 3.12 merge-window, I thought people might find themselves with nothing to do, so here's a new SimpleDRM series. Comments welcome!

This depends on the tip/x86/fb series in the x86-tip tree:
http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/log/?h=x86/fb
Which, as far as I understood, will be pushed into 3.12 by the x86 people.

Patches #1 and #2 implement the SimpleDRM driver which can replace vesafb, efifb, simplefb, vgafb and more. Just enable the CONFIG_X86_SYSFB option and you're good to go.

Patches #3 to #6 implement drm_kick_out_firmware() to make x86 drivers kick out firmware-DRM drivers instead of only fbdev via remove_conflicting_framebuffers().

I tested this based on drm-next plus the x86/fb series merged with i915 and nouveau and it worked just fine.

Regards
David

David Herrmann (6):
drm: add SimpleDRM driver
drm: simpledrm: add fbdev fallback support
drm: add helpers to kick out firmware drivers
drm: nouveau: kick out firmware drivers during probe drm/i915: use new drm_kick_out_firmware() drm/radeon: use new drm_kick_out_firmware()

 MAINTAINERS                                 |   8 +
 drivers/gpu/drm/Kconfig                     |   2 +
 drivers/gpu/drm/Makefile                    |   1 +
 drivers/gpu/drm/drm_pci.c                   |   1 +
 drivers/gpu/drm/drm_platform.c              |   1 +
 drivers/gpu/drm/drm_stub.c                  | 118 +++++++++
 drivers/gpu/drm/drm_usb.c                   |   1 +
 drivers/gpu/drm/i915/i915_dma.c             |   6 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c       |  29 ++-
 drivers/gpu/drm/radeon/radeon_drv.c         |  28 ---
 drivers/gpu/drm/radeon/radeon_kms.c         |  30 +++
 drivers/gpu/drm/simpledrm/Kconfig           |  29 +++
 drivers/gpu/drm/simpledrm/Makefile          |   4 +
 drivers/gpu/drm/simpledrm/simpledrm.h       | 112 +++++++++
 drivers/gpu/drm/simpledrm/simpledrm_drv.c   | 226 +++++++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_fbdev.c | 153 ++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_main.c  | 363 ++++++++++++++++++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_mem.c   | 242 +++++++++++++++++++
 include/drm/drmP.h                          |  26 ++
 19 files changed, 1342 insertions(+), 38 deletions(-)
 create mode 100644 drivers/gpu/drm/simpledrm/Kconfig
 create mode 100644 drivers/gpu/drm/simpledrm/Makefile
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm.h
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_drv.c
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_fbdev.c
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_main.c
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_mem.c
Signature · 1 line
1.8.4
#1 lore raw

PATCH v4 1/6 drm: add SimpleDRM driver

The SimpleDRM driver binds to simple-framebuffer devices and provides a DRM/KMS API. It provides only a single CRTC+encoder+connector combination plus one initial mode.

Userspace can create one dumb-buffer and attach it to the CRTC. Only if the buffer is destroyed, a new buffer can be created. The buffer is directly mapped into user-space, so we have only resources for a single buffer. Otherwise, shadow buffers plus damage-request would be needed.

---
 MAINTAINERS                                |   8 +
 drivers/gpu/drm/Kconfig                    |   2 +
 drivers/gpu/drm/Makefile                   |   1 +
 drivers/gpu/drm/simpledrm/Kconfig          |  18 ++
 drivers/gpu/drm/simpledrm/Makefile         |   3 +
 drivers/gpu/drm/simpledrm/simpledrm.h      |  89 ++++++++
 drivers/gpu/drm/simpledrm/simpledrm_drv.c  | 225 ++++++++++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_main.c | 328 +++++++++++++++++++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_mem.c  | 242 +++++++++++++++++++++
 9 files changed, 916 insertions(+)
 create mode 100644 drivers/gpu/drm/simpledrm/Kconfig
 create mode 100644 drivers/gpu/drm/simpledrm/Makefile
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm.h
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_drv.c
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_main.c
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_mem.c
MAINTAINERS +8 -0
index a26b10e..35c2fab 100644
@@ -7435,6 +7435,14 @@ S:	Odd Fixes
 F:	drivers/media/platform/sh_vou.c
 F:	include/media/sh_vou.h
 
+SIMPLE DRM DRIVER
+M:	David Herrmann <[email protected]>
+L:	[email protected]
+T:	git git://people.freedesktop.org/~dvdhrm/linux
+S:	Maintained
+F:	drivers/gpu/drm/simpledrm
+F:	include/linux/platform_data/simpledrm.h
+
 SIMPLE FIRMWARE INTERFACE (SFI)
 M:	Len Brown <[email protected]>
 L:	[email protected]
drivers/gpu/drm/Kconfig +2 -0
index 955555d..33c1765 100644
@@ -236,3 +236,5 @@ source "drivers/gpu/drm/tilcdc/Kconfig"
 source "drivers/gpu/drm/qxl/Kconfig"
 
 source "drivers/gpu/drm/msm/Kconfig"
+
+source "drivers/gpu/drm/simpledrm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index f089adf..fe23d6f 100644
@@ -55,4 +55,5 @@ obj-$(CONFIG_DRM_OMAP)	+= omapdrm/
 obj-$(CONFIG_DRM_TILCDC)	+= tilcdc/
 obj-$(CONFIG_DRM_QXL) += qxl/
 obj-$(CONFIG_DRM_MSM) += msm/
+obj-$(CONFIG_DRM_SIMPLEDRM) += simpledrm/
 obj-y			+= i2c/
drivers/gpu/drm/simpledrm/Kconfig new file +18 -0
new file mode 100644
index 0000000..35bcce8
@@ -0,0 +1,18 @@
+config DRM_SIMPLEDRM
+	tristate "Simple firmware framebuffer DRM driver"
+	depends on DRM && (FB_SIMPLE = n)
+	help
+	  SimpleDRM can run on all systems with pre-initialized graphics
+	  hardware. It uses a framebuffer that was initialized during
+	  firmware boot. No page-flipping, modesetting or other advanced
+	  features are available. However, other DRM drivers can be loaded
+	  later and take over from SimpleDRM if they provide real hardware
+	  support.
+
+	  SimpleDRM supports "simple-framebuffer" DeviceTree objects and
+	  compatible platform framebuffers.
+
+	  If unsure, say Y.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called simpledrm.
drivers/gpu/drm/simpledrm/Makefile new file +3 -0
new file mode 100644
index 0000000..ceb97eb
@@ -0,0 +1,3 @@
+simpledrm-y := simpledrm_drv.o simpledrm_main.o simpledrm_mem.o
+
+obj-$(CONFIG_DRM_SIMPLEDRM) := simpledrm.o
drivers/gpu/drm/simpledrm/simpledrm.h new file +89 -0

89 lines not on this page · raw message

drivers/gpu/drm/simpledrm/simpledrm_drv.c new file +225 -0

225 lines not on this page · raw message

drivers/gpu/drm/simpledrm/simpledrm_main.c new file +328 -0

328 lines not on this page · raw message

drivers/gpu/drm/simpledrm/simpledrm_mem.c new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
1.8.4
#2 lore raw

Re: [PATCH v4 1/6] drm: add SimpleDRM driver

Hi David,

Quoted 12 lines · David Herrmann

The SimpleDRM driver binds to simple-framebuffer devices and provides a DRM/KMS API. It provides only a single CRTC+encoder+connector combination plus one initial mode.

Userspace can create one dumb-buffer and attach it to the CRTC. Only if the buffer is destroyed, a new buffer can be created. The buffer is directly mapped into user-space, so we have only resources for a single buffer. Otherwise, shadow buffers plus damage-request would be needed.

---

[...]

Quoted 13 lines
drivers/gpu/drm/simpledrm/simpledrm_main.c new file +13 -0
+static int sdrm_conn_fill_modes(struct drm_connector *conn, uint32_t max_x,
+                               uint32_t max_y)
+{
+       struct sdrm_device *sdrm = conn->dev->dev_private;
+       struct drm_display_mode *mode;
+       int ret;
+
+       if (conn->force == DRM_FORCE_ON)
+               conn->status = connector_status_connected;
+       else if (conn->force)
+               conn->status = connector_status_disconnected;
+       else
+               conn->status = connector_status_connected;

drivers/gpu/drm/simpledrm/simpledrm_main.c line 120

Quoted 10 lines
drivers/gpu/drm/simpledrm/simpledrm_main.c new file +10 -0
+
+       list_for_each_entry(mode, &conn->modes, head)
+               mode->status = MODE_UNVERIFIED;
+
+       mode = drm_gtf_mode(sdrm->ddev, sdrm->fb_width, sdrm->fb_height,
+                           60, 0, 0);
+       if (mode) {
+               mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+               drm_mode_probed_add(conn, mode);
+               sdrm->mode = mode;

Should you also be setting sdrm->fb_{width,height} to mode->{v,h}display here? Otherwise, due to the rounding in drm_gtf_mode(), these values won't necessarily match (which I suppose they must?).

Cheers,

Tom

#3 lore raw

Re: [PATCH v4 1/6] drm: add SimpleDRM driver

Hi Tom

Quoted 38 lines · Tom Gundersen

Hi David,

Quoted 12 lines · David Herrmann

The SimpleDRM driver binds to simple-framebuffer devices and provides a DRM/KMS API. It provides only a single CRTC+encoder+connector combination plus one initial mode.

Userspace can create one dumb-buffer and attach it to the CRTC. Only if the buffer is destroyed, a new buffer can be created. The buffer is directly mapped into user-space, so we have only resources for a single buffer. Otherwise, shadow buffers plus damage-request would be needed.

---

[...]

Quoted 20 lines
drivers/gpu/drm/simpledrm/simpledrm_main.c new file +20 -0
+static int sdrm_conn_fill_modes(struct drm_connector *conn, uint32_t max_x,
+                               uint32_t max_y)
+{
+       struct sdrm_device *sdrm = conn->dev->dev_private;
+       struct drm_display_mode *mode;
+       int ret;
+
+       if (conn->force == DRM_FORCE_ON)
+               conn->status = connector_status_connected;
+       else if (conn->force)
+               conn->status = connector_status_disconnected;
+       else
+               conn->status = connector_status_connected;
+
+       list_for_each_entry(mode, &conn->modes, head)
+               mode->status = MODE_UNVERIFIED;
+
+       mode = drm_gtf_mode(sdrm->ddev, sdrm->fb_width, sdrm->fb_height,
+                           60, 0, 0);
+       if (mode) {
Quoted 8 lines

drivers/gpu/drm/simpledrm/simpledrm_main.c line 120

Quoted 3 lines
drivers/gpu/drm/simpledrm/simpledrm_main.c new file +3 -0
+               mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+               drm_mode_probed_add(conn, mode);
+               sdrm->mode = mode;

Should you also be setting sdrm->fb_{width,height} to mode->{v,h}display here? Otherwise, due to the rounding in drm_gtf_mode(), these values won't necessarily match (which I suppose they must?).

What the ****. I wasn't aware drm_gtf_mode() modifies the v/hdisplay values. Hm.. I will probably have to use something else then.

Thanks
David

#4 lore raw

PATCH v4 2/6 drm: simpledrm: add fbdev fallback support

In reply to David Herrmann

Create a simple fbdev device during SimpleDRM setup so legacy user-space and fbcon can use it.

---
 drivers/gpu/drm/simpledrm/Kconfig           |  11 ++
 drivers/gpu/drm/simpledrm/Makefile          |   1 +
 drivers/gpu/drm/simpledrm/simpledrm.h       |  22 ++++
 drivers/gpu/drm/simpledrm/simpledrm_fbdev.c | 153 ++++++++++++++++++++++++++++
 drivers/gpu/drm/simpledrm/simpledrm_main.c  |   2 +
 5 files changed, 189 insertions(+)
 create mode 100644 drivers/gpu/drm/simpledrm/simpledrm_fbdev.c
drivers/gpu/drm/simpledrm/Kconfig +11 -0
index 35bcce8..eef2a36 100644
@@ -12,7 +12,18 @@ config DRM_SIMPLEDRM
 	  SimpleDRM supports "simple-framebuffer" DeviceTree objects and
 	  compatible platform framebuffers.
 
+	  If fbdev support is enabled, this driver will also provide an fbdev
+	  compatibility layer.
+
 	  If unsure, say Y.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called simpledrm.
+
+config DRM_SIMPLEDRM_FBDEV
+	bool
+	depends on DRM_SIMPLEDRM && FB
+	default y
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
drivers/gpu/drm/simpledrm/Makefile +1 -0
index ceb97eb..2144787 100644
@@ -1,3 +1,4 @@
 simpledrm-y := simpledrm_drv.o simpledrm_main.o simpledrm_mem.o
+simpledrm-$(CONFIG_DRM_SIMPLEDRM_FBDEV) += simpledrm_fbdev.o
 
 obj-$(CONFIG_DRM_SIMPLEDRM) := simpledrm.o
drivers/gpu/drm/simpledrm/simpledrm.h +22 -0
index 977b344..b854981 100644
@@ -46,6 +46,9 @@ struct sdrm_device {
 	struct drm_encoder enc;
 	struct drm_connector conn;
 	struct drm_display_mode *mode;
+
+	/* fbdev */
+	struct fb_info *fbdev;
 };
 
 int sdrm_drm_load(struct drm_device *ddev, unsigned long flags);
@@ -86,4 +89,23 @@ struct sdrm_framebuffer {
 
 #define to_sdrm_fb(x) container_of(x, struct sdrm_framebuffer, base)
 
+/* simpledrm fbdev helpers */
+
+#ifdef CONFIG_DRM_SIMPLEDRM_FBDEV
+
+void sdrm_fbdev_init(struct sdrm_device *sdrm);
+void sdrm_fbdev_cleanup(struct sdrm_device *sdrm);
+
+#else /* CONFIG_DRM_SIMPLEDRM_FBDEV */
+
+static inline void sdrm_fbdev_init(struct sdrm_device *sdrm)
+{
+}
+
+static inline void sdrm_fbdev_cleanup(struct sdrm_device *sdrm)
+{
+}
+
+#endif /* CONFIG_DRM_SIMPLEDRM_FBDEV */
+
 #endif /* SDRM_DRV_H */
drivers/gpu/drm/simpledrm/simpledrm_fbdev.c new file +153 -0

153 lines not on this page · raw message

drivers/gpu/drm/simpledrm/simpledrm_main.c +2 -0
index ae507e3..497542d 100644
@@ -303,6 +303,7 @@ int sdrm_drm_load(struct drm_device *ddev, unsigned long flags)
 	if (ret)
 		goto err_cleanup;
 
+	sdrm_fbdev_init(sdrm);
 	return 0;
 
 err_cleanup:
@@ -320,6 +321,7 @@ int sdrm_drm_unload(struct drm_device *ddev)
 {
 	struct sdrm_device *sdrm = ddev->dev_private;
 
+	sdrm_fbdev_cleanup(sdrm);
 	drm_mode_config_cleanup(ddev);
 	sdrm_pdev_destroy(sdrm);
 	kfree(sdrm);
Signature · 1 line
1.8.4
#5 lore raw

PATCH v4 3/6 drm: add helpers to kick out firmware drivers

In reply to David Herrmann

If we load a real hardware DRM driver, we want all firmware drivers to be unloaded. Historically, this was done via remove_conflicting_framebuffers(), but for DRM drivers (like SimpleDRM) we need a new way.

This patch introduces DRIVER_FIRMWARE and DRM apertures to provide a quite similar way to kick out firmware DRM drivers. Additionally, unlike the fbdev equivalent, DRM firmware drivers can now query the system whether a real hardware driver is already loaded and prevent loading themselves.

Whenever a real hardware DRM driver is loaded which claims to provide the boot fw FB, we invalidate the firmware framebuffer. Otherwise, simpledrm could be loaded again, after a real hw-driver was unloaded (which is very unlikely to work, except if hw-drivers reset fw FBs during unload). Note that fbdev doesn't provide such protection against late driver probing.

---
 drivers/gpu/drm/drm_pci.c                  |   1 +
 drivers/gpu/drm/drm_platform.c             |   1 +
 drivers/gpu/drm/drm_stub.c                 | 118 +++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_usb.c                  |   1 +
 drivers/gpu/drm/simpledrm/simpledrm.h      |   1 +
 drivers/gpu/drm/simpledrm/simpledrm_drv.c  |   3 +-
 drivers/gpu/drm/simpledrm/simpledrm_main.c |  33 ++++++++
 include/drm/drmP.h                         |  26 +++++++
 8 files changed, 183 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_pci.c +1 -0
index 1f96cee..f3de4d6 100644
@@ -378,6 +378,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 	}
 
 	list_add_tail(&dev->driver_item, &driver->device_list);
+	list_add_tail(&dev->global_item, &drm_devlist);
 
 	DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
 		 driver->name, driver->major, driver->minor, driver->patchlevel,
drivers/gpu/drm/drm_platform.c +1 -0
index f7a18c6..a287429 100644
@@ -94,6 +94,7 @@ static int drm_get_platform_dev(struct platform_device *platdev,
 	}
 
 	list_add_tail(&dev->driver_item, &driver->device_list);
+	list_add_tail(&dev->global_item, &drm_devlist);
 
 	mutex_unlock(&drm_global_mutex);
 
drivers/gpu/drm/drm_stub.c +118 -0

134 lines not on this page · raw message

drivers/gpu/drm/drm_usb.c +1 -0
index 8766472..b672cf2 100644
@@ -56,6 +56,7 @@ int drm_get_usb_dev(struct usb_interface *interface,
 		goto err_g3;
 
 	list_add_tail(&dev->driver_item, &driver->device_list);
+	list_add_tail(&dev->global_item, &drm_devlist);
 
 	mutex_unlock(&drm_global_mutex);
 
drivers/gpu/drm/simpledrm/simpledrm.h +1 -0
index b854981..c093ad5 100644
@@ -53,6 +53,7 @@ struct sdrm_device {
 
 int sdrm_drm_load(struct drm_device *ddev, unsigned long flags);
 int sdrm_drm_unload(struct drm_device *ddev);
+void sdrm_drm_kick_out_firmware(struct drm_device *ddev);
 int sdrm_drm_mmap(struct file *filp, struct vm_area_struct *vma);
 int sdrm_pdev_init(struct sdrm_device *sdrm);
 void sdrm_pdev_destroy(struct sdrm_device *sdrm);
drivers/gpu/drm/simpledrm/simpledrm_drv.c +2 -1
index 8a34051..aea702c 100644
@@ -33,9 +33,10 @@ static const struct file_operations sdrm_drm_fops = {
 };
 
 static struct drm_driver sdrm_drm_driver = {
-	.driver_features = DRIVER_MODESET | DRIVER_GEM,
+	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_FIRMWARE,
 	.load = sdrm_drm_load,
 	.unload = sdrm_drm_unload,
+	.kick_out_firmware = sdrm_drm_kick_out_firmware,
 	.fops = &sdrm_drm_fops,
 
 	.gem_init_object = sdrm_gem_init_object,
drivers/gpu/drm/simpledrm/simpledrm_main.c +33 -0
index 497542d..38571c2 100644
@@ -267,6 +267,21 @@ int sdrm_drm_load(struct drm_device *ddev, unsigned long flags)
 	if (ret)
 		goto err_name;
 
+	ddev->apertures = alloc_apertures(1);
+	if (!ddev->apertures) {
+		ret = -ENOMEM;
+		goto err_pdev;
+	}
+
+	ddev->apertures->ranges[0].base = sdrm->fb_base;
+	ddev->apertures->ranges[0].size = sdrm->fb_size;
+
+	if (drm_is_firmware_used(ddev->apertures)) {
+		dev_info(ddev->dev, "firmware framebuffer is already in use\n");
+		ret = -EBUSY;
+		goto err_apert;
+	}
+
 	drm_mode_config_init(ddev);
 	ddev->mode_config.min_width = 0;
 	ddev->mode_config.min_height = 0;
@@ -308,6 +323,9 @@ int sdrm_drm_load(struct drm_device *ddev, unsigned long flags)
 
 err_cleanup:
 	drm_mode_config_cleanup(ddev);
+err_apert:
+	kfree(ddev->apertures);
+err_pdev:
 	sdrm_pdev_destroy(sdrm);
 err_name:
 	kfree(ddev->devname);
@@ -328,3 +346,18 @@ int sdrm_drm_unload(struct drm_device *ddev)
 
 	return 0;
 }
+
+void sdrm_drm_kick_out_firmware(struct drm_device *ddev)
+{
+	struct sdrm_device *sdrm = ddev->dev_private;
+
+	mutex_lock(&ddev->struct_mutex);
+
+	sdrm_fbdev_cleanup(sdrm);
+	drm_unplug_dev_locked(ddev);
+	if (sdrm->fb_obj)
+		sdrm_gem_unmap_object(sdrm->fb_obj);
+	sdrm_pdev_destroy(sdrm);
+
+	mutex_unlock(&ddev->struct_mutex);
+}
include/drm/drmP.h +26 -0
index 2907341..d197033 100644
@@ -46,6 +46,7 @@
 #include <linux/miscdevice.h>
 #include <linux/fs.h>
 #include <linux/init.h>
+#include <linux/fb.h>
 #include <linux/file.h>
 #include <linux/platform_device.h>
 #include <linux/pci.h>
@@ -146,6 +147,7 @@ int drm_err(const char *func, const char *format, ...);
 #define DRIVER_MODESET     0x2000
 #define DRIVER_PRIME       0x4000
 #define DRIVER_RENDER      0x8000
+#define DRIVER_FIRMWARE    0x10000
 
 #define DRIVER_BUS_PCI 0x1
 #define DRIVER_BUS_PLATFORM 0x2
@@ -966,6 +968,23 @@ struct drm_driver {
 			    struct drm_device *dev,
 			    uint32_t handle);
 
+	/**
+	 * kick_out_firmware - kick out firmware driver
+	 * @dev: DRM device
+	 *
+	 * Iff this driver has DRIVER_FIRMWARE set, this function is called
+	 * when a real hw-driver is loaded and claims the framebuffer memory
+	 * that is mapped by the firmware driver. This is called with the
+	 * global drm mutex held.
+	 * Drivers should unmap any memory-mappings, disable the device and
+	 * schedule a driver removal.
+	 *
+	 * Note that a driver setting DRIVER_FIRMWARE is supposed to also set
+	 * the "apertures" information on @dev. It is used to match the memory
+	 * regions that are used by firmware drivers.
+	 */
+	void (*kick_out_firmware) (struct drm_device *dev);
+
 	/* Driver private ops for this object */
 	const struct vm_operations_struct *gem_vm_ops;
 
@@ -1087,6 +1106,7 @@ struct drm_pending_vblank_event {
  */
 struct drm_device {
 	struct list_head driver_item;	/**< list of devices per driver */
+	struct list_head global_item;	/**< global list of devices */
 	char *devname;			/**< For /proc/interrupts */
 	int if_version;			/**< Highest interface version set */
 
@@ -1218,6 +1238,8 @@ struct drm_device {
 	int switch_power_state;
 
 	atomic_t unplugged; /* device has been unplugged or gone away */
+	struct apertures_struct *apertures;	/**< fbmem apertures */
+	bool apert_boot;			/**< true if mapped as boot fb */
 };
 
 #define DRM_SWITCH_POWER_ON 0
@@ -1457,6 +1479,10 @@ extern void drm_master_put(struct drm_master **master);
 extern void drm_put_dev(struct drm_device *dev);
 extern int drm_put_minor(struct drm_minor **minor);
 extern void drm_unplug_dev(struct drm_device *dev);
+extern void drm_unplug_dev_locked(struct drm_device *dev);
+extern void drm_kick_out_firmware(struct apertures_struct *ap, bool boot);
+extern bool drm_is_firmware_used(struct apertures_struct *ap);
+extern struct list_head drm_devlist;
 extern unsigned int drm_debug;
 extern unsigned int drm_rnodes;
 
Signature · 1 line
1.8.4
#6 lore raw

PATCH v4 4/6 drm: nouveau: kick out firmware drivers during probe

In reply to David Herrmann

Use the new DRM infrastructure to kick out firmware drivers before probing the real driver.

Cc Maarten Lankhorst <[email protected]>
Cc Ben Skeggs <[email protected]>
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +22 -7
index 62c6118..452cc21 100644
@@ -252,13 +252,11 @@ nouveau_accel_init(struct nouveau_drm *drm)
 	nouveau_bo_move_init(drm);
 }
 
-static int nouveau_drm_probe(struct pci_dev *pdev,
-			     const struct pci_device_id *pent)
+static int nouveau_kick_out_firmware(struct drm_device *dev)
 {
-	struct nouveau_device *device;
 	struct apertures_struct *aper;
 	bool boot = false;
-	int ret;
+	struct pci_dev *pdev = dev->pdev;
 
 	/* remove conflicting drivers (vesafb, efifb etc) */
 	aper = alloc_apertures(3);
@@ -284,8 +282,18 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
 #ifdef CONFIG_X86
 	boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 #endif
-	remove_conflicting_framebuffers(aper, "nouveaufb", boot);
-	kfree(aper);
+
+	drm_kick_out_firmware(aper, boot);
+	dev->apertures = aper;
+	dev->apert_boot = boot;
+	return 0;
+}
+
+static int nouveau_drm_probe(struct pci_dev *pdev,
+			     const struct pci_device_id *pent)
+{
+	struct nouveau_device *device;
+	int ret;
 
 	ret = nouveau_device_create(pdev, nouveau_name(pdev), pci_name(pdev),
 				    nouveau_config, nouveau_debug, &device);
@@ -336,10 +344,14 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
 	struct nouveau_drm *drm;
 	int ret;
 
-	ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm);
+	ret = nouveau_kick_out_firmware(dev);
 	if (ret)
 		return ret;
 
+	ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm);
+	if (ret)
+		goto fail_apert;
+
 	dev->dev_private = drm;
 	drm->dev = dev;
 
@@ -444,6 +456,9 @@ fail_ttm:
 	nouveau_vga_fini(drm);
 fail_device:
 	nouveau_cli_destroy(&drm->client);
+fail_apert:
+	kfree(dev->apertures);
+	dev->apertures = NULL;
 	return ret;
 }
 
Signature · 1 line
1.8.4
#7 lore raw

PATCH v4 5/6 drm/i915: use new drm_kick_out_firmware()

In reply to David Herrmann

Use the new DRM infrastructure to kick out firmware DRM drivers before loading i915.

---
 drivers/gpu/drm/i915/i915_dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +3 -3
index 3e4e607..9d375a6 100644
@@ -1414,9 +1414,9 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
 	primary =
 		pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 
-	remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
-
-	kfree(ap);
+	drm_kick_out_firmware(ap, primary);
+	dev_priv->dev->apertures = ap;
+	dev_priv->dev->apert_boot = primary;
 }
 
 static void i915_dump_device_info(struct drm_i915_private *dev_priv)
Signature · 1 line
1.8.4
#8 lore raw

Re: [PATCH v4 5/6] drm/i915: use new drm_kick_out_firmware()

Quoted 14 lines · David Herrmann

Use the new DRM infrastructure to kick out firmware DRM drivers before loading i915.

---
 drivers/gpu/drm/i915/i915_dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +0 -0
index 3e4e607..9d375a6 100644

drivers/gpu/drm/i915/i915_dma.c static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv) · line 1419

Quoted 9 lines
drivers/gpu/drm/i915/i915_dma.c +3 -3
@@ -1414,9 +1414,9 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
 	primary =
 		pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 
-	remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
-
-	kfree(ap);
+	drm_kick_out_firmware(ap, primary);
+	dev_priv->dev->apertures = ap;
+	dev_priv->dev->apert_boot = primary;

What about passing dev to drm_kick_out_firmware and shovelling these two assignments in there? I've check your nouveau/radeon patches and I think this would work ...
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#9 lore raw

Re: [PATCH v4 5/6] drm/i915: use new drm_kick_out_firmware()

Hi

Quoted 18 lines · Daniel Vetter
Quoted 17 lines · David Herrmann

Use the new DRM infrastructure to kick out firmware DRM drivers before loading i915.

---
 drivers/gpu/drm/i915/i915_dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +0 -0
index 3e4e607..9d375a6 100644
@@ -1414,9 +1414,9 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
      primary =
              pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 
Quoted 10 lines

drivers/gpu/drm/i915/i915_dma.c static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv) · line 1419

Quoted 6 lines
drivers/gpu/drm/i915/i915_dma.c +3 -3
-     remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
-
-     kfree(ap);
+     drm_kick_out_firmware(ap, primary);
+     dev_priv->dev->apertures = ap;
+     dev_priv->dev->apert_boot = primary;

What about passing dev to drm_kick_out_firmware and shovelling these two assignments in there? I've check your nouveau/radeon patches and I think this would work ...

Yepp, that sounds reasonable. And I guess the kfree() of apertures can also be done in drm_put_dev(). Maybe we can even to the whole stuff in drm_pci.c, I will have a look.

Thanks
David

#10 lore raw

Re: [PATCH v4 5/6] drm/i915: use new drm_kick_out_firmware()

Quoted 32 lines · David Herrmann

Hi

Quoted 18 lines · Daniel Vetter
Quoted 17 lines · David Herrmann

Use the new DRM infrastructure to kick out firmware DRM drivers before loading i915.

---
 drivers/gpu/drm/i915/i915_dma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +0 -0
index 3e4e607..9d375a6 100644
@@ -1414,9 +1414,9 @@ static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
      primary =
              pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 
Quoted 10 lines

drivers/gpu/drm/i915/i915_dma.c static void i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv) · line 1419

Quoted 6 lines
drivers/gpu/drm/i915/i915_dma.c +3 -3
-     remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
-
-     kfree(ap);
+     drm_kick_out_firmware(ap, primary);
+     dev_priv->dev->apertures = ap;
+     dev_priv->dev->apert_boot = primary;

What about passing dev to drm_kick_out_firmware and shovelling these two assignments in there? I've check your nouveau/radeon patches and I think this would work ...

Quoted 3 lines

Yepp, that sounds reasonable. And I guess the kfree() of apertures can also be done in drm_put_dev(). Maybe we can even to the whole stuff in drm_pci.c, I will have a look.

I like the helper approach used here since it allows drivers to pick an appropriate spot. Moving it into drm_pci.c could be a bit ugly. Aside: I'm pondering ideas to weed out the midlayer smell from the drm device init sequence. I've played around with a few things and it looks like we're really close to doing the Right Thing ;-)

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#11 lore raw

PATCH v4 6/6 drm/radeon: use new drm_kick_out_firmware()

In reply to David Herrmann

Kick out firmware DRM and fbdev drivers via the new drm_kick_out_firmware() before loading radeon.

---
 drivers/gpu/drm/radeon/radeon_drv.c | 28 ----------------------------
 drivers/gpu/drm/radeon/radeon_kms.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 28 deletions(-)
drivers/gpu/drm/radeon/radeon_drv.c +0 -28
index 1f93dd5..13f1e15 100644
@@ -311,37 +311,9 @@ static struct drm_driver driver_old = {
 
 static struct drm_driver kms_driver;
 
-static int radeon_kick_out_firmware_fb(struct pci_dev *pdev)
-{
-	struct apertures_struct *ap;
-	bool primary = false;
-
-	ap = alloc_apertures(1);
-	if (!ap)
-		return -ENOMEM;
-
-	ap->ranges[0].base = pci_resource_start(pdev, 0);
-	ap->ranges[0].size = pci_resource_len(pdev, 0);
-
-#ifdef CONFIG_X86
-	primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
-#endif
-	remove_conflicting_framebuffers(ap, "radeondrmfb", primary);
-	kfree(ap);
-
-	return 0;
-}
-
 static int radeon_pci_probe(struct pci_dev *pdev,
 			    const struct pci_device_id *ent)
 {
-	int ret;
-
-	/* Get rid of things like offb */
-	ret = radeon_kick_out_firmware_fb(pdev);
-	if (ret)
-		return ret;
-
 	return drm_get_pci_dev(pdev, ent, &kms_driver);
 }
 
drivers/gpu/drm/radeon/radeon_kms.c +30 -0
index b46a561..d8f2a38 100644
@@ -62,6 +62,30 @@ done_free:
 	return 0;
 }
 
+static int radeon_kick_out_firmware(struct drm_device *dev)
+{
+	struct pci_dev *pdev = dev->pdev;
+	struct apertures_struct *ap;
+	bool primary = false;
+
+	ap = alloc_apertures(1);
+	if (!ap)
+		return -ENOMEM;
+
+	ap->ranges[0].base = pci_resource_start(pdev, 0);
+	ap->ranges[0].size = pci_resource_len(pdev, 0);
+
+#ifdef CONFIG_X86
+	primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
+#endif
+
+	drm_kick_out_firmware(ap, primary);
+	dev->apertures = ap;
+	dev->apert_boot = primary;
+
+	return 0;
+}
+
 /**
  * radeon_driver_load_kms - Main load function for KMS.
  *
@@ -86,6 +110,12 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
 	}
 	dev->dev_private = (void *)rdev;
 
+	r = radeon_kick_out_firmware(dev);
+	if (r) {
+		kfree(rdev);
+		return r;
+	}
+
 	/* update BUS flag */
 	if (drm_pci_device_is_agp(dev)) {
 		flags |= RADEON_IS_AGP;
Signature · 1 line
1.8.4
#12 lore raw
In reply to David Herrmann

Hi

Quoted 8 lines · David Herrmann

Hi

With the upcoming 3.12 merge-window, I thought people might find themselves with nothing to do, so here's a new SimpleDRM series. Comments welcome!

This depends on the tip/x86/fb series in the x86-tip tree:
http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/log/?h=x86/fb
Which, as far as I understood, will be pushed into 3.12 by the x86 people.

FYI, this is now merged in Linus' tree. See:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=228abe73ad67665d71eacd6a8a347dd76b0115ae

So hopefully we can get SimpleDRM ready for 3.13.

Cheers
David

#13 lore raw

Hi David,

Quoted 8 lines · David Herrmann

Hi

Quoted 5 lines · David Herrmann

Hi

With the upcoming 3.12 merge-window, I thought people might find themselves with nothing to do, so here's a new SimpleDRM series. Comments welcome!

Quoted 8 lines
Quoted 3 lines

This depends on the tip/x86/fb series in the x86-tip tree:
http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/log/?h=x86/fb
Which, as far as I understood, will be pushed into 3.12 by the x86 people.

FYI, this is now merged in Linus' tree. See:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=228abe73ad67665d71eacd6a8a347dd76b0115ae

So hopefully we can get SimpleDRM ready for 3.13.

Now that simplefb works for me, I finally got around to testing this. Just a couple of comments:

* I guess you need to add the modalias "platform:simple-framebuffer"
in addition to the "of:..." one to get module auto loading working.

* the driver currently doesn't work with your IORESOURCE_BUSY fix to
sysfb (as might be expected(?)):
simple-framebuffer simple-framebuffer.0: cannot reserve VMEM
simple-framebuffer: probe of simple-framebuffer.0 failed with error -5

* except for that, fbcon on top of the fbdev fallback support works fine for me. I didn't yet try the drm driver itself, what clients (if any) are supposed to work with this, kmscon, weston?

Cheers,

Tom

#14 lore raw

Hi

Quoted 18 lines · Tom Gundersen

Hi David,

Quoted 15 lines · David Herrmann

Hi

Quoted 8 lines · David Herrmann

Hi

With the upcoming 3.12 merge-window, I thought people might find themselves with nothing to do, so here's a new SimpleDRM series. Comments welcome!

This depends on the tip/x86/fb series in the x86-tip tree:
http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/log/?h=x86/fb
Which, as far as I understood, will be pushed into 3.12 by the x86 people.

FYI, this is now merged in Linus' tree. See:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=228abe73ad67665d71eacd6a8a347dd76b0115ae

Quoted 7 lines
Quoted 1 line

So hopefully we can get SimpleDRM ready for 3.13.

Now that simplefb works for me, I finally got around to testing this. Just a couple of comments:

* I guess you need to add the modalias "platform:simple-framebuffer"
in addition to the "of:..." one to get module auto loading working.

Yes, sounds good.

Quoted 4 lines

* the driver currently doesn't work with your IORESOURCE_BUSY fix to
sysfb (as might be expected(?)):
simple-framebuffer simple-framebuffer.0: cannot reserve VMEM
simple-framebuffer: probe of simple-framebuffer.0 failed with error -5

Yes, if the simple-framebuffer region is already marked BUSY, simpleDRM must not (and doesn't have to) call __request_region() (or request_mem_region()). I have to remove that call if the BUSY fix gets applied.

Quoted 3 lines

* except for that, fbcon on top of the fbdev fallback support works fine for me. I didn't yet try the drm driver itself, what clients (if any) are supposed to work with this, kmscon, weston?

Obviously, simpledrm doesn't support double-buffering, page-flipping or other advanced techniques. So I currently doubt you can use any real application on it as they all at least require 2 buffers. I haven't decided whether to emulate these in the kernel driver or to rely on user-space to deal with this reduced driver. It's quite likely I will go with both. That means, a compatibility option that makes simpledrm emulate any required techniques (multiple FBs, page-flipping) but also user-space patches to maybe some day be able to disable the kernel emulation.

Thanks a lot for testing all this. I will try to get the fixes into rc2. The speed-improvements might have to wait for 3.13, though.

Cheers
David