2019-05-27 08:55:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* fbsysfs.c - framebuffer device class and attributes
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 James Simmons <jsimmons@infradead.org>
|
|
|
|
*/
|
|
|
|
|
2023-06-13 13:07:08 +02:00
|
|
|
#include <linux/console.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/fb.h>
|
2019-05-28 11:02:56 +02:00
|
|
|
#include <linux/fbcon.h>
|
2023-06-13 13:07:09 +02:00
|
|
|
#include <linux/major.h>
|
|
|
|
|
|
|
|
#include "fb_internal.h"
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-10-03 01:14:50 -07:00
|
|
|
#define FB_SYSFS_FLAG_ATTR 1
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var->activate |= FB_ACTIVATE_FORCE;
|
2011-01-25 15:07:35 -08:00
|
|
|
console_lock();
|
2022-04-05 23:03:23 +02:00
|
|
|
lock_fb_info(fb_info);
|
2005-04-16 15:20:36 -07:00
|
|
|
err = fb_set_var(fb_info, var);
|
2020-07-30 19:47:14 +09:00
|
|
|
if (!err)
|
|
|
|
fbcon_update_vcs(fb_info, var->activate & FB_ACTIVATE_ALL);
|
2022-04-05 23:03:23 +02:00
|
|
|
unlock_fb_info(fb_info);
|
2011-01-25 15:07:35 -08:00
|
|
|
console_unlock();
|
2005-04-16 15:20:36 -07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mode_string(char *buf, unsigned int offset,
|
|
|
|
const struct fb_videomode *mode)
|
|
|
|
{
|
|
|
|
char m = 'U';
|
2006-06-26 00:27:00 -07:00
|
|
|
char v = 'p';
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
if (mode->flag & FB_MODE_IS_DETAILED)
|
|
|
|
m = 'D';
|
|
|
|
if (mode->flag & FB_MODE_IS_VESA)
|
|
|
|
m = 'V';
|
|
|
|
if (mode->flag & FB_MODE_IS_STANDARD)
|
|
|
|
m = 'S';
|
2006-06-26 00:27:00 -07:00
|
|
|
|
|
|
|
if (mode->vmode & FB_VMODE_INTERLACED)
|
|
|
|
v = 'i';
|
|
|
|
if (mode->vmode & FB_VMODE_DOUBLE)
|
|
|
|
v = 'd';
|
|
|
|
|
|
|
|
return snprintf(&buf[offset], PAGE_SIZE - offset, "%c:%dx%d%c-%d\n",
|
|
|
|
m, mode->xres, mode->yres, v, mode->refresh);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_mode(struct device *device, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
char mstr[100];
|
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
struct fb_modelist *modelist;
|
|
|
|
struct fb_videomode *mode;
|
|
|
|
size_t i;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&var, 0, sizeof(var));
|
|
|
|
|
2023-08-23 15:21:49 +08:00
|
|
|
list_for_each_entry(modelist, &fb_info->modelist, list) {
|
2005-04-16 15:20:36 -07:00
|
|
|
mode = &modelist->mode;
|
|
|
|
i = mode_string(mstr, 0, mode);
|
|
|
|
if (strncmp(mstr, buf, max(count, i)) == 0) {
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
fb_videomode_to_var(&var, mode);
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
fb_info->mode = mode;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_mode(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
if (!fb_info->mode)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return mode_string(buf, 0, fb_info->mode);
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_modes(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
LIST_HEAD(old_list);
|
|
|
|
int i = count / sizeof(struct fb_videomode);
|
|
|
|
|
|
|
|
if (i * sizeof(struct fb_videomode) != count)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-25 15:07:35 -08:00
|
|
|
console_lock();
|
2019-05-28 11:02:44 +02:00
|
|
|
lock_fb_info(fb_info);
|
2013-11-05 18:00:57 +08:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
list_splice(&fb_info->modelist, &old_list);
|
2007-02-12 00:55:19 -08:00
|
|
|
fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
|
2005-04-16 15:20:36 -07:00
|
|
|
&fb_info->modelist);
|
|
|
|
if (fb_new_modelist(fb_info)) {
|
|
|
|
fb_destroy_modelist(&fb_info->modelist);
|
|
|
|
list_splice(&old_list, &fb_info->modelist);
|
|
|
|
} else
|
|
|
|
fb_destroy_modelist(&old_list);
|
|
|
|
|
2013-01-25 10:28:15 +10:00
|
|
|
unlock_fb_info(fb_info);
|
2013-11-05 18:00:57 +08:00
|
|
|
console_unlock();
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_modes(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
unsigned int i;
|
|
|
|
struct fb_modelist *modelist;
|
|
|
|
const struct fb_videomode *mode;
|
|
|
|
|
|
|
|
i = 0;
|
2023-08-23 15:21:49 +08:00
|
|
|
list_for_each_entry(modelist, &fb_info->modelist, list) {
|
2005-04-16 15:20:36 -07:00
|
|
|
mode = &modelist->mode;
|
|
|
|
i += mode_string(buf, i, mode);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_bpp(struct device *device, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char ** last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.bits_per_pixel = simple_strtoul(buf, last, 0);
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_bpp(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d\n", fb_info->var.bits_per_pixel);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_rotate(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-11-08 21:39:15 -08:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-11-08 21:39:15 -08:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char **last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.rotate = simple_strtoul(buf, last, 0);
|
|
|
|
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_rotate(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-11-08 21:39:15 -08:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-11-08 21:39:15 -08:00
|
|
|
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d\n", fb_info->var.rotate);
|
2005-11-08 21:39:15 -08:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_virtual(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char *last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.xres_virtual = simple_strtoul(buf, &last, 0);
|
|
|
|
last++;
|
|
|
|
if (last - buf >= count)
|
|
|
|
return -EINVAL;
|
|
|
|
var.yres_virtual = simple_strtoul(last, &last, 0);
|
|
|
|
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_virtual(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d,%d\n", fb_info->var.xres_virtual,
|
2005-06-13 15:52:36 -07:00
|
|
|
fb_info->var.yres_virtual);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_stride(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-10-24 21:46:21 +01:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d\n", fb_info->fix.line_length);
|
2005-10-24 21:46:21 +01:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_blank(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
char *last = NULL;
|
2019-05-28 11:02:56 +02:00
|
|
|
int err, arg;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2019-05-28 11:02:56 +02:00
|
|
|
arg = simple_strtoul(buf, &last, 0);
|
2011-01-25 15:07:35 -08:00
|
|
|
console_lock();
|
2019-05-28 11:02:56 +02:00
|
|
|
err = fb_blank(fb_info, arg);
|
|
|
|
/* might again call into fb_blank */
|
|
|
|
fbcon_fb_blanked(fb_info, arg);
|
2011-01-25 15:07:35 -08:00
|
|
|
console_unlock();
|
2005-04-16 15:20:36 -07:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2025-03-21 10:53:55 +01:00
|
|
|
static ssize_t show_blank(struct device *device, struct device_attribute *attr, char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2025-03-21 10:53:55 +01:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
|
|
|
|
|
|
|
return sysfs_emit(buf, "%d\n", fb_info->blank);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_console(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_console(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_cursor(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_cursor(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_pan(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 15:20:36 -07:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char *last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.xoffset = simple_strtoul(buf, &last, 0);
|
|
|
|
last++;
|
|
|
|
if (last - buf >= count)
|
|
|
|
return -EINVAL;
|
|
|
|
var.yoffset = simple_strtoul(last, &last, 0);
|
|
|
|
|
2011-01-25 15:07:35 -08:00
|
|
|
console_lock();
|
2005-04-16 15:20:36 -07:00
|
|
|
err = fb_pan_display(fb_info, &var);
|
2011-01-25 15:07:35 -08:00
|
|
|
console_unlock();
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_pan(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d,%d\n", fb_info->var.xoffset,
|
2007-05-08 00:37:30 -07:00
|
|
|
fb_info->var.yoffset);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_name(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-07-30 23:49:54 +01:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-07-30 23:49:54 +01:00
|
|
|
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%s\n", fb_info->fix.id);
|
2005-07-30 23:49:54 +01:00
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_fbstate(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2006-01-09 20:53:01 -08:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-01-09 20:53:01 -08:00
|
|
|
u32 state;
|
|
|
|
char *last = NULL;
|
|
|
|
|
|
|
|
state = simple_strtoul(buf, &last, 0);
|
|
|
|
|
2011-01-25 15:07:35 -08:00
|
|
|
console_lock();
|
2019-05-28 11:02:44 +02:00
|
|
|
lock_fb_info(fb_info);
|
2013-11-05 18:00:57 +08:00
|
|
|
|
2006-01-09 20:53:01 -08:00
|
|
|
fb_set_suspend(fb_info, (int)state);
|
2013-11-05 18:00:57 +08:00
|
|
|
|
fb: avoid possible deadlock caused by fb_set_suspend
A lock ordering issue can cause deadlocks: in framebuffer/console code,
all needed struct fb_info locks are taken before acquire_console_sem(),
in places which need to take console semaphore.
But fb_set_suspend is always called with console semaphore held, and
inside it we call lock_fb_info which gets the fb_info lock, inverse
locking order of what the rest of the code does. This causes a real
deadlock issue, when we write to state fb sysfs attribute (which calls
fb_set_suspend) while a framebuffer is being unregistered by
remove_conflicting_framebuffers, as can be shown by following show
blocked state trace on a test program which loads i915 and runs another
forked processes writing to state attribute:
Test process with semaphore held and trying to get fb_info lock:
..
fb-test2 D 0000000000000000 0 237 228 0x00000000
ffff8800774f3d68 0000000000000082 00000000000135c0 00000000000135c0
ffff880000000000 ffff8800774f3fd8 ffff8800774f3fd8 ffff880076ee4530
00000000000135c0 ffff8800774f3fd8 ffff8800774f2000 00000000000135c0
Call Trace:
[<ffffffff8141287a>] __mutex_lock_slowpath+0x11a/0x1e0
[<ffffffff814142f2>] ? _raw_spin_lock_irq+0x22/0x40
[<ffffffff814123d3>] mutex_lock+0x23/0x50
[<ffffffff8125dfc5>] lock_fb_info+0x25/0x60
[<ffffffff8125e3f0>] fb_set_suspend+0x20/0x80
[<ffffffff81263e2f>] store_fbstate+0x4f/0x70
[<ffffffff812e7f70>] dev_attr_store+0x20/0x30
[<ffffffff811c46b4>] sysfs_write_file+0xd4/0x160
[<ffffffff81155a26>] vfs_write+0xc6/0x190
[<ffffffff81155d51>] sys_write+0x51/0x90
[<ffffffff8100c012>] system_call_fastpath+0x16/0x1b
..
modprobe process stalled because has the fb_info lock (got inside
unregister_framebuffer) but waiting for the semaphore held by the
test process which is waiting to get the fb_info lock:
..
modprobe D 0000000000000000 0 230 218 0x00000000
ffff880077a4d618 0000000000000082 0000000000000001 0000000000000001
ffff880000000000 ffff880077a4dfd8 ffff880077a4dfd8 ffff8800775a2e20
00000000000135c0 ffff880077a4dfd8 ffff880077a4c000 00000000000135c0
Call Trace:
[<ffffffff81411fe5>] schedule_timeout+0x215/0x310
[<ffffffff81058051>] ? get_parent_ip+0x11/0x50
[<ffffffff814130dd>] __down+0x6d/0xb0
[<ffffffff81089f71>] down+0x41/0x50
[<ffffffff810629ac>] acquire_console_sem+0x2c/0x50
[<ffffffff812ca53d>] unbind_con_driver+0xad/0x2d0
[<ffffffff8126f5f7>] fbcon_event_notify+0x457/0x890
[<ffffffff814144ff>] ? _raw_spin_unlock_irqrestore+0x1f/0x50
[<ffffffff81058051>] ? get_parent_ip+0x11/0x50
[<ffffffff8141836d>] notifier_call_chain+0x4d/0x70
[<ffffffff8108a3b8>] __blocking_notifier_call_chain+0x58/0x80
[<ffffffff8108a3f6>] blocking_notifier_call_chain+0x16/0x20
[<ffffffff8125dabb>] fb_notifier_call_chain+0x1b/0x20
[<ffffffff8125e6ac>] unregister_framebuffer+0x7c/0x130
[<ffffffff8125e8b3>] remove_conflicting_framebuffers+0x153/0x180
[<ffffffff8125eef3>] register_framebuffer+0x93/0x2c0
[<ffffffffa0331112>] drm_fb_helper_single_fb_probe+0x252/0x2f0 [drm_kms_helper]
[<ffffffffa03314a3>] drm_fb_helper_initial_config+0x2f3/0x6d0 [drm_kms_helper]
[<ffffffffa03318dd>] ? drm_fb_helper_single_add_all_connectors+0x5d/0x1c0 [drm_kms_helper]
[<ffffffffa037b588>] intel_fbdev_init+0xa8/0x160 [i915]
[<ffffffffa0343d74>] i915_driver_load+0x854/0x12b0 [i915]
[<ffffffffa02f0e7e>] drm_get_pci_dev+0x19e/0x360 [drm]
[<ffffffff8141821d>] ? sub_preempt_count+0x9d/0xd0
[<ffffffffa0386f91>] i915_pci_probe+0x15/0x17 [i915]
[<ffffffff8124481f>] local_pci_probe+0x5f/0xd0
[<ffffffff81244f89>] pci_device_probe+0x119/0x120
[<ffffffff812eccaa>] ? driver_sysfs_add+0x7a/0xb0
[<ffffffff812ed003>] driver_probe_device+0xa3/0x290
[<ffffffff812ed1f0>] ? __driver_attach+0x0/0xb0
[<ffffffff812ed29b>] __driver_attach+0xab/0xb0
[<ffffffff812ed1f0>] ? __driver_attach+0x0/0xb0
[<ffffffff812ebd3e>] bus_for_each_dev+0x5e/0x90
[<ffffffff812ecc2e>] driver_attach+0x1e/0x20
[<ffffffff812ec6f2>] bus_add_driver+0xe2/0x320
[<ffffffffa03aa000>] ? i915_init+0x0/0x96 [i915]
[<ffffffff812ed536>] driver_register+0x76/0x140
[<ffffffffa03aa000>] ? i915_init+0x0/0x96 [i915]
[<ffffffff81245216>] __pci_register_driver+0x56/0xd0
[<ffffffffa02f1264>] drm_pci_init+0xe4/0xf0 [drm]
[<ffffffffa03aa000>] ? i915_init+0x0/0x96 [i915]
[<ffffffffa02e84a8>] drm_init+0x58/0x70 [drm]
[<ffffffffa03aa094>] i915_init+0x94/0x96 [i915]
[<ffffffff81002194>] do_one_initcall+0x44/0x190
[<ffffffff810a066b>] sys_init_module+0xcb/0x210
[<ffffffff8100c012>] system_call_fastpath+0x16/0x1b
..
fb-test2 which reproduces above is available on kernel.org bug #26232.
To solve this issue, avoid calling lock_fb_info inside fb_set_suspend,
and move it out to where needed (callers of fb_set_suspend must call
lock_fb_info before if needed). So far, the only place which needs to
call lock_fb_info is store_fbstate, all other places which calls
fb_set_suspend are suspend/resume hooks that should not need the lock as
they should be run only when processes are already frozen in
suspend/resume.
References: https://bugzilla.kernel.org/show_bug.cgi?id=26232
Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: stable@kernel.org
2011-06-17 19:02:39 +00:00
|
|
|
unlock_fb_info(fb_info);
|
2013-11-05 18:00:57 +08:00
|
|
|
console_unlock();
|
2006-01-09 20:53:01 -08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_fbstate(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2006-01-09 20:53:01 -08:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2021-10-12 20:28:00 -07:00
|
|
|
return sysfs_emit(buf, "%d\n", fb_info->state);
|
2006-01-09 20:53:01 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 19:13:07 +01:00
|
|
|
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t store_bl_curve(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2006-06-25 05:47:08 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-06-25 05:47:08 -07:00
|
|
|
u8 tmp_curve[FB_BACKLIGHT_LEVELS];
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-09-25 16:25:07 -07:00
|
|
|
/* Some drivers don't use framebuffer_alloc(), but those also
|
|
|
|
* don't have backlights.
|
|
|
|
*/
|
|
|
|
if (!fb_info || !fb_info->bl_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-06-25 05:47:08 -07:00
|
|
|
if (count != (FB_BACKLIGHT_LEVELS / 8 * 24))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < (FB_BACKLIGHT_LEVELS / 8); ++i)
|
|
|
|
if (sscanf(&buf[i * 24],
|
|
|
|
"%2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx\n",
|
|
|
|
&tmp_curve[i * 8 + 0],
|
|
|
|
&tmp_curve[i * 8 + 1],
|
|
|
|
&tmp_curve[i * 8 + 2],
|
|
|
|
&tmp_curve[i * 8 + 3],
|
|
|
|
&tmp_curve[i * 8 + 4],
|
|
|
|
&tmp_curve[i * 8 + 5],
|
|
|
|
&tmp_curve[i * 8 + 6],
|
|
|
|
&tmp_curve[i * 8 + 7]) != 8)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* If there has been an error in the input data, we won't
|
|
|
|
* reach this loop.
|
|
|
|
*/
|
2007-02-10 14:10:33 +00:00
|
|
|
mutex_lock(&fb_info->bl_curve_mutex);
|
2006-06-25 05:47:08 -07:00
|
|
|
for (i = 0; i < FB_BACKLIGHT_LEVELS; ++i)
|
|
|
|
fb_info->bl_curve[i] = tmp_curve[i];
|
2007-02-10 14:10:33 +00:00
|
|
|
mutex_unlock(&fb_info->bl_curve_mutex);
|
2006-06-25 05:47:08 -07:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
static ssize_t show_bl_curve(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2006-06-25 05:47:08 -07:00
|
|
|
{
|
2006-09-14 07:30:59 -07:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-06-25 05:47:08 -07:00
|
|
|
ssize_t len = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-09-25 16:25:07 -07:00
|
|
|
/* Some drivers don't use framebuffer_alloc(), but those also
|
|
|
|
* don't have backlights.
|
|
|
|
*/
|
|
|
|
if (!fb_info || !fb_info->bl_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2007-02-10 14:10:33 +00:00
|
|
|
mutex_lock(&fb_info->bl_curve_mutex);
|
2006-06-25 05:47:08 -07:00
|
|
|
for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8)
|
2015-08-24 22:54:21 +03:00
|
|
|
len += scnprintf(&buf[len], PAGE_SIZE - len, "%8ph\n",
|
2014-09-05 17:47:35 +03:00
|
|
|
fb_info->bl_curve + i);
|
2007-02-10 14:10:33 +00:00
|
|
|
mutex_unlock(&fb_info->bl_curve_mutex);
|
2006-06-25 05:47:08 -07:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-12 19:43:35 -04:00
|
|
|
/* When cmap is added back in it should be a binary attribute
|
|
|
|
* not a text one. Consideration should also be given to converting
|
|
|
|
* fbdev to use configfs instead of sysfs */
|
2025-02-20 17:59:35 +08:00
|
|
|
static DEVICE_ATTR(bits_per_pixel, 0644, show_bpp, store_bpp);
|
|
|
|
static DEVICE_ATTR(blank, 0644, show_blank, store_blank);
|
|
|
|
static DEVICE_ATTR(console, 0644, show_console, store_console);
|
|
|
|
static DEVICE_ATTR(cursor, 0644, show_cursor, store_cursor);
|
|
|
|
static DEVICE_ATTR(mode, 0644, show_mode, store_mode);
|
|
|
|
static DEVICE_ATTR(modes, 0644, show_modes, store_modes);
|
|
|
|
static DEVICE_ATTR(pan, 0644, show_pan, store_pan);
|
|
|
|
static DEVICE_ATTR(virtual_size, 0644, show_virtual, store_virtual);
|
|
|
|
static DEVICE_ATTR(name, 0444, show_name, NULL);
|
|
|
|
static DEVICE_ATTR(stride, 0444, show_stride, NULL);
|
|
|
|
static DEVICE_ATTR(rotate, 0644, show_rotate, store_rotate);
|
|
|
|
static DEVICE_ATTR(state, 0644, show_fbstate, store_fbstate);
|
2018-12-20 19:13:07 +01:00
|
|
|
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
|
2025-02-20 17:59:35 +08:00
|
|
|
static DEVICE_ATTR(bl_curve, 0644, show_bl_curve, store_bl_curve);
|
2006-06-25 05:47:08 -07:00
|
|
|
#endif
|
2025-02-20 17:59:35 +08:00
|
|
|
|
|
|
|
static struct attribute *fb_device_attrs[] = {
|
|
|
|
&dev_attr_bits_per_pixel.attr,
|
|
|
|
&dev_attr_blank.attr,
|
|
|
|
&dev_attr_console.attr,
|
|
|
|
&dev_attr_cursor.attr,
|
|
|
|
&dev_attr_mode.attr,
|
|
|
|
&dev_attr_modes.attr,
|
|
|
|
&dev_attr_pan.attr,
|
|
|
|
&dev_attr_virtual_size.attr,
|
|
|
|
&dev_attr_name.attr,
|
|
|
|
&dev_attr_stride.attr,
|
|
|
|
&dev_attr_rotate.attr,
|
|
|
|
&dev_attr_state.attr,
|
|
|
|
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
|
|
|
|
&dev_attr_bl_curve.attr,
|
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group fb_device_attr_group = {
|
|
|
|
.attrs = fb_device_attrs,
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
2023-06-13 13:07:09 +02:00
|
|
|
static int fb_init_device(struct fb_info *fb_info)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2025-02-20 17:59:35 +08:00
|
|
|
int ret;
|
2006-10-03 01:14:50 -07:00
|
|
|
|
2006-09-14 07:30:59 -07:00
|
|
|
dev_set_drvdata(fb_info->dev, fb_info);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-10-03 01:14:50 -07:00
|
|
|
fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
|
|
|
|
|
2025-02-20 17:59:35 +08:00
|
|
|
ret = device_add_group(fb_info->dev, &fb_device_attr_group);
|
|
|
|
if (ret)
|
2006-10-03 01:14:50 -07:00
|
|
|
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-13 13:07:09 +02:00
|
|
|
static void fb_cleanup_device(struct fb_info *fb_info)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-10-03 01:14:50 -07:00
|
|
|
if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
|
2025-02-20 17:59:35 +08:00
|
|
|
device_remove_group(fb_info->dev, &fb_device_attr_group);
|
2006-10-03 01:14:50 -07:00
|
|
|
|
|
|
|
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2023-06-13 13:07:09 +02:00
|
|
|
|
|
|
|
int fb_device_create(struct fb_info *fb_info)
|
|
|
|
{
|
|
|
|
int node = fb_info->node;
|
|
|
|
dev_t devt = MKDEV(FB_MAJOR, node);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fb_info->dev = device_create(fb_class, fb_info->device, devt, NULL, "fb%d", node);
|
|
|
|
if (IS_ERR(fb_info->dev)) {
|
|
|
|
/* Not fatal */
|
|
|
|
ret = PTR_ERR(fb_info->dev);
|
|
|
|
pr_warn("Unable to create device for framebuffer %d; error %d\n", node, ret);
|
|
|
|
fb_info->dev = NULL;
|
|
|
|
} else {
|
|
|
|
fb_init_device(fb_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fb_device_destroy(struct fb_info *fb_info)
|
|
|
|
{
|
|
|
|
dev_t devt = MKDEV(FB_MAJOR, fb_info->node);
|
|
|
|
|
|
|
|
if (!fb_info->dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fb_cleanup_device(fb_info);
|
|
|
|
device_destroy(fb_class, devt);
|
|
|
|
fb_info->dev = NULL;
|
|
|
|
}
|