genunifont: fix ftell() error checking
[platform/upstream/kmscon.git] / fblog / 0006-fblog-allow-enabling-disabling-fblog-on-runtime.patch
1 From cab17dccb6026f9f33717db72f528f3b84d7393f Mon Sep 17 00:00:00 2001
2 From: David Herrmann <dh.herrmann@googlemail.com>
3 Date: Sat, 16 Jun 2012 23:07:50 +0200
4 Subject: [PATCH 06/10] fblog: allow enabling/disabling fblog on runtime
5
6 A sysfs file called "active" can be used to enable and disable fblog on
7 runtime. For example, the init-process can run "echo '0' >.../active"
8 after booting the system. This will allow other applications like X11 to
9 use the graphics subsystem. During shutdown, we can write '1' to get
10 system messages again.
11
12 When disabling fblog, we remove all framebuffers and will prevent new
13 hotplugged framebuffers from being added. When enabling fblog again, we
14 rescan the system for all framebuffers and resume operating.
15
16 The sysfs file is not registered, yet, as we do not have a "struct device"
17 yet. This will follow shortly, though.
18
19 Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
20 ---
21  Documentation/ABI/testing/sysfs-fblog |    9 ++++++
22  drivers/video/console/fblog.c         |   49 +++++++++++++++++++++++++++++++++
23  2 files changed, 58 insertions(+)
24  create mode 100644 Documentation/ABI/testing/sysfs-fblog
25
26 diff --git a/Documentation/ABI/testing/sysfs-fblog b/Documentation/ABI/testing/sysfs-fblog
27 new file mode 100644
28 index 0000000..596393c
29 --- /dev/null
30 +++ b/Documentation/ABI/testing/sysfs-fblog
31 @@ -0,0 +1,9 @@
32 +What:          /sys/class/graphics/fblog/active
33 +Date:          June 2012
34 +KernelVersion: 3.6
35 +Contact:       David Herrmann <dh.herrmann@googlemail.com>
36 +Description:   Enable/Disable fblog. When setting this to 0, fblog will stop
37 +               writing to framebuffers and other applications can use the
38 +               graphics subsystem. When setting this to 1, fblog will rescan
39 +               the system for all framebuffers and resume drawing the kernel
40 +               log onto all framebuffers.
41 diff --git a/drivers/video/console/fblog.c b/drivers/video/console/fblog.c
42 index 7d4032e..9b05c56 100644
43 --- a/drivers/video/console/fblog.c
44 +++ b/drivers/video/console/fblog.c
45 @@ -92,6 +92,7 @@ struct fblog_fb {
46  };
47  
48  static struct fblog_fb *fblog_fbs[FB_MAX];
49 +static atomic_t fblog_active;
50  
51  static void fblog_buf_resize(struct fblog_buf *buf, size_t width,
52                              size_t height)
53 @@ -338,6 +339,8 @@ static void fblog_register(struct fb_info *info)
54         const struct fb_videomode *mode;
55         unsigned int width, height;
56  
57 +       if (!atomic_read(&fblog_active))
58 +               return;
59         if (!info || info->node < 0 || info->node >= FB_MAX)
60                 return;
61         if (!registered_fb[info->node] || fblog_fbs[info->node])
62 @@ -428,6 +431,52 @@ static void fblog_refresh(struct fblog_fb *fb)
63         fblog_redraw(fb);
64  }
65  
66 +static void fblog_activate(void)
67 +{
68 +       if (atomic_read(&fblog_active))
69 +               return;
70 +
71 +       atomic_set(&fblog_active, 1);
72 +       fblog_register_all();
73 +}
74 +
75 +static void fblog_deactivate(void)
76 +{
77 +       if (!atomic_read(&fblog_active))
78 +               return;
79 +
80 +       atomic_set(&fblog_active, 0);
81 +       fblog_unregister_all();
82 +}
83 +
84 +static ssize_t fblog_dev_active_show(struct device *dev,
85 +                                    struct device_attribute *attr,
86 +                                    char *buf)
87 +{
88 +       return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&fblog_active));
89 +}
90 +
91 +static ssize_t fblog_dev_active_store(struct device *dev,
92 +                                     struct device_attribute *attr,
93 +                                     const char *buf,
94 +                                     size_t count)
95 +{
96 +       unsigned long num;
97 +
98 +       num = simple_strtoul(buf, NULL, 10);
99 +       console_lock();
100 +       if (num)
101 +               fblog_activate();
102 +       else
103 +               fblog_deactivate();
104 +       console_unlock();
105 +
106 +       return count;
107 +}
108 +
109 +static DEVICE_ATTR(active, S_IRUGO | S_IWUSR | S_IWGRP, fblog_dev_active_show,
110 +                  fblog_dev_active_store);
111 +
112  static int __init fblog_init(void)
113  {
114         return 0;
115 -- 
116 1.7.10.4
117