Skip to contentSkip to conversation

drm/gma500: Convert fbdev to DRM client

PATCH In review Thomas Zimmermann 2 participants 9 messages Mar 13, 2023 – Mar 16, 2023

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover drm/gma500: Convert fbdev to DRM client

Convert gma500's fbdev code to drm_client. Replace to the current ad-hoc integration. The conversion includes a number of cleanups. Only build fbdev support if the config option has been set.

Tested on Cedarview HW.

v2:
* remove fb_base (Patrik)
* use 'static inline' in header files (kernel test robot)
* fix many minor issues and typos

Thomas Zimmermann (7):
drm/gma500: Remove unnecessary include statements drm/gma500: Move fbdev code into separate source file drm/gma500: Remove fbdev vma open and close callbacks drm/gma500: Fix naming in fb_ops
drm/gma500: Inline psbfb_create() into psbfb_probe() drm/gma500: Implement client-based fbdev emulation drm/gma500: Pass fb_info to psb_fbdev_vm_fault()

 drivers/gpu/drm/gma500/Makefile      |   1 +
 drivers/gpu/drm/gma500/fbdev.c       | 344 +++++++++++++++++++++++++++
 drivers/gpu/drm/gma500/framebuffer.c | 341 +-------------------------
 drivers/gpu/drm/gma500/psb_drv.c     |   5 +-
 drivers/gpu/drm/gma500/psb_drv.h     |  19 +-
 5 files changed, 363 insertions(+), 347 deletions(-)
 create mode 100644 drivers/gpu/drm/gma500/fbdev.c

base-commit: b21ced77ae1dbc3d8b01d3aef3c99bba7377a69b

Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 1/7 drm/gma500: Remove unnecessary include statements

Remove unnecessary include statements from framebuffer.c. No functional changes.

---
 drivers/gpu/drm/gma500/framebuffer.c | 15 ---------------
 1 file changed, 15 deletions(-)
drivers/gpu/drm/gma500/framebuffer.c +0 -15
index 50611eb7f134..a07ca61ddc86 100644
@@ -5,23 +5,10 @@
  *
  **************************************************************************/
 
-#include <linux/console.h>
-#include <linux/delay.h>
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/module.h>
 #include <linux/pfn_t.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/tty.h>
 
-#include <drm/drm.h>
-#include <drm/drm_crtc.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_fb_helper.h>
-#include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_modeset_helper.h>
@@ -29,8 +16,6 @@
 #include "framebuffer.h"
 #include "gem.h"
 #include "psb_drv.h"
-#include "psb_intel_drv.h"
-#include "psb_intel_reg.h"
 
 static const struct drm_framebuffer_funcs psb_fb_funcs = {
 	.destroy = drm_gem_fb_destroy,
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH v2 2/7 drm/gma500: Move fbdev code into separate source file

In reply to Thomas Zimmermann

Move the fbdev emulation from framebuffer.c to fbdev.c. Only build the source code if the Kconfig symbol has been selected. Remaining in framebuffer.c is gma500's code for DRM framebuffers. No functional changes.

v2:
* remove 'extern' from function declaration (Patrik)
* declare empty init/fini functions as 'static inline' (kernel test robot)
* rebase onto vm_flags_set()
* typo fixes in commit message

---
 drivers/gpu/drm/gma500/Makefile      |   1 +
 drivers/gpu/drm/gma500/fbdev.c       | 325 +++++++++++++++++++++++++++
 drivers/gpu/drm/gma500/framebuffer.c | 318 +-------------------------
 drivers/gpu/drm/gma500/psb_drv.h     |  17 ++
 4 files changed, 346 insertions(+), 315 deletions(-)
 create mode 100644 drivers/gpu/drm/gma500/fbdev.c
drivers/gpu/drm/gma500/Makefile +1 -0
index 63012bf2485a..4f302cd5e1a6 100644
@@ -38,5 +38,6 @@ gma500_gfx-y += \
 	  psb_irq.o
 
 gma500_gfx-$(CONFIG_ACPI) +=  opregion.o
+gma500_gfx-$(CONFIG_DRM_FBDEV_EMULATION) +=  fbdev.o
 
 obj-$(CONFIG_DRM_GMA500) += gma500_gfx.o
drivers/gpu/drm/gma500/fbdev.c new file +325 -0

325 lines not on this page · raw message

drivers/gpu/drm/gma500/framebuffer.c +3 -315

354 lines not on this page · raw message

drivers/gpu/drm/gma500/psb_drv.h +17 -0
index a5df6d2f2cab..5d2ccb5280a4 100644
@@ -610,7 +610,24 @@ extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
 /* modesetting */
 extern void psb_modeset_init(struct drm_device *dev);
 extern void psb_modeset_cleanup(struct drm_device *dev);
+
+/* framebuffer */
+struct drm_framebuffer *psb_framebuffer_create(struct drm_device *dev,
+					       const struct drm_mode_fb_cmd2 *mode_cmd,
+					       struct drm_gem_object *obj);
+
+/* fbdev */
+#if defined(CONFIG_DRM_FBDEV_EMULATION)
 extern int psb_fbdev_init(struct drm_device *dev);
+extern void psb_fbdev_fini(struct drm_device *dev);
+#else
+static inline int psb_fbdev_init(struct drm_device *dev)
+{
+	return 0;
+}
+static inline void psb_fbdev_fini(struct drm_device *dev)
+{ }
+#endif
 
 /* backlight.c */
 int gma_backlight_init(struct drm_device *dev);
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH v2 3/7 drm/gma500: Remove fbdev vma open and close callbacks

In reply to Thomas Zimmermann

Remove fbdev emulations' open and close implementaitons for the VM. The functions are empty. Also update the naming of the VMA code.

---
 drivers/gpu/drm/gma500/fbdev.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/gma500/fbdev.c +4 -12
index 5235646334d9..8d181cb26440 100644
@@ -18,7 +18,7 @@
  * VM area struct
  */
 
-static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
+static vm_fault_t psb_fbdev_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct drm_framebuffer *fb = vma->vm_private_data;
@@ -49,16 +49,8 @@ static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
 	return ret;
 }
 
