2019-05-29 07:18:01 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-01-24 19:41:20 -06:00
|
|
|
/*
|
|
|
|
* framebuffer-coreboot.c
|
|
|
|
*
|
|
|
|
* Memory based framebuffer accessed through coreboot table.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2013 David Herrmann <dh.herrmann@gmail.com>
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
* Copyright 2017 Samuel Holland <samuel@sholland.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_data/simplefb.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
#include "coreboot_table.h"
|
|
|
|
|
|
|
|
#define CB_TAG_FRAMEBUFFER 0x12
|
|
|
|
|
|
|
|
static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
|
|
|
|
|
|
|
|
static int framebuffer_probe(struct coreboot_device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 length;
|
|
|
|
struct lb_framebuffer *fb = &dev->framebuffer;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct resource res;
|
|
|
|
struct simplefb_platform_data pdata = {
|
|
|
|
.width = fb->x_resolution,
|
|
|
|
.height = fb->y_resolution,
|
|
|
|
.stride = fb->bytes_per_line,
|
|
|
|
.format = NULL,
|
|
|
|
};
|
|
|
|
|
firmware: coreboot: framebuffer: Avoid invalid zero physical address
On ARM64 systems coreboot defers framebuffer allocation to its payload,
to be done by a libpayload function call. In this case, coreboot tables
still include a framebuffer entry with display format details, but the
physical address field is set to zero (as in [1], for example).
Unfortunately, this field is not automatically updated when the
framebuffer is initialized through libpayload, citing that doing so
would invalidate checksums over the entire coreboot table [2].
This can be observed on ARM64 Chromebooks with stock firmware. On a
Google Kevin (RK3399), trying to use coreboot framebuffer driver as
built-in to the kernel results in a benign error. But on Google Hana
(MT8173) and Google Cozmo (MT8183) it causes a hang.
When the framebuffer physical address field in the coreboot table is
zero, we have no idea where coreboot initialized a framebuffer, or even
if it did. Instead of trying to set up a framebuffer located at zero,
return ENODEV to indicate that there isn't one.
[1] https://review.coreboot.org/c/coreboot/+/17109
[2] https://review.coreboot.org/c/coreboot/+/8797
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Link: https://lore.kernel.org/r/20231108182625.46563-1-alpernebiyasak@gmail.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
2023-11-08 21:25:13 +03:00
|
|
|
if (!fb->physical_address)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2018-01-24 19:41:20 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); ++i) {
|
|
|
|
if (fb->bits_per_pixel == formats[i].bits_per_pixel &&
|
|
|
|
fb->red_mask_pos == formats[i].red.offset &&
|
|
|
|
fb->red_mask_size == formats[i].red.length &&
|
|
|
|
fb->green_mask_pos == formats[i].green.offset &&
|
|
|
|
fb->green_mask_size == formats[i].green.length &&
|
|
|
|
fb->blue_mask_pos == formats[i].blue.offset &&
|
2023-01-22 22:04:31 +03:00
|
|
|
fb->blue_mask_size == formats[i].blue.length)
|
2018-01-24 19:41:20 -06:00
|
|
|
pdata.format = formats[i].name;
|
|
|
|
}
|
|
|
|
if (!pdata.format)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
memset(&res, 0, sizeof(res));
|
|
|
|
res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
|
|
|
|
res.name = "Coreboot Framebuffer";
|
|
|
|
res.start = fb->physical_address;
|
|
|
|
length = PAGE_ALIGN(fb->y_resolution * fb->bytes_per_line);
|
|
|
|
res.end = res.start + length - 1;
|
|
|
|
if (res.end <= res.start)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pdev = platform_device_register_resndata(&dev->dev,
|
|
|
|
"simple-framebuffer", 0,
|
|
|
|
&res, 1, &pdata,
|
|
|
|
sizeof(pdata));
|
|
|
|
if (IS_ERR(pdev))
|
|
|
|
pr_warn("coreboot: could not register framebuffer\n");
|
|
|
|
else
|
|
|
|
dev_set_drvdata(&dev->dev, pdev);
|
|
|
|
|
|
|
|
return PTR_ERR_OR_ZERO(pdev);
|
|
|
|
}
|
|
|
|
|
2021-01-26 22:53:39 +01:00
|
|
|
static void framebuffer_remove(struct coreboot_device *dev)
|
2018-01-24 19:41:20 -06:00
|
|
|
{
|
|
|
|
struct platform_device *pdev = dev_get_drvdata(&dev->dev);
|
|
|
|
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
}
|
|
|
|
|
2024-02-12 09:50:07 -05:00
|
|
|
static const struct coreboot_device_id framebuffer_ids[] = {
|
|
|
|
{ .tag = CB_TAG_FRAMEBUFFER },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(coreboot, framebuffer_ids);
|
|
|
|
|
2018-01-24 19:41:20 -06:00
|
|
|
static struct coreboot_driver framebuffer_driver = {
|
|
|
|
.probe = framebuffer_probe,
|
|
|
|
.remove = framebuffer_remove,
|
|
|
|
.drv = {
|
|
|
|
.name = "framebuffer",
|
|
|
|
},
|
2024-02-12 09:50:07 -05:00
|
|
|
.id_table = framebuffer_ids,
|
2018-01-24 19:41:20 -06:00
|
|
|
};
|
2019-05-10 11:01:47 -07:00
|
|
|
module_coreboot_driver(framebuffer_driver);
|
2018-01-24 19:41:20 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>");
|
2024-06-05 15:07:21 -07:00
|
|
|
MODULE_DESCRIPTION("Memory based framebuffer accessed through coreboot table");
|
2018-01-24 19:41:20 -06:00
|
|
|
MODULE_LICENSE("GPL");
|