Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a387aeb

Browse files
Thomas ZimmermannCarlos Llamas
authored andcommitted
UPSTREAM: drm/fbdev: Add memory-agnostic fbdev client
[ Upstream commit 5d08c44 ] Add an fbdev client that can work with any memory manager. The client implementation is the same as existing code in fbdev-dma or fbdev-shmem. Provide struct drm_driver.fbdev_probe for the new client to allocate the surface GEM buffer. The new callback replaces fb_probe of struct drm_fb_helper_funcs, which does the same. To use the new client, DRM drivers set fbdev_probe in their struct drm_driver instance and call drm_fbdev_client_setup(). Probing and creating the fbdev surface buffer is now independent from the other operations in struct drm_fb_helper. For the pixel format, the fbdev client either uses a specified format, the value in preferred_depth or 32-bit RGB. v2: - test for struct drm_fb_helper.funcs for NULL (Sui) - respect struct drm_mode_config.preferred_depth for default format Change-Id: I50035b52dfef65794ea7057ae0aeaa580defd9c7 Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240924071734.98201-4-tzimmermann@suse.de Stable-dep-of: 6b481ab ("drm/nouveau: select FW caching") Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 7f5535f) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1 parent e3e9468 commit a387aeb

File tree

5 files changed

+190
-7
lines changed

5 files changed

+190
-7
lines changed

drivers/gpu/drm/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ drm_kms_helper-y := \
145145
drm_self_refresh_helper.o \
146146
drm_simple_kms_helper.o
147147
drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
148-
drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
148+
drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += \
149+
drm_fbdev_client.o \
150+
drm_fb_helper.o
149151
obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
150152

151153
#

drivers/gpu/drm/drm_fb_helper.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ EXPORT_SYMBOL(drm_fb_helper_init);
492492
* @fb_helper: driver-allocated fbdev helper
493493
*
494494
* A helper to alloc fb_info and the member cmap. Called by the driver
495-
* within the fb_probe fb_helper callback function. Drivers do not
496-
* need to release the allocated fb_info structure themselves, this is
495+
* within the struct &drm_driver.fbdev_probe callback function. Drivers do
496+
* not need to release the allocated fb_info structure themselves, this is
497497
* automatically done when calling drm_fb_helper_fini().
498498
*
499499
* RETURNS:
@@ -1610,7 +1610,7 @@ static int drm_fb_helper_find_sizes(struct drm_fb_helper *fb_helper,
16101610

16111611
/*
16121612
* Allocates the backing storage and sets up the fbdev info structure through
1613-
* the ->fb_probe callback.
1613+
* the ->fbdev_probe callback.
16141614
*/
16151615
static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper)
16161616
{
@@ -1628,7 +1628,10 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper)
16281628
}
16291629

16301630
/* push down into drivers */
1631-
ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1631+
if (dev->driver->fbdev_probe)
1632+
ret = dev->driver->fbdev_probe(fb_helper, &sizes);
1633+
else if (fb_helper->funcs)
1634+
ret = fb_helper->funcs->fb_probe(fb_helper, &sizes);
16321635
if (ret < 0)
16331636
return ret;
16341637

@@ -1700,7 +1703,7 @@ static void drm_fb_helper_fill_var(struct fb_info *info,
17001703
* instance and the drm framebuffer allocated in &drm_fb_helper.fb.
17011704
*
17021705
* Drivers should call this (or their equivalent setup code) from their
1703-
* &drm_fb_helper_funcs.fb_probe callback after having allocated the fbdev
1706+
* &drm_driver.fbdev_probe callback after having allocated the fbdev
17041707
* backing storage framebuffer.
17051708
*/
17061709
void drm_fb_helper_fill_info(struct fb_info *info,
@@ -1856,7 +1859,7 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper)
18561859
* Note that this also registers the fbdev and so allows userspace to call into
18571860
* the driver through the fbdev interfaces.
18581861
*
1859-
* This function will call down into the &drm_fb_helper_funcs.fb_probe callback
1862+
* This function will call down into the &drm_driver.fbdev_probe callback
18601863
* to let the driver allocate and initialize the fbdev info structure and the
18611864
* drm framebuffer used to back the fbdev. drm_fb_helper_fill_info() is provided
18621865
* as a helper to setup simple default values for the fbdev info structure.

drivers/gpu/drm/drm_fbdev_client.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
#include <drm/drm_client.h>
4+
#include <drm/drm_crtc_helper.h>
5+
#include <drm/drm_drv.h>
6+
#include <drm/drm_fbdev_client.h>
7+
#include <drm/drm_fb_helper.h>
8+
#include <drm/drm_fourcc.h>
9+
#include <drm/drm_print.h>
10+
11+
/*
12+
* struct drm_client_funcs
13+
*/
14+
15+
static void drm_fbdev_client_unregister(struct drm_client_dev *client)
16+
{
17+
struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
18+
19+
if (fb_helper->info) {
20+
drm_fb_helper_unregister_info(fb_helper);
21+
} else {
22+
drm_client_release(&fb_helper->client);
23+
drm_fb_helper_unprepare(fb_helper);
24+
kfree(fb_helper);
25+
}
26+
}
27+
28+
static int drm_fbdev_client_restore(struct drm_client_dev *client)
29+
{
30+
drm_fb_helper_lastclose(client->dev);
31+
32+
return 0;
33+
}
34+
35+
static int drm_fbdev_client_hotplug(struct drm_client_dev *client)
36+
{
37+
struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
38+
struct drm_device *dev = client->dev;
39+
int ret;
40+
41+
if (dev->fb_helper)
42+
return drm_fb_helper_hotplug_event(dev->fb_helper);
43+
44+
ret = drm_fb_helper_init(dev, fb_helper);
45+
if (ret)
46+
goto err_drm_err;
47+
48+
if (!drm_drv_uses_atomic_modeset(dev))
49+
drm_helper_disable_unused_functions(dev);
50+
51+
ret = drm_fb_helper_initial_config(fb_helper);
52+
if (ret)
53+
goto err_drm_fb_helper_fini;
54+
55+
return 0;
56+
57+
err_drm_fb_helper_fini:
58+
drm_fb_helper_fini(fb_helper);
59+
err_drm_err:
60+
drm_err(dev, "fbdev: Failed to setup emulation (ret=%d)\n", ret);
61+
return ret;
62+
}
63+
64+
static const struct drm_client_funcs drm_fbdev_client_funcs = {
65+
.owner = THIS_MODULE,
66+
.unregister = drm_fbdev_client_unregister,
67+
.restore = drm_fbdev_client_restore,
68+
.hotplug = drm_fbdev_client_hotplug,
69+
};
70+
71+
/**
72+
* drm_fbdev_client_setup() - Setup fbdev emulation
73+
* @dev: DRM device
74+
* @format: Preferred color format for the device. DRM_FORMAT_XRGB8888
75+
* is used if this is zero.
76+
*
77+
* This function sets up fbdev emulation. Restore, hotplug events and
78+
* teardown are all taken care of. Drivers that do suspend/resume need
79+
* to call drm_fb_helper_set_suspend_unlocked() themselves. Simple
80+
* drivers might use drm_mode_config_helper_suspend().
81+
*
82+
* This function is safe to call even when there are no connectors present.
83+
* Setup will be retried on the next hotplug event.
84+
*
85+
* The fbdev client is destroyed by drm_dev_unregister().
86+
*
87+
* Returns:
88+
* 0 on success, or a negative errno code otherwise.
89+
*/
90+
int drm_fbdev_client_setup(struct drm_device *dev, const struct drm_format_info *format)
91+
{
92+
struct drm_fb_helper *fb_helper;
93+
unsigned int color_mode;
94+
int ret;
95+
96+
/* TODO: Use format info throughout DRM */
97+
if (format) {
98+
unsigned int bpp = drm_format_info_bpp(format, 0);
99+
100+
switch (bpp) {
101+
case 16:
102+
color_mode = format->depth; // could also be 15
103+
break;
104+
default:
105+
color_mode = bpp;
106+
}
107+
} else {
108+
switch (dev->mode_config.preferred_depth) {
109+
case 0:
110+
case 24:
111+
color_mode = 32;
112+
break;
113+
default:
114+
color_mode = dev->mode_config.preferred_depth;
115+
}
116+
}
117+
118+
drm_WARN(dev, !dev->registered, "Device has not been registered.\n");
119+
drm_WARN(dev, dev->fb_helper, "fb_helper is already set!\n");
120+
121+
fb_helper = kzalloc(sizeof(*fb_helper), GFP_KERNEL);
122+
if (!fb_helper)
123+
return -ENOMEM;
124+
drm_fb_helper_prepare(dev, fb_helper, color_mode, NULL);
125+
126+
ret = drm_client_init(dev, &fb_helper->client, "fbdev", &drm_fbdev_client_funcs);
127+
if (ret) {
128+
drm_err(dev, "Failed to register client: %d\n", ret);
129+
goto err_drm_client_init;
130+
}
131+
132+
drm_client_register(&fb_helper->client);
133+
134+
return 0;
135+
136+
err_drm_client_init:
137+
drm_fb_helper_unprepare(fb_helper);
138+
kfree(fb_helper);
139+
return ret;
140+
}
141+
EXPORT_SYMBOL(drm_fbdev_client_setup);

include/drm/drm_drv.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#include <drm/drm_device.h>
3636

37+
struct drm_fb_helper;
38+
struct drm_fb_helper_surface_size;
3739
struct drm_file;
3840
struct drm_gem_object;
3941
struct drm_master;
@@ -366,6 +368,22 @@ struct drm_driver {
366368
struct drm_device *dev, uint32_t handle,
367369
uint64_t *offset);
368370

371+
/**
372+
* @fbdev_probe
373+
*
374+
* Allocates and initialize the fb_info structure for fbdev emulation.
375+
* Furthermore it also needs to allocate the DRM framebuffer used to
376+
* back the fbdev.
377+
*
378+
* This callback is mandatory for fbdev support.
379+
*
380+
* Returns:
381+
*
382+
* 0 on success ot a negative error code otherwise.
383+
*/
384+
int (*fbdev_probe)(struct drm_fb_helper *fbdev_helper,
385+
struct drm_fb_helper_surface_size *sizes);
386+
369387
/**
370388
* @show_fdinfo:
371389
*

include/drm/drm_fbdev_client.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: MIT */
2+
3+
#ifndef DRM_FBDEV_CLIENT_H
4+
#define DRM_FBDEV_CLIENT_H
5+
6+
struct drm_device;
7+
struct drm_format_info;
8+
9+
#ifdef CONFIG_DRM_FBDEV_EMULATION
10+
int drm_fbdev_client_setup(struct drm_device *dev, const struct drm_format_info *format);
11+
#else
12+
static inline int drm_fbdev_client_setup(struct drm_device *dev,
13+
const struct drm_format_info *format)
14+
{
15+
return 0;
16+
}
17+
#endif
18+
19+
#endif

0 commit comments

Comments
 (0)