Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/exynos: Implement fbdev emulation as in-kernel client

Move code from ad-hoc fbdev callbacks into DRM client functions
and remove the old callbacks. The functions instruct the client
to poll for changed output or restore the display. The DRM core
calls both, the old callbacks and the new client helpers, from
the same places. The new functions perform the same operation as
before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation
throughout the driver. Instead initialize the fbdev client by a
single call to exynos_fbdev_setup() after exynos has registered its
DRM device. As in most drivers, exynos' fbdev emulation now acts
like a regular DRM client.

The fbdev client setup consists of the initial preparation and the
hot-plugging of the display. The latter creates the fbdev device
and sets up the fbdev framebuffer. The setup performs display
hot-plugging once. If no display can be detected, DRM probe helpers
re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically.
No further action is required within exynos. If the fbdev framebuffer
has been fully set up, struct fb_ops.fb_destroy implements the
release. For partially initialized emulation, the fbdev client
reverts the initial setup.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>

authored by

Thomas Zimmermann and committed by
Inki Dae
49953b70 99286486

+80 -111
+3 -10
drivers/gpu/drm/exynos/exynos_drm_drv.c
··· 16 16 #include <drm/drm_atomic.h> 17 17 #include <drm/drm_atomic_helper.h> 18 18 #include <drm/drm_drv.h> 19 - #include <drm/drm_fb_helper.h> 20 19 #include <drm/drm_file.h> 21 20 #include <drm/drm_fourcc.h> 22 21 #include <drm/drm_ioctl.h> ··· 107 108 .driver_features = DRIVER_MODESET | DRIVER_GEM 108 109 | DRIVER_ATOMIC | DRIVER_RENDER, 109 110 .open = exynos_drm_open, 110 - .lastclose = drm_fb_helper_lastclose, 111 111 .postclose = exynos_drm_postclose, 112 112 .dumb_create = exynos_drm_gem_dumb_create, 113 113 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, ··· 286 288 /* init kms poll for handling hpd */ 287 289 drm_kms_helper_poll_init(drm); 288 290 289 - ret = exynos_drm_fbdev_init(drm); 290 - if (ret) 291 - goto err_cleanup_poll; 292 - 293 291 /* register the DRM device */ 294 292 ret = drm_dev_register(drm, 0); 295 293 if (ret < 0) 296 - goto err_cleanup_fbdev; 294 + goto err_cleanup_poll; 295 + 296 + exynos_drm_fbdev_setup(drm); 297 297 298 298 return 0; 299 299 300 - err_cleanup_fbdev: 301 - exynos_drm_fbdev_fini(drm); 302 300 err_cleanup_poll: 303 301 drm_kms_helper_poll_fini(drm); 304 302 err_unbind_all: ··· 315 321 316 322 drm_dev_unregister(drm); 317 323 318 - exynos_drm_fbdev_fini(drm); 319 324 drm_kms_helper_poll_fini(drm); 320 325 321 326 component_unbind_all(drm->dev, drm);
-2
drivers/gpu/drm/exynos/exynos_drm_fb.c
··· 11 11 #include <drm/drm_atomic.h> 12 12 #include <drm/drm_atomic_helper.h> 13 13 #include <drm/drm_crtc.h> 14 - #include <drm/drm_fb_helper.h> 15 14 #include <drm/drm_framebuffer.h> 16 15 #include <drm/drm_fourcc.h> 17 16 #include <drm/drm_gem_framebuffer_helper.h> ··· 156 157 157 158 static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { 158 159 .fb_create = exynos_user_fb_create, 159 - .output_poll_changed = drm_fb_helper_output_poll_changed, 160 160 .atomic_check = drm_atomic_helper_check, 161 161 .atomic_commit = drm_atomic_helper_commit, 162 162 };
+75 -81
drivers/gpu/drm/exynos/exynos_drm_fbdev.c
··· 8 8 * Seung-Woo Kim <sw0312.kim@samsung.com> 9 9 */ 10 10 11 - #include <linux/console.h> 12 - #include <linux/dma-mapping.h> 13 - #include <linux/vmalloc.h> 14 - 15 - #include <drm/drm_crtc.h> 11 + #include <drm/drm_crtc_helper.h> 12 + #include <drm/drm_drv.h> 16 13 #include <drm/drm_fb_helper.h> 17 - #include <drm/drm_fourcc.h> 18 14 #include <drm/drm_framebuffer.h> 19 15 #include <drm/drm_gem_framebuffer_helper.h> 20 16 #include <drm/drm_prime.h> 21 - #include <drm/drm_probe_helper.h> 22 17 #include <drm/exynos_drm.h> 23 18 24 19 #include "exynos_drm_drv.h" ··· 31 36 return drm_gem_prime_mmap(obj, vma); 32 37 } 33 38 39 + static void exynos_drm_fb_destroy(struct fb_info *info) 40 + { 41 + struct drm_fb_helper *fb_helper = info->par; 42 + struct drm_framebuffer *fb = fb_helper->fb; 43 + 44 + drm_fb_helper_fini(fb_helper); 45 + 46 + drm_framebuffer_remove(fb); 47 + 48 + drm_client_release(&fb_helper->client); 49 + drm_fb_helper_unprepare(fb_helper); 50 + kfree(fb_helper); 51 + } 52 + 34 53 static const struct fb_ops exynos_drm_fb_ops = { 35 54 .owner = THIS_MODULE, 36 55 DRM_FB_HELPER_DEFAULT_OPS, ··· 54 45 .fb_fillrect = drm_fb_helper_cfb_fillrect, 55 46 .fb_copyarea = drm_fb_helper_cfb_copyarea, 56 47 .fb_imageblit = drm_fb_helper_cfb_imageblit, 48 + .fb_destroy = exynos_drm_fb_destroy, 57 49 }; 58 50 59 51 static int exynos_drm_fbdev_update(struct drm_fb_helper *helper, ··· 125 115 if (ret < 0) 126 116 goto err_destroy_framebuffer; 127 117 128 - return ret; 118 + return 0; 129 119 130 120 err_destroy_framebuffer: 131 121 drm_framebuffer_cleanup(helper->fb); 122 + helper->fb = NULL; 132 123 err_destroy_gem: 133 124 exynos_drm_gem_destroy(exynos_gem); 134 - 135 - /* 136 - * if failed, all resources allocated above would be released by 137 - * drm_mode_config_cleanup() when drm_load() had been called prior 138 - * to any specific driver such as fimd or hdmi driver. 139 - */ 140 - 141 125 return ret; 142 126 } 143 127 ··· 144 140 */ 145 141 146 142 static void exynos_drm_fbdev_client_unregister(struct drm_client_dev *client) 147 - { } 143 + { 144 + struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client); 145 + 146 + if (fb_helper->info) { 147 + drm_fb_helper_unregister_info(fb_helper); 148 + } else { 149 + drm_client_release(&fb_helper->client); 150 + drm_fb_helper_unprepare(fb_helper); 151 + kfree(fb_helper); 152 + } 153 + } 148 154 149 155 static int exynos_drm_fbdev_client_restore(struct drm_client_dev *client) 150 156 { 157 + drm_fb_helper_lastclose(client->dev); 158 + 151 159 return 0; 152 160 } 153 161 154 162 static int exynos_drm_fbdev_client_hotplug(struct drm_client_dev *client) 155 163 { 164 + struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client); 165 + struct drm_device *dev = client->dev; 166 + int ret; 167 + 168 + if (dev->fb_helper) 169 + return drm_fb_helper_hotplug_event(dev->fb_helper); 170 + 171 + ret = drm_fb_helper_init(dev, fb_helper); 172 + if (ret) 173 + goto err_drm_err; 174 + 175 + if (!drm_drv_uses_atomic_modeset(dev)) 176 + drm_helper_disable_unused_functions(dev); 177 + 178 + ret = drm_fb_helper_initial_config(fb_helper); 179 + if (ret) 180 + goto err_drm_fb_helper_fini; 181 + 156 182 return 0; 183 + 184 + err_drm_fb_helper_fini: 185 + drm_fb_helper_fini(fb_helper); 186 + err_drm_err: 187 + drm_err(dev, "Failed to setup fbdev emulation (ret=%d)\n", ret); 188 + return ret; 157 189 } 158 190 159 191 static const struct drm_client_funcs exynos_drm_fbdev_client_funcs = { ··· 199 159 .hotplug = exynos_drm_fbdev_client_hotplug, 200 160 }; 201 161 202 - int exynos_drm_fbdev_init(struct drm_device *dev) 162 + void exynos_drm_fbdev_setup(struct drm_device *dev) 203 163 { 204 - struct drm_fb_helper *helper; 164 + struct drm_fb_helper *fb_helper; 205 165 int ret; 206 166 207 - if (!dev->mode_config.num_crtc) 208 - return 0; 167 + drm_WARN(dev, !dev->registered, "Device has not been registered.\n"); 168 + drm_WARN(dev, dev->fb_helper, "fb_helper is already set!\n"); 209 169 210 - helper = kzalloc(sizeof(*helper), GFP_KERNEL); 211 - if (!helper) 212 - return -ENOMEM; 213 - 214 - drm_fb_helper_prepare(dev, helper, PREFERRED_BPP, &exynos_drm_fb_helper_funcs); 215 - 216 - ret = drm_client_init(dev, &helper->client, "exynos-fbdev", &exynos_drm_fbdev_client_funcs); 217 - if (ret) 218 - goto err_drm_fb_helper_unprepare; 219 - 220 - ret = drm_fb_helper_init(dev, helper); 221 - if (ret < 0) { 222 - DRM_DEV_ERROR(dev->dev, 223 - "failed to initialize drm fb helper.\n"); 224 - goto err_drm_client_release; 225 - } 226 - 227 - ret = drm_fb_helper_initial_config(helper); 228 - if (ret < 0) { 229 - DRM_DEV_ERROR(dev->dev, 230 - "failed to set up hw configuration.\n"); 231 - goto err_setup; 232 - } 233 - 234 - return 0; 235 - 236 - err_setup: 237 - drm_fb_helper_fini(helper); 238 - err_drm_client_release: 239 - drm_client_release(&helper->client); 240 - err_drm_fb_helper_unprepare: 241 - drm_fb_helper_unprepare(helper); 242 - kfree(helper); 243 - 244 - return ret; 245 - } 246 - 247 - static void exynos_drm_fbdev_destroy(struct drm_device *dev, 248 - struct drm_fb_helper *fb_helper) 249 - { 250 - struct drm_framebuffer *fb; 251 - 252 - /* release drm framebuffer and real buffer */ 253 - if (fb_helper->fb && fb_helper->fb->funcs) { 254 - fb = fb_helper->fb; 255 - if (fb) 256 - drm_framebuffer_remove(fb); 257 - } 258 - 259 - drm_fb_helper_unregister_info(fb_helper); 260 - 261 - drm_fb_helper_fini(fb_helper); 262 - } 263 - 264 - void exynos_drm_fbdev_fini(struct drm_device *dev) 265 - { 266 - struct drm_fb_helper *fb_helper = dev->fb_helper; 267 - 170 + fb_helper = kzalloc(sizeof(*fb_helper), GFP_KERNEL); 268 171 if (!fb_helper) 269 172 return; 173 + drm_fb_helper_prepare(dev, fb_helper, PREFERRED_BPP, &exynos_drm_fb_helper_funcs); 270 174 271 - exynos_drm_fbdev_destroy(dev, fb_helper); 272 - drm_client_release(&fb_helper->client); 175 + ret = drm_client_init(dev, &fb_helper->client, "fbdev", &exynos_drm_fbdev_client_funcs); 176 + if (ret) 177 + goto err_drm_client_init; 178 + 179 + ret = exynos_drm_fbdev_client_hotplug(&fb_helper->client); 180 + if (ret) 181 + drm_dbg_kms(dev, "client hotplug ret=%d\n", ret); 182 + 183 + drm_client_register(&fb_helper->client); 184 + 185 + return; 186 + 187 + err_drm_client_init: 273 188 drm_fb_helper_unprepare(fb_helper); 274 189 kfree(fb_helper); 275 190 } 276 -
+2 -18
drivers/gpu/drm/exynos/exynos_drm_fbdev.h
··· 12 12 #define _EXYNOS_DRM_FBDEV_H_ 13 13 14 14 #ifdef CONFIG_DRM_FBDEV_EMULATION 15 - 16 - int exynos_drm_fbdev_init(struct drm_device *dev); 17 - void exynos_drm_fbdev_fini(struct drm_device *dev); 18 - 15 + void exynos_drm_fbdev_setup(struct drm_device *dev); 19 16 #else 20 - 21 - static inline int exynos_drm_fbdev_init(struct drm_device *dev) 22 - { 23 - return 0; 24 - } 25 - 26 - static inline void exynos_drm_fbdev_fini(struct drm_device *dev) 17 + static inline void exynos_drm_fbdev_setup(struct drm_device *dev) 27 18 { 28 19 } 29 - 30 - static inline void exynos_drm_fbdev_restore_mode(struct drm_device *dev) 31 - { 32 - } 33 - 34 - #define exynos_drm_output_poll_changed (NULL) 35 - 36 20 #endif 37 21 38 22 #endif