-static void psbfb_vm_open(struct vm_area_struct *vma)
-{ }
-
-static void psbfb_vm_close(struct vm_area_struct *vma)
-{ }
-
-static const struct vm_operations_struct psbfb_vm_ops = {
-	.fault	= psbfb_vm_fault,
-	.open	= psbfb_vm_open,
-	.close	= psbfb_vm_close
+static const struct vm_operations_struct psb_fbdev_vm_ops = {
+	.fault	= psb_fbdev_vm_fault,
 };
 
 /*
@@ -122,7 +114,7 @@ static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 	 * kernel remapping of the object. FIXME: Review if this is
 	 * suitable for our mmap work
 	 */
-	vma->vm_ops = &psbfb_vm_ops;
+	vma->vm_ops = &psb_fbdev_vm_ops;
 	vma->vm_private_data = (void *)fb;
 	vm_flags_set(vma, VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP);
 
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH v2 4/7 drm/gma500: Fix naming in fb_ops

In reply to Thomas Zimmermann

Fix some names around struct fb_ops to better fit the overall naming conventions. No functional changes.

v2:
* fix typo in commit message

---
 drivers/gpu/drm/gma500/fbdev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/gma500/fbdev.c +9 -9
index 8d181cb26440..f5c4c89a7c47 100644
@@ -59,10 +59,10 @@ static const struct vm_operations_struct psb_fbdev_vm_ops = {
 
 #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16)
 
-static int psbfb_setcolreg(unsigned int regno,
-			   unsigned int red, unsigned int green,
-			   unsigned int blue, unsigned int transp,
-			   struct fb_info *info)
+static int psb_fbdev_fb_setcolreg(unsigned int regno,
+				  unsigned int red, unsigned int green,
+				  unsigned int blue, unsigned int transp,
+				  struct fb_info *info)
 {
 	struct drm_fb_helper *fb_helper = info->par;
 	struct drm_framebuffer *fb = fb_helper->fb;
@@ -99,7 +99,7 @@ static int psbfb_setcolreg(unsigned int regno,
 	return 0;
 }
 
-static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+static int psb_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct drm_fb_helper *fb_helper = info->par;
 	struct drm_framebuffer *fb = fb_helper->fb;
@@ -121,16 +121,16 @@ static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 	return 0;
 }
 
-static const struct fb_ops psbfb_unaccel_ops = {
+static const struct fb_ops psb_fbdev_fb_ops = {
 	.owner = THIS_MODULE,
 	DRM_FB_HELPER_DEFAULT_OPS,
-	.fb_setcolreg = psbfb_setcolreg,
+	.fb_setcolreg = psb_fbdev_fb_setcolreg,
 	.fb_read = drm_fb_helper_cfb_read,
 	.fb_write = drm_fb_helper_cfb_write,
 	.fb_fillrect = drm_fb_helper_cfb_fillrect,
 	.fb_copyarea = drm_fb_helper_cfb_copyarea,
 	.fb_imageblit = drm_fb_helper_cfb_imageblit,
-	.fb_mmap = psbfb_mmap,
+	.fb_mmap = psb_fbdev_fb_mmap,
 };
 
 /*
@@ -190,7 +190,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
 
 	fb_helper->fb = fb;
 
-	info->fbops = &psbfb_unaccel_ops;
+	info->fbops = &psb_fbdev_fb_ops;
 
 	info->fix.smem_start = dev_priv->fb_base;
 	info->fix.smem_len = size;
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH v2 5/7 drm/gma500: Inline psbfb_create() into psbfb_probe()

In reply to Thomas Zimmermann

Inline psbfb_create() into its only caller psbfb_probe(). Streamline the color-depth selection. Also clean up the naming around struct drm_fb_helper_funcs.

v2:
* rename psbfb_probe() (Patrik)

---
 drivers/gpu/drm/gma500/fbdev.c | 71 ++++++++++++++--------------------
 1 file changed, 29 insertions(+), 42 deletions(-)
drivers/gpu/drm/gma500/fbdev.c +29 -42
index f5c4c89a7c47..74e843f8e64d 100644
@@ -137,31 +137,49 @@ static const struct fb_ops psb_fbdev_fb_ops = {
  * struct drm_fb_helper_funcs
  */
 
-static int psbfb_create(struct drm_fb_helper *fb_helper,
-			struct drm_fb_helper_surface_size *sizes)
+static int psb_fbdev_fb_probe(struct drm_fb_helper *fb_helper,
+			      struct drm_fb_helper_surface_size *sizes)
 {
 	struct drm_device *dev = fb_helper->dev;
 	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
 	struct fb_info *info;
 	struct drm_framebuffer *fb;
-	struct drm_mode_fb_cmd2 mode_cmd;
+	struct drm_mode_fb_cmd2 mode_cmd = { };
 	int size;
 	int ret;
 	struct psb_gem_object *backing;
 	struct drm_gem_object *obj;
 	u32 bpp, depth;
 
-	mode_cmd.width = sizes->surface_width;
-	mode_cmd.height = sizes->surface_height;
+	/* No 24-bit packed mode */
+	if (sizes->surface_bpp == 24) {
+		sizes->surface_bpp = 32;
+		sizes->surface_depth = 24;
+	}
 	bpp = sizes->surface_bpp;
 	depth = sizes->surface_depth;
 
-	/* No 24bit packed */
-	if (bpp == 24)
-		bpp = 32;
+	/*
+	 * If the mode does not fit in 32 bit then switch to 16 bit to get
+	 * a console on full resolution. The X mode setting server will
+	 * allocate its own 32-bit GEM framebuffer.
+	 */
+	size = ALIGN(sizes->surface_width * DIV_ROUND_UP(bpp, 8), 64) *
+		     sizes->surface_height;
+	size = ALIGN(size, PAGE_SIZE);
 
+	if (size > dev_priv->vram_stolen_size) {
+		sizes->surface_bpp = 16;
+		sizes->surface_depth = 16;
+	}
+	bpp = sizes->surface_bpp;
+	depth = sizes->surface_depth;
+
+	mode_cmd.width = sizes->surface_width;
+	mode_cmd.height = sizes->surface_height;
 	mode_cmd.pitches[0] = ALIGN(mode_cmd.width * DIV_ROUND_UP(bpp, 8), 64);
+	mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
 
 	size = mode_cmd.pitches[0] * mode_cmd.height;
 	size = ALIGN(size, PAGE_SIZE);
@@ -180,8 +198,6 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
 		goto err_drm_gem_object_put;
 	}
 
-	mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
-
 	fb = psb_framebuffer_create(dev, &mode_cmd, obj);
 	if (IS_ERR(fb)) {
 		ret = PTR_ERR(fb);
@@ -217,37 +233,8 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
 	return ret;
 }
 
-static int psbfb_probe(struct drm_fb_helper *fb_helper,
-				struct drm_fb_helper_surface_size *sizes)
-{
-	struct drm_device *dev = fb_helper->dev;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
-	unsigned int fb_size;
-	int bytespp;
-
-	bytespp = sizes->surface_bpp / 8;
-	if (bytespp == 3)	/* no 24bit packed */
-		bytespp = 4;
-
-	/*
-	 * If the mode will not fit in 32bit then switch to 16bit to get
-	 * a console on full resolution. The X mode setting server will
-	 * allocate its own 32bit GEM framebuffer
-	 */
-	fb_size = ALIGN(sizes->surface_width * bytespp, 64) *
-		  sizes->surface_height;
-	fb_size = ALIGN(fb_size, PAGE_SIZE);
-
-	if (fb_size > dev_priv->vram_stolen_size) {
-		sizes->surface_bpp = 16;
-		sizes->surface_depth = 16;
-	}
-
-	return psbfb_create(fb_helper, sizes);
-}
-
-static const struct drm_fb_helper_funcs psb_fb_helper_funcs = {
-	.fb_probe = psbfb_probe,
+static const struct drm_fb_helper_funcs psb_fbdev_fb_helper_funcs = {
+	.fb_probe = psb_fbdev_fb_probe,
 };
 
 static int psb_fbdev_destroy(struct drm_device *dev,
@@ -280,7 +267,7 @@ int psb_fbdev_init(struct drm_device *dev)
 
 	dev_priv->fb_helper = fb_helper;
 
-	drm_fb_helper_prepare(dev, fb_helper, 32, &psb_fb_helper_funcs);
+	drm_fb_helper_prepare(dev, fb_helper, 32, &psb_fbdev_fb_helper_funcs);
 
 	ret = drm_fb_helper_init(dev, fb_helper);
 	if (ret)
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH v2 6/7 drm/gma500: Implement client-based fbdev emulation

In reply to Thomas Zimmermann

Implement fbdevemulation on top of struct drm_client and its helpers. This ad-hoc interfaces for restoring and closing fbdev emulation with per-client callback for hotplugging, restoring and unregistering.

A single function, psb_fbdev_setup(), starts fbdev emulation after the DRM device has been registered. Hence, fbdev acts like a regular DRM client.

The setup call only prepares the fbdev emulation. It then implements connector hotplugging. The first successful hotplug event initializes fbdev emulation.

Unregistering depends on the hotplugging. Fully initialized emulation is cleaned up through drm_fb_helper_unregister_info() and fb_destroy. For prepared-only setups, unregistering unprepares the emulation and releases all resources. In both cases, fbdev emulation will be cleaned up.

v2:
* declare empty setup function as 'static inline' (kernel test robot)

---
 drivers/gpu/drm/gma500/fbdev.c       | 153 ++++++++++++++++++---------
 drivers/gpu/drm/gma500/framebuffer.c |   3 -
 drivers/gpu/drm/gma500/psb_drv.c     |   5 +-
 drivers/gpu/drm/gma500/psb_drv.h     |  12 +--
 4 files changed, 106 insertions(+), 67 deletions(-)
drivers/gpu/drm/gma500/fbdev.c +102 -51
index 74e843f8e64d..0433392c7fbf 100644
@@ -8,6 +8,7 @@
 #include <linux/pfn_t.h>
 
 #include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_framebuffer.h>
 
@@ -121,6 +122,27 @@ static int psb_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 	return 0;
 }
 
+static void psb_fbdev_fb_destroy(struct fb_info *info)
+{
+	struct drm_fb_helper *fb_helper = info->par;
+	struct drm_framebuffer *fb = fb_helper->fb;
+	struct drm_gem_object *obj = fb->obj[0];
+
+	drm_fb_helper_fini(fb_helper);
+
+	drm_framebuffer_unregister_private(fb);
+	fb->obj[0] = NULL;
+	drm_framebuffer_cleanup(fb);
+	kfree(fb);
+
+	drm_gem_object_put(obj);
+
+	drm_client_release(&fb_helper->client);
+
+	drm_fb_helper_unprepare(fb_helper);
+	kfree(fb_helper);
+}
+
 static const struct fb_ops psb_fbdev_fb_ops = {
 	.owner = THIS_MODULE,
 	DRM_FB_HELPER_DEFAULT_OPS,
@@ -131,6 +153,7 @@ static const struct fb_ops psb_fbdev_fb_ops = {
 	.fb_copyarea = drm_fb_helper_cfb_copyarea,
 	.fb_imageblit = drm_fb_helper_cfb_imageblit,
 	.fb_mmap = psb_fbdev_fb_mmap,
+	.fb_destroy = psb_fbdev_fb_destroy,
 };
 
 /*
@@ -190,14 +213,6 @@ static int psb_fbdev_fb_probe(struct drm_fb_helper *fb_helper,
 		return PTR_ERR(backing);
 	obj = &backing->base;
 
-	memset(dev_priv->vram_addr + backing->offset, 0, size);
-
-	info = drm_fb_helper_alloc_info(fb_helper);
-	if (IS_ERR(info)) {
-		ret = PTR_ERR(info);
-		goto err_drm_gem_object_put;
-	}
-
 	fb = psb_framebuffer_create(dev, &mode_cmd, obj);
 	if (IS_ERR(fb)) {
 		ret = PTR_ERR(fb);
@@ -206,28 +221,40 @@ static int psb_fbdev_fb_probe(struct drm_fb_helper *fb_helper,
 
 	fb_helper->fb = fb;
 
-	info->fbops = &psb_fbdev_fb_ops;
-
-	info->fix.smem_start = dev_priv->fb_base;
-	info->fix.smem_len = size;
-	info->fix.ywrapstep = 0;
-	info->fix.ypanstep = 0;
+	info = drm_fb_helper_alloc_info(fb_helper);
+	if (IS_ERR(info)) {
+		ret = PTR_ERR(info);
+		goto err_drm_framebuffer_unregister_private;
+	}
 
+	info->fbops = &psb_fbdev_fb_ops;
+	info->flags = FBINFO_DEFAULT;
 	/* Accessed stolen memory directly */
 	info->screen_base = dev_priv->vram_addr + backing->offset;
 	info->screen_size = size;
 
 	drm_fb_helper_fill_info(info, fb_helper, sizes);
 
+	info->fix.smem_start = dev_priv->fb_base;
+	info->fix.smem_len = size;
+	info->fix.ywrapstep = 0;
+	info->fix.ypanstep = 0;
 	info->fix.mmio_start = pci_resource_start(pdev, 0);
 	info->fix.mmio_len = pci_resource_len(pdev, 0);
 
+	memset(info->screen_base, 0, info->screen_size);
+
 	/* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
 
 	dev_dbg(dev->dev, "allocated %dx%d fb\n", fb->width, fb->height);
 
 	return 0;
 
+err_drm_framebuffer_unregister_private:
+	drm_framebuffer_unregister_private(fb);
+	fb->obj[0] = NULL;
+	drm_framebuffer_cleanup(fb);
+	kfree(fb);
 err_drm_gem_object_put:
 	drm_gem_object_put(obj);
 	return ret;
@@ -237,68 +264,92 @@ static const struct drm_fb_helper_funcs psb_fbdev_fb_helper_funcs = {
 	.fb_probe = psb_fbdev_fb_probe,
 };
 
-static int psb_fbdev_destroy(struct drm_device *dev,
-			     struct drm_fb_helper *fb_helper)
-{
-	struct drm_framebuffer *fb = fb_helper->fb;
-
-	drm_fb_helper_unregister_info(fb_helper);
+/*
+ * struct drm_client_funcs and setup code
+ */
 
-	drm_fb_helper_fini(fb_helper);
-	drm_framebuffer_unregister_private(fb);
-	drm_framebuffer_cleanup(fb);
+static void psb_fbdev_client_unregister(struct drm_client_dev *client)
+{
+	struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
+
+	if (fb_helper->info) {
+		drm_fb_helper_unregister_info(fb_helper);
+	} else {
+		drm_fb_helper_unprepare(fb_helper);
+		drm_client_release(&fb_helper->client);
+		kfree(fb_helper);
+	}
+}
 
-	if (fb->obj[0])
-		drm_gem_object_put(fb->obj[0]);
-	kfree(fb);
+static int psb_fbdev_client_restore(struct drm_client_dev *client)
+{
+	drm_fb_helper_lastclose(client->dev);
 
 	return 0;
 }
 
-int psb_fbdev_init(struct drm_device *dev)
+static int psb_fbdev_client_hotplug(struct drm_client_dev *client)
 {
-	struct drm_fb_helper *fb_helper;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
+	struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
+	struct drm_device *dev = client->dev;
 	int ret;
 
-	fb_helper = kzalloc(sizeof(*fb_helper), GFP_KERNEL);
-	if (!fb_helper)
-		return -ENOMEM;
-
-	dev_priv->fb_helper = fb_helper;
-
-	drm_fb_helper_prepare(dev, fb_helper, 32, &psb_fbdev_fb_helper_funcs);
+	if (dev->fb_helper)
+		return drm_fb_helper_hotplug_event(dev->fb_helper);
 
 	ret = drm_fb_helper_init(dev, fb_helper);
 	if (ret)
-		goto free;
+		goto err_drm_err;
 
-	/* disable all the possible outputs/crtcs before entering KMS mode */
-	drm_helper_disable_unused_functions(dev);
+	if (!drm_drv_uses_atomic_modeset(dev))
+		drm_helper_disable_unused_functions(dev);
 
 	ret = drm_fb_helper_initial_config(fb_helper);
 	if (ret)
-		goto fini;
+		goto err_drm_fb_helper_fini;
 
 	return 0;
 
-fini:
+err_drm_fb_helper_fini:
 	drm_fb_helper_fini(fb_helper);
-free:
-	drm_fb_helper_unprepare(fb_helper);
-	kfree(fb_helper);
+err_drm_err:
+	drm_err(dev, "Failed to setup gma500 fbdev emulation (ret=%d)\n", ret);
 	return ret;
 }
 
-void psb_fbdev_fini(struct drm_device *dev)
+static const struct drm_client_funcs psb_fbdev_client_funcs = {
+	.owner		= THIS_MODULE,
+	.unregister	= psb_fbdev_client_unregister,
+	.restore	= psb_fbdev_client_restore,
+	.hotplug	= psb_fbdev_client_hotplug,
+};
+
+void psb_fbdev_setup(struct drm_psb_private *dev_priv)
 {
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
+	struct drm_device *dev = &dev_priv->dev;
+	struct drm_fb_helper *fb_helper;
+	int ret;
 
-	if (!dev_priv->fb_helper)
+	fb_helper = kzalloc(sizeof(*fb_helper), GFP_KERNEL);
+	if (!fb_helper)
 		return;
+	drm_fb_helper_prepare(dev, fb_helper, 32, &psb_fbdev_fb_helper_funcs);
+
+	ret = drm_client_init(dev, &fb_helper->client, "fbdev-gma500", &psb_fbdev_client_funcs);
+	if (ret) {
+		drm_err(dev, "Failed to register client: %d\n", ret);
+		goto err_drm_fb_helper_unprepare;
+	}
+
+	ret = psb_fbdev_client_hotplug(&fb_helper->client);
+	if (ret)
+		drm_dbg_kms(dev, "client hotplug ret=%d\n", ret);
+
+	drm_client_register(&fb_helper->client);
+
+	return;
 
-	psb_fbdev_destroy(dev, dev_priv->fb_helper);
-	drm_fb_helper_unprepare(dev_priv->fb_helper);
-	kfree(dev_priv->fb_helper);
-	dev_priv->fb_helper = NULL;
+err_drm_fb_helper_unprepare:
+	drm_fb_helper_unprepare(fb_helper);
+	kfree(fb_helper);
 }
drivers/gpu/drm/gma500/framebuffer.c +0 -3
index 506b881a7b24..f5c3bae95eb5 100644
@@ -5,7 +5,6 @@
  *
  **************************************************************************/
 
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_modeset_helper.h>
@@ -120,7 +119,6 @@ static struct drm_framebuffer *psb_user_framebuffer_create
 
 static const struct drm_mode_config_funcs psb_mode_funcs = {
 	.fb_create = psb_user_framebuffer_create,
-	.output_poll_changed = drm_fb_helper_output_poll_changed,
 };
 
 static void psb_setup_outputs(struct drm_device *dev)
@@ -223,6 +221,5 @@ void psb_modeset_cleanup(struct drm_device *dev)
 	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
 	if (dev_priv->modeset) {
 		drm_kms_helper_poll_fini(dev);
-		psb_fbdev_fini(dev);
 	}
 }
drivers/gpu/drm/gma500/psb_drv.c +2 -3
index cd9c73f5a64a..2ce96b1b9c74 100644
@@ -21,7 +21,6 @@
 #include <drm/drm.h>
 #include <drm/drm_aperture.h>
 #include <drm/drm_drv.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_file.h>
 #include <drm/drm_ioctl.h>
 #include <drm/drm_pciids.h>
@@ -387,7 +386,6 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 	dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
 
 	psb_modeset_init(dev);
-	psb_fbdev_init(dev);
 	drm_kms_helper_poll_init(dev);
 
 	/* Only add backlight support if we have LVDS or MIPI output */
@@ -452,6 +450,8 @@ static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		return ret;
 
+	psb_fbdev_setup(dev_priv);
+
 	return 0;
 }
 
@@ -477,7 +477,6 @@ static const struct file_operations psb_gem_fops = {
 
 static const struct drm_driver driver = {
 	.driver_features = DRIVER_MODESET | DRIVER_GEM,
-	.lastclose = drm_fb_helper_lastclose,
 
 	.num_ioctls = ARRAY_SIZE(psb_ioctls),
 
drivers/gpu/drm/gma500/psb_drv.h +2 -10
index 5d2ccb5280a4..931f62c1d942 100644
@@ -193,8 +193,6 @@
 #define KSEL_BYPASS_25 6
 #define KSEL_BYPASS_83_100 7
 
-struct drm_fb_helper;
-
 struct opregion_header;
 struct opregion_acpi;
 struct opregion_swsci;
@@ -522,7 +520,6 @@ struct drm_psb_private {
 	uint32_t blc_adj1;
 	uint32_t blc_adj2;
 
-	struct drm_fb_helper *fb_helper;
 	resource_size_t fb_base;
 
 	bool dsr_enable;
@@ -618,14 +615,9 @@ struct drm_framebuffer *psb_framebuffer_create(struct drm_device *dev,
 
 /* fbdev */
 #if defined(CONFIG_DRM_FBDEV_EMULATION)
-extern int psb_fbdev_init(struct drm_device *dev);
-extern void psb_fbdev_fini(struct drm_device *dev);
+void psb_fbdev_setup(struct drm_psb_private *dev_priv);
 #else
-static inline int psb_fbdev_init(struct drm_device *dev)
-{
-	return 0;
-}
-static inline void psb_fbdev_fini(struct drm_device *dev)
+static inline void psb_fbdev_setup(struct drm_psb_private *dev_priv)
 { }
 #endif
 
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH v2 7/7 drm/gma500: Pass fb_info to psb_fbdev_vm_fault()

In reply to Thomas Zimmermann

Instead of the DRM framebuffer, pass the FB info strcuture to the fbdev page-fault handler psb_fbdev_vm_fault(). The framebuffer is a high-level data structure and does not belong into fault handling. The fb_info has all necessary information. Also set fix.smem_start to the correct value (the beginning of the framebuffer in physical address space) and streamline the page-fault handler.

v2:
* remove unused struct drm_psb_private.fb_base (Patrik)

---
 drivers/gpu/drm/gma500/fbdev.c       | 39 ++++++++++------------------
 drivers/gpu/drm/gma500/framebuffer.c |  5 ----
 drivers/gpu/drm/gma500/psb_drv.h     |  2 --
 3 files changed, 14 insertions(+), 32 deletions(-)
drivers/gpu/drm/gma500/fbdev.c +14 -25
index 0433392c7fbf..62287407e717 100644
@@ -22,32 +22,24 @@
 static vm_fault_t psb_fbdev_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
-	struct drm_framebuffer *fb = vma->vm_private_data;
-	struct drm_device *dev = fb->dev;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
-	struct psb_gem_object *pobj = to_psb_gem_object(fb->obj[0]);
-	int page_num;
-	int i;
-	unsigned long address;
-	vm_fault_t ret = VM_FAULT_SIGBUS;
-	unsigned long pfn;
-	unsigned long phys_addr = (unsigned long)dev_priv->stolen_base + pobj->offset;
-
-	page_num = vma_pages(vma);
-	address = vmf->address - (vmf->pgoff << PAGE_SHIFT);
+	struct fb_info *info = vma->vm_private_data;
+	unsigned long address = vmf->address - (vmf->pgoff << PAGE_SHIFT);
+	unsigned long pfn = info->fix.smem_start >> PAGE_SHIFT;
+	vm_fault_t err = VM_FAULT_SIGBUS;
+	unsigned long page_num = vma_pages(vma);
+	unsigned long i;
 
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
-	for (i = 0; i < page_num; i++) {
-		pfn = (phys_addr >> PAGE_SHIFT);
-
-		ret = vmf_insert_mixed(vma, address, __pfn_to_pfn_t(pfn, PFN_DEV));
-		if (unlikely(ret & VM_FAULT_ERROR))
+	for (i = 0; i < page_num; ++i) {
+		err = vmf_insert_mixed(vma, address, __pfn_to_pfn_t(pfn, PFN_DEV));
+		if (unlikely(err & VM_FAULT_ERROR))
 			break;
 		address += PAGE_SIZE;
-		phys_addr += PAGE_SIZE;
+		++pfn;
 	}
-	return ret;
+
+	return err;
 }
 
 static const struct vm_operations_struct psb_fbdev_vm_ops = {
@@ -102,9 +94,6 @@ static int psb_fbdev_fb_setcolreg(unsigned int regno,
 
 static int psb_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
-	struct drm_fb_helper *fb_helper = info->par;
-	struct drm_framebuffer *fb = fb_helper->fb;
-
 	if (vma->vm_pgoff != 0)
 		return -EINVAL;
 	if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
@@ -116,7 +105,7 @@ static int psb_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 	 * suitable for our mmap work
 	 */
 	vma->vm_ops = &psb_fbdev_vm_ops;
-	vma->vm_private_data = (void *)fb;
+	vma->vm_private_data = info;
 	vm_flags_set(vma, VM_IO | VM_MIXEDMAP | VM_DONTEXPAND | VM_DONTDUMP);
 
 	return 0;
@@ -235,7 +224,7 @@ static int psb_fbdev_fb_probe(struct drm_fb_helper *fb_helper,
 
 	drm_fb_helper_fill_info(info, fb_helper, sizes);
 
-	info->fix.smem_start = dev_priv->fb_base;
+	info->fix.smem_start = dev_priv->stolen_base + backing->offset;
 	info->fix.smem_len = size;
 	info->fix.ywrapstep = 0;
 	info->fix.ypanstep = 0;
drivers/gpu/drm/gma500/framebuffer.c +0 -5
index f5c3bae95eb5..1a374702b696 100644
@@ -186,7 +186,6 @@ void psb_modeset_init(struct drm_device *dev)
 {
 	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
 	struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
-	struct pci_dev *pdev = to_pci_dev(dev->dev);
 	int i;
 
 	if (drmm_mode_config_init(dev))
@@ -197,10 +196,6 @@ void psb_modeset_init(struct drm_device *dev)
 
 	dev->mode_config.funcs = &psb_mode_funcs;
 
-	/* set memory base */
-	/* Oaktrail and Poulsbo should use BAR 2*/
-	pci_read_config_dword(pdev, PSB_BSM, (u32 *)&(dev_priv->fb_base));
-
 	/* num pipes is 2 for PSB but 1 for Mrst */
 	for (i = 0; i < dev_priv->num_pipe; i++)
 		psb_intel_crtc_init(dev, i, mode_dev);
drivers/gpu/drm/gma500/psb_drv.h +0 -2
index 931f62c1d942..f7f709df99b4 100644
@@ -520,8 +520,6 @@ struct drm_psb_private {
 	uint32_t blc_adj1;
 	uint32_t blc_adj2;
 
-	resource_size_t fb_base;
-
 	bool dsr_enable;
 	u32 dsr_fb_update;
 	bool dpi_panel_on[3];
Signature · 1 line
2.39.2
maintainer Acked-by on the v2 series
#8 lore raw
In reply to Thomas Zimmermann
Quoted 5 lines · Thomas Zimmermann

Convert gma500's fbdev code to drm_client. Replace to the current ad-hoc integration. The conversion includes a number of cleanups. Only build fbdev support if the config option has been set.

Quoted 7 lines

Tested on Cedarview HW.

v2:
* remove fb_base (Patrik)
* use 'static inline' in header files (kernel test robot)
* fix many minor issues and typos

Thanks Thomas! For the entire series:

Quoted 22 lines

Thomas Zimmermann (7):
drm/gma500: Remove unnecessary include statements drm/gma500: Move fbdev code into separate source file drm/gma500: Remove fbdev vma open and close callbacks drm/gma500: Fix naming in fb_ops
drm/gma500: Inline psbfb_create() into psbfb_probe() drm/gma500: Implement client-based fbdev emulation drm/gma500: Pass fb_info to psb_fbdev_vm_fault()

 drivers/gpu/drm/gma500/Makefile      |   1 +
 drivers/gpu/drm/gma500/fbdev.c       | 344 +++++++++++++++++++++++++++
 drivers/gpu/drm/gma500/framebuffer.c | 341 +-------------------------
 drivers/gpu/drm/gma500/psb_drv.c     |   5 +-
 drivers/gpu/drm/gma500/psb_drv.h     |  19 +-
 5 files changed, 363 insertions(+), 347 deletions(-)
 create mode 100644 drivers/gpu/drm/gma500/fbdev.c

base-commit: b21ced77ae1dbc3d8b01d3aef3c99bba7377a69b --
2.39.2