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

Configure Feed

Select the types of activity you want to include in your feed.

drm/sysfb: corebootdrm: Add DRM driver for coreboot framebuffers

Add corebootdrm, a DRM driver for coreboot framebuffers. The driver
supports a pre-initialized framebuffer with various packed RGB formats.
The driver code is fairly small and uses the same logic as the other
sysfb drivers. Most of the implementation comes from existing sysfb
helpers.

Until now, coreboot relied on simpledrm or simplefb for boot-up graphics
output. Initialize the platform device for corebootdrm in the same place
in framebuffer_probe(). With a later commit, the simple-framebuffer should
be removed.

v4:
- sort include statements (Tzung-Bi)
v3:
- comment on _HAS_LFB semantics (Tzung-Bi)
- fix typo in commit description (Tzung-Bi)
- comment on simple-framebuffer being obsolete for coreboot
v2:
- reimplement as platform driver
- limit resources and mappings to known framebuffer memory; no
page alignment
- create corebootdrm device from coreboot framebuffer code

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Acked-by: Julius Werner <jwerner@chromium.org>
Acked-by: Tzung-Bi Shih <tzungbi@kernel.org> # coreboot
Link: https://patch.msgid.link/20260217155836.96267-12-tzimmermann@suse.de

+458 -4
+2 -1
drivers/firmware/google/Kconfig
··· 63 63 help 64 64 This option enables the kernel to search for a framebuffer in 65 65 the coreboot table. If found, it is registered with a platform 66 - device of type simple-framebuffer. 66 + device of type coreboot-framebuffer. Using the old device of 67 + type simple-framebuffer is deprecated. 67 68 68 69 config GOOGLE_MEMCONSOLE_COREBOOT 69 70 tristate "Firmware Memory Console"
+19 -3
drivers/firmware/google/framebuffer-coreboot.c
··· 76 76 return NULL; 77 77 } 78 78 79 - static const struct simplefb_format formats[] = SIMPLEFB_FORMATS; 80 - 81 79 static int framebuffer_probe(struct coreboot_device *dev) 82 80 { 83 - int i; 84 81 struct lb_framebuffer *fb = &dev->framebuffer; 85 82 struct device *parent; 86 83 struct platform_device *pdev; 87 84 struct resource res; 88 85 int ret; 86 + #if !IS_ENABLED(CONFIG_DRM_COREBOOTDRM) 89 87 struct simplefb_platform_data pdata = { 90 88 .width = fb->x_resolution, 91 89 .height = fb->y_resolution, 92 90 .stride = fb->bytes_per_line, 93 91 .format = NULL, 94 92 }; 93 + int i; 94 + static const struct simplefb_format formats[] = SIMPLEFB_FORMATS; 95 + #endif 95 96 96 97 /* 97 98 * On coreboot systems, the advertised LB_TAG_FRAMEBUFFER entry ··· 119 118 if (IS_ERR(parent)) 120 119 return PTR_ERR(parent); 121 120 121 + #if IS_ENABLED(CONFIG_DRM_COREBOOTDRM) 122 + pdev = platform_device_register_resndata(parent, "coreboot-framebuffer", 0, 123 + &res, 1, fb, fb->size); 124 + if (IS_ERR(pdev)) { 125 + pr_warn("coreboot: could not register framebuffer\n"); 126 + ret = PTR_ERR(pdev); 127 + goto out_put_device_parent; 128 + } 129 + #else 130 + /* 131 + * FIXME: Coreboot systems should use a driver that binds to 132 + * coreboot-framebuffer devices. Remove support for 133 + * simple-framebuffer at some point. 134 + */ 122 135 for (i = 0; i < ARRAY_SIZE(formats); ++i) { 123 136 if (fb->bits_per_pixel == formats[i].bits_per_pixel && 124 137 fb->red_mask_pos == formats[i].red.offset && ··· 157 142 pr_warn("coreboot: could not register framebuffer\n"); 158 143 goto out_put_device_parent; 159 144 } 145 + #endif 160 146 161 147 ret = 0; 162 148
+16
drivers/gpu/drm/sysfb/Kconfig
··· 7 7 tristate 8 8 depends on DRM 9 9 10 + config DRM_COREBOOTDRM 11 + tristate "Coreboot framebuffer driver" 12 + depends on DRM && MMU 13 + depends on GOOGLE_FRAMEBUFFER_COREBOOT 14 + select APERTURE_HELPERS 15 + select DRM_CLIENT_SELECTION 16 + select DRM_GEM_SHMEM_HELPER 17 + select DRM_KMS_HELPER 18 + select DRM_SYSFB_HELPER 19 + help 20 + DRM driver for coreboot-provided framebuffers. 21 + 22 + This driver assumes that the display hardware has been initialized 23 + by coreboot firmware before the kernel boots. Scanout buffer, size, 24 + and display format must be provided via coreboot framebuffer device. 25 + 10 26 config DRM_EFIDRM 11 27 tristate "EFI framebuffer driver" 12 28 depends on DRM && MMU && EFI && (!SYSFB_SIMPLEFB || COMPILE_TEST)
+1
drivers/gpu/drm/sysfb/Makefile
··· 6 6 drm_sysfb_helper-$(CONFIG_SCREEN_INFO) += drm_sysfb_screen_info.o 7 7 obj-$(CONFIG_DRM_SYSFB_HELPER) += drm_sysfb_helper.o 8 8 9 + obj-$(CONFIG_DRM_COREBOOTDRM) += corebootdrm.o 9 10 obj-$(CONFIG_DRM_EFIDRM) += efidrm.o 10 11 obj-$(CONFIG_DRM_OFDRM) += ofdrm.o 11 12 obj-$(CONFIG_DRM_SIMPLEDRM) += simpledrm.o
+412
drivers/gpu/drm/sysfb/corebootdrm.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <linux/aperture.h> 4 + #include <linux/coreboot.h> 5 + #include <linux/minmax.h> 6 + #include <linux/platform_device.h> 7 + 8 + #include <drm/clients/drm_client_setup.h> 9 + #include <drm/drm_atomic.h> 10 + #include <drm/drm_atomic_state_helper.h> 11 + #include <drm/drm_connector.h> 12 + #include <drm/drm_damage_helper.h> 13 + #include <drm/drm_device.h> 14 + #include <drm/drm_drv.h> 15 + #include <drm/drm_fbdev_shmem.h> 16 + #include <drm/drm_framebuffer.h> 17 + #include <drm/drm_gem_atomic_helper.h> 18 + #include <drm/drm_gem_framebuffer_helper.h> 19 + #include <drm/drm_gem_shmem_helper.h> 20 + #include <drm/drm_managed.h> 21 + #include <drm/drm_modeset_helper_vtables.h> 22 + #include <drm/drm_print.h> 23 + #include <drm/drm_probe_helper.h> 24 + 25 + #include "drm_sysfb_helper.h" 26 + 27 + #define DRIVER_NAME "corebootdrm" 28 + #define DRIVER_DESC "DRM driver for Coreboot framebuffers" 29 + #define DRIVER_MAJOR 1 30 + #define DRIVER_MINOR 0 31 + 32 + static const struct drm_format_info * 33 + corebootdrm_get_format_fb(struct drm_device *dev, const struct lb_framebuffer *fb) 34 + { 35 + static const struct drm_sysfb_format formats[] = { 36 + { PIXEL_FORMAT_XRGB1555, DRM_FORMAT_XRGB1555, }, 37 + { PIXEL_FORMAT_RGB565, DRM_FORMAT_RGB565, }, 38 + { PIXEL_FORMAT_RGB888, DRM_FORMAT_RGB888, }, 39 + { PIXEL_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888, }, 40 + { PIXEL_FORMAT_XBGR8888, DRM_FORMAT_XBGR8888, }, 41 + { PIXEL_FORMAT_XRGB2101010, DRM_FORMAT_XRGB2101010, }, 42 + }; 43 + const struct pixel_format pixel = { 44 + .bits_per_pixel = fb->bits_per_pixel, 45 + .indexed = false, 46 + .alpha = { 47 + .offset = 0, 48 + .length = 0, 49 + }, 50 + .red = { 51 + .offset = fb->red_mask_pos, 52 + .length = fb->red_mask_size, 53 + }, 54 + .green = { 55 + .offset = fb->green_mask_pos, 56 + .length = fb->green_mask_size, 57 + }, 58 + .blue = { 59 + .offset = fb->blue_mask_pos, 60 + .length = fb->blue_mask_size, 61 + }, 62 + }; 63 + 64 + return drm_sysfb_get_format(dev, formats, ARRAY_SIZE(formats), &pixel); 65 + } 66 + 67 + static int corebootdrm_get_width_fb(struct drm_device *dev, const struct lb_framebuffer *fb) 68 + { 69 + return drm_sysfb_get_validated_int0(dev, "width", fb->x_resolution, INT_MAX); 70 + } 71 + 72 + static int corebootdrm_get_height_fb(struct drm_device *dev, const struct lb_framebuffer *fb) 73 + { 74 + return drm_sysfb_get_validated_int0(dev, "height", fb->y_resolution, INT_MAX); 75 + } 76 + 77 + static int corebootdrm_get_pitch_fb(struct drm_device *dev, const struct drm_format_info *format, 78 + unsigned int width, const struct lb_framebuffer *fb) 79 + { 80 + u64 bytes_per_line = fb->bytes_per_line; 81 + 82 + if (!bytes_per_line) 83 + bytes_per_line = drm_format_info_min_pitch(format, 0, width); 84 + 85 + return drm_sysfb_get_validated_int0(dev, "pitch", bytes_per_line, INT_MAX); 86 + } 87 + 88 + static resource_size_t corebootdrm_get_size_fb(struct drm_device *dev, unsigned int height, 89 + unsigned int pitch, 90 + const struct lb_framebuffer *fb) 91 + { 92 + resource_size_t size; 93 + 94 + if (check_mul_overflow(height, pitch, &size)) 95 + return 0; 96 + 97 + return size; 98 + } 99 + 100 + static phys_addr_t corebootdrm_get_address_fb(struct drm_device *dev, resource_size_t size, 101 + const struct lb_framebuffer *fb) 102 + { 103 + if (size > PHYS_ADDR_MAX) 104 + return 0; 105 + if (!fb->physical_address) 106 + return 0; 107 + if (fb->physical_address > (PHYS_ADDR_MAX - size)) 108 + return 0; 109 + 110 + return fb->physical_address; 111 + } 112 + 113 + /* 114 + * Simple Framebuffer device 115 + */ 116 + 117 + struct corebootdrm_device { 118 + struct drm_sysfb_device sysfb; 119 + 120 + /* modesetting */ 121 + u32 formats[DRM_SYSFB_PLANE_NFORMATS(1)]; 122 + struct drm_plane primary_plane; 123 + struct drm_crtc crtc; 124 + struct drm_encoder encoder; 125 + struct drm_connector connector; 126 + }; 127 + 128 + /* 129 + * Modesetting 130 + */ 131 + 132 + static const u64 corebootdrm_primary_plane_format_modifiers[] = { 133 + DRM_SYSFB_PLANE_FORMAT_MODIFIERS, 134 + }; 135 + 136 + static const struct drm_plane_helper_funcs corebootdrm_primary_plane_helper_funcs = { 137 + DRM_SYSFB_PLANE_HELPER_FUNCS, 138 + }; 139 + 140 + static const struct drm_plane_funcs corebootdrm_primary_plane_funcs = { 141 + DRM_SYSFB_PLANE_FUNCS, 142 + .destroy = drm_plane_cleanup, 143 + }; 144 + 145 + static const struct drm_crtc_helper_funcs corebootdrm_crtc_helper_funcs = { 146 + DRM_SYSFB_CRTC_HELPER_FUNCS, 147 + }; 148 + 149 + static const struct drm_crtc_funcs corebootdrm_crtc_funcs = { 150 + DRM_SYSFB_CRTC_FUNCS, 151 + .destroy = drm_crtc_cleanup, 152 + }; 153 + 154 + static const struct drm_encoder_funcs corebootdrm_encoder_funcs = { 155 + .destroy = drm_encoder_cleanup, 156 + }; 157 + 158 + static const struct drm_connector_helper_funcs corebootdrm_connector_helper_funcs = { 159 + DRM_SYSFB_CONNECTOR_HELPER_FUNCS, 160 + }; 161 + 162 + static const struct drm_connector_funcs corebootdrm_connector_funcs = { 163 + DRM_SYSFB_CONNECTOR_FUNCS, 164 + .destroy = drm_connector_cleanup, 165 + }; 166 + 167 + static const struct drm_mode_config_funcs corebootdrm_mode_config_funcs = { 168 + DRM_SYSFB_MODE_CONFIG_FUNCS, 169 + }; 170 + 171 + static int corebootdrm_mode_config_init(struct corebootdrm_device *cdev) 172 + { 173 + struct drm_sysfb_device *sysfb = &cdev->sysfb; 174 + struct drm_device *dev = &sysfb->dev; 175 + const struct drm_format_info *format = sysfb->fb_format; 176 + unsigned int width = sysfb->fb_mode.hdisplay; 177 + unsigned int height = sysfb->fb_mode.vdisplay; 178 + struct drm_plane *primary_plane; 179 + struct drm_crtc *crtc; 180 + struct drm_encoder *encoder; 181 + struct drm_connector *connector; 182 + size_t nformats; 183 + int ret; 184 + 185 + ret = drmm_mode_config_init(dev); 186 + if (ret) 187 + return ret; 188 + 189 + dev->mode_config.min_width = width; 190 + dev->mode_config.max_width = max_t(unsigned int, width, DRM_SHADOW_PLANE_MAX_WIDTH); 191 + dev->mode_config.min_height = height; 192 + dev->mode_config.max_height = max_t(unsigned int, height, DRM_SHADOW_PLANE_MAX_HEIGHT); 193 + dev->mode_config.funcs = &corebootdrm_mode_config_funcs; 194 + dev->mode_config.preferred_depth = format->depth; 195 + 196 + /* Primary plane */ 197 + 198 + nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1, 199 + cdev->formats, ARRAY_SIZE(cdev->formats)); 200 + 201 + primary_plane = &cdev->primary_plane; 202 + ret = drm_universal_plane_init(dev, primary_plane, 0, &corebootdrm_primary_plane_funcs, 203 + cdev->formats, nformats, 204 + corebootdrm_primary_plane_format_modifiers, 205 + DRM_PLANE_TYPE_PRIMARY, NULL); 206 + if (ret) 207 + return ret; 208 + drm_plane_helper_add(primary_plane, &corebootdrm_primary_plane_helper_funcs); 209 + drm_plane_enable_fb_damage_clips(primary_plane); 210 + 211 + /* CRTC */ 212 + 213 + crtc = &cdev->crtc; 214 + ret = drm_crtc_init_with_planes(dev, crtc, primary_plane, NULL, 215 + &corebootdrm_crtc_funcs, NULL); 216 + if (ret) 217 + return ret; 218 + drm_crtc_helper_add(crtc, &corebootdrm_crtc_helper_funcs); 219 + 220 + /* Encoder */ 221 + 222 + encoder = &cdev->encoder; 223 + ret = drm_encoder_init(dev, encoder, &corebootdrm_encoder_funcs, 224 + DRM_MODE_ENCODER_NONE, NULL); 225 + if (ret) 226 + return ret; 227 + encoder->possible_crtcs = drm_crtc_mask(crtc); 228 + 229 + /* Connector */ 230 + 231 + connector = &cdev->connector; 232 + ret = drm_connector_init(dev, connector, &corebootdrm_connector_funcs, 233 + DRM_MODE_CONNECTOR_Unknown); 234 + if (ret) 235 + return ret; 236 + drm_connector_helper_add(connector, &corebootdrm_connector_helper_funcs); 237 + drm_connector_set_panel_orientation_with_quirk(connector, 238 + DRM_MODE_PANEL_ORIENTATION_UNKNOWN, 239 + width, height); 240 + 241 + ret = drm_connector_attach_encoder(connector, encoder); 242 + if (ret) 243 + return ret; 244 + 245 + return 0; 246 + } 247 + 248 + /* 249 + * DRM driver 250 + */ 251 + 252 + DEFINE_DRM_GEM_FOPS(corebootdrm_fops); 253 + 254 + static struct drm_driver corebootdrm_drm_driver = { 255 + DRM_GEM_SHMEM_DRIVER_OPS, 256 + DRM_FBDEV_SHMEM_DRIVER_OPS, 257 + .name = DRIVER_NAME, 258 + .desc = DRIVER_DESC, 259 + .major = DRIVER_MAJOR, 260 + .minor = DRIVER_MINOR, 261 + .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, 262 + .fops = &corebootdrm_fops, 263 + }; 264 + 265 + /* 266 + * Coreboot driver 267 + */ 268 + 269 + static int corebootdrm_probe(struct platform_device *pdev) 270 + { 271 + const struct lb_framebuffer *fb = dev_get_platdata(&pdev->dev); 272 + struct corebootdrm_device *cdev; 273 + struct drm_sysfb_device *sysfb; 274 + struct drm_device *dev; 275 + const struct drm_format_info *format; 276 + int width, height, pitch; 277 + resource_size_t size; 278 + phys_addr_t address; 279 + struct resource *res, *mem = NULL; 280 + struct resource aperture; 281 + void __iomem *screen_base; 282 + int ret; 283 + 284 + cdev = devm_drm_dev_alloc(&pdev->dev, &corebootdrm_drm_driver, 285 + struct corebootdrm_device, sysfb.dev); 286 + if (IS_ERR(cdev)) 287 + return PTR_ERR(cdev); 288 + platform_set_drvdata(pdev, cdev); 289 + 290 + sysfb = &cdev->sysfb; 291 + dev = &sysfb->dev; 292 + 293 + if (!fb) { 294 + drm_err(dev, "coreboot framebuffer not found\n"); 295 + return -EINVAL; 296 + } else if (!LB_FRAMEBUFFER_HAS_LFB(fb)) { 297 + drm_err(dev, "coreboot framebuffer entry too small\n"); 298 + return -EINVAL; 299 + } 300 + 301 + /* 302 + * Hardware settings 303 + */ 304 + 305 + format = corebootdrm_get_format_fb(dev, fb); 306 + if (!format) 307 + return -EINVAL; 308 + width = corebootdrm_get_width_fb(dev, fb); 309 + if (width < 0) 310 + return width; 311 + height = corebootdrm_get_height_fb(dev, fb); 312 + if (height < 0) 313 + return height; 314 + pitch = corebootdrm_get_pitch_fb(dev, format, width, fb); 315 + if (pitch < 0) 316 + return pitch; 317 + size = corebootdrm_get_size_fb(dev, height, pitch, fb); 318 + if (!size) 319 + return -EINVAL; 320 + address = corebootdrm_get_address_fb(dev, size, fb); 321 + if (!address) 322 + return -EINVAL; 323 + 324 + sysfb->fb_mode = drm_sysfb_mode(width, height, 0, 0); 325 + sysfb->fb_format = format; 326 + sysfb->fb_pitch = pitch; 327 + 328 + drm_dbg(dev, "display mode={" DRM_MODE_FMT "}\n", DRM_MODE_ARG(&sysfb->fb_mode)); 329 + drm_dbg(dev, "framebuffer format=%p4cc, size=%dx%d, pitch=%d byte\n", 330 + &format->format, width, height, pitch); 331 + 332 + /* 333 + * Memory management 334 + */ 335 + 336 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 337 + if (!res) { 338 + drm_err(dev, "memory resource not found\n"); 339 + return -EINVAL; 340 + } 341 + 342 + mem = devm_request_mem_region(&pdev->dev, res->start, resource_size(res), 343 + dev->driver->name); 344 + if (!mem) { 345 + drm_warn(dev, "could not acquire memory resource at %pr\n", res); 346 + /* 347 + * We cannot make this fatal. Sometimes this comes from magic 348 + * spaces our resource handlers simply don't know about. Use 349 + * the memory resource as-is and try to map that instead. 350 + */ 351 + mem = res; 352 + } 353 + 354 + drm_dbg(dev, "using memory resource at %pr\n", mem); 355 + 356 + aperture = DEFINE_RES_MEM(address, size); 357 + if (!resource_contains(mem, &aperture)) { 358 + drm_err(dev, "framebuffer aperture at invalid memory range %pr\n", &aperture); 359 + return -EINVAL; 360 + } 361 + 362 + ret = devm_aperture_acquire_for_platform_device(pdev, address, size); 363 + if (ret) { 364 + drm_err(dev, "could not acquire framebuffer aperture: %d\n", ret); 365 + return ret; 366 + } 367 + 368 + screen_base = devm_ioremap_wc(&pdev->dev, address, size); 369 + if (!screen_base) 370 + return -ENOMEM; 371 + 372 + iosys_map_set_vaddr_iomem(&sysfb->fb_addr, screen_base); 373 + 374 + /* 375 + * DRM mode setting and registration 376 + */ 377 + 378 + ret = corebootdrm_mode_config_init(cdev); 379 + if (ret) 380 + return ret; 381 + 382 + drm_mode_config_reset(dev); 383 + 384 + ret = drm_dev_register(dev, 0); 385 + if (ret) 386 + return ret; 387 + 388 + drm_client_setup(dev, sysfb->fb_format); 389 + 390 + return 0; 391 + } 392 + 393 + static void corebootdrm_remove(struct platform_device *pdev) 394 + { 395 + struct corebootdrm_device *cdev = platform_get_drvdata(pdev); 396 + struct drm_device *dev = &cdev->sysfb.dev; 397 + 398 + drm_dev_unplug(dev); 399 + } 400 + 401 + static struct platform_driver corebootdrm_platform_driver = { 402 + .driver = { 403 + .name = "coreboot-framebuffer", 404 + }, 405 + .probe = corebootdrm_probe, 406 + .remove = corebootdrm_remove, 407 + }; 408 + 409 + module_platform_driver(corebootdrm_platform_driver); 410 + 411 + MODULE_DESCRIPTION(DRIVER_DESC); 412 + MODULE_LICENSE("GPL");
+8
include/linux/coreboot.h
··· 13 13 #define _LINUX_COREBOOT_H 14 14 15 15 #include <linux/compiler_attributes.h> 16 + #include <linux/stddef.h> 16 17 #include <linux/types.h> 17 18 18 19 typedef __aligned(4) u64 cb_u64; ··· 66 65 u8 reserved_mask_pos; 67 66 u8 reserved_mask_size; 68 67 }; 68 + 69 + /* 70 + * True if the coreboot-provided data is large enough to hold information 71 + * on the linear framebuffer. False otherwise. 72 + */ 73 + #define LB_FRAMEBUFFER_HAS_LFB(__fb) \ 74 + ((__fb)->size >= offsetofend(struct lb_framebuffer, reserved_mask_size)) 69 75 70 76 #endif /* _LINUX_COREBOOT_H */