Skip to content

Commit e2d4e5d

Browse files
committed
Merge pull request #6 from jctemkin/master
Add DPMS support to DRM plugin, and add according RPCs. [OXT-47]
2 parents 0ea6c4d + aac53d5 commit e2d4e5d

10 files changed

Lines changed: 143 additions & 7 deletions

File tree

libsurfman/src/surfman-head.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,14 @@ extern "C"
611611
*/
612612
void (*restore_brightness)(struct surfman_plugin *plugin);
613613

614+
/*
615+
* dpms_on : power screen on
616+
*/
617+
void (*dpms_on)(struct surfman_plugin *plugin);
618+
619+
/*
620+
* dpms_off : power screen off
621+
*/
622+
void (*dpms_off)(struct surfman_plugin *plugin);
623+
614624
} surfman_plugin_t;

libsurfman/version-micro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1
1+
2

plugins/drm/src/drm-plugin.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,52 @@ INTERNAL void drmp_restore_brightness(surfman_plugin_t *plugin)
470470
backlight_restore(backlight);
471471
}
472472

473+
INTERNAL void drmp_dpms_on(surfman_plugin_t *plugin)
474+
{
475+
(void) plugin;
476+
struct drm_device *d;
477+
struct drm_monitor *m;
478+
int rc;
479+
480+
DRM_DBG("%s, dpms on", __FUNCTION__);
481+
482+
list_for_each_entry(d, &devices, l) {
483+
drm_device_set_master(d);
484+
list_for_each_entry(m, &(d->monitors), l_dev) {
485+
rc = drm_monitor_dpms_on(m);
486+
if (rc) {
487+
DRM_DBG("%s, dpms on failed for monitor at conn=%d, enc=%d, "
488+
"crtc=%d - %s", __FUNCTION__, m->connector, m->encoder,
489+
m->crtc, strerror(rc));
490+
}
491+
}
492+
drm_device_drop_master(d);
493+
}
494+
}
495+
496+
INTERNAL void drmp_dpms_off(surfman_plugin_t *plugin)
497+
{
498+
(void) plugin;
499+
struct drm_device *d;
500+
struct drm_monitor *m;
501+
int rc;
502+
503+
DRM_DBG("%s, dpms off", __FUNCTION__);
504+
505+
list_for_each_entry(d, &devices, l) {
506+
drm_device_set_master(d);
507+
list_for_each_entry(m, &(d->monitors), l_dev) {
508+
rc = drm_monitor_dpms_off(m);
509+
if (rc) {
510+
DRM_DBG("%s, dpms off failed for monitor at conn=%d, enc=%d, "
511+
"crtc=%d - %s", __FUNCTION__, m->connector, m->encoder,
512+
m->crtc, strerror(rc));
513+
}
514+
}
515+
drm_device_drop_master(d);
516+
}
517+
}
518+
473519
#define OPTIONAL (NULL)
474520
#define REQUIRED ((void*)0xDEADBEEF)
475521
/* Surfman plugin interface. */
@@ -504,6 +550,11 @@ surfman_plugin_t surfman_plugin = {
504550
.increase_brightness = drmp_increase_brightness,
505551
.decrease_brightness = drmp_decrease_brightness,
506552
.restore_brightness = drmp_restore_brightness,
553+
554+
/* DPMS mode management. */
555+
.dpms_on = drmp_dpms_on,
556+
.dpms_off = drmp_dpms_off,
557+
507558
.options = {
508559
64, /* libDRM requires a 64 bytes alignment (not 64bit ;). */
509560
0 /* TODO: SURFMAN_FEATURE_NEED_REFRESH triggers a cache-incohrency with xenfb2

plugins/drm/src/monitor.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ static int drmModeSetDpmsProp(int fd, drmModeConnector *connector, int value)
161161
}
162162

163163
static int drm_monitor_disable_dpms(struct drm_monitor *monitor)
164+
{
165+
/* TODO for now, set DPMS to On for each monitor as it is initialized. I believe
166+
* this will disable the default power saving timeout. It may end up that this is
167+
* the best place to initially set DPMS state to On in the end and we manage timing
168+
* it out into power saving states with xenmgr.
169+
*/
170+
return drm_monitor_dpms_on(monitor);
171+
}
172+
173+
/*
174+
* Set the DPMS mode of a monitor for power saving purposes.
175+
*/
176+
int drm_monitor_dpms_on(struct drm_monitor *monitor)
164177
{
165178
drmModeConnector *c;
166179
int rc;
@@ -170,16 +183,26 @@ static int drm_monitor_disable_dpms(struct drm_monitor *monitor)
170183
return -errno;
171184
}
172185

173-
/* TODO for now, set DPMS to On for each monitor as it is initialized. I believe
174-
* this will disable the default power saving timeout. It may end up that this is
175-
* the best place to initially set DPMS state to On in the end and we manage timing
176-
* it out into power saving states with xenmgr.
177-
*/
178186
rc = drmModeSetDpmsProp(monitor->device->fd, c, DRM_MODE_DPMS_ON);
179187
drmModeFreeConnector(c);
180188
return rc;
181189
}
182190

191+
int drm_monitor_dpms_off(struct drm_monitor *monitor)
192+
{
193+
drmModeConnector *c;
194+
int rc;
195+
196+
c = drmModeGetConnector(monitor->device->fd, monitor->connector);
197+
if (!c) {
198+
return -errno;
199+
}
200+
201+
rc = drmModeSetDpmsProp(monitor->device->fd, c, DRM_MODE_DPMS_OFF);
202+
drmModeFreeConnector(c);
203+
return rc;
204+
}
205+
183206
/*
184207
* Check that default connector configuration is suitable for this monitor.
185208
*/

plugins/drm/src/prototypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ extern const struct drm_framebuffer_ops framebuffer_foreign_ops;
6262
extern void drm_monitor_info(const struct drm_monitor *m);
6363
extern int drm_monitors_scan(struct drm_device *device);
6464
extern int drm_monitor_init(struct drm_monitor *monitor);
65+
extern int drm_monitor_dpms_on(struct drm_monitor *monitor);
66+
extern int drm_monitor_dpms_off(struct drm_monitor *monitor);
6567
/* udev.c */
6668
extern int udev_process_subsystem(struct udev *udev, const char *subsystem, void *(*action)(struct udev *, struct udev_device *));
6769
extern void udev_settle(struct udev *udev, unsigned int timeout);

surfman/src/dbus.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static const struct
3434
{ "dump_all_screens", dbus_dump_all_screens },
3535
{ "increase_brightness", dbus_increase_brightness },
3636
{ "decrease_brightness", dbus_decrease_brightness },
37+
{ "dpms_on", dbus_dpms_on },
38+
{ "dpms_off", dbus_dpms_off },
3739
{ "pre_s3", dbus_pre_s3 },
3840
{ "post_s3", dbus_post_s3 },
3941
{ "display_image", dbus_display_image },

surfman/src/dbus_glue.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ dbus_decrease_brightness (DBusMessage *msg, DBusMessage *reply)
105105
return TRUE;
106106
}
107107

108+
dbus_bool_t
109+
dbus_dpms_on (DBusMessage *msg, DBusMessage *reply)
110+
{
111+
plugin_dpms_on ();
112+
113+
//Re-display the most recently displayed domain.
114+
domain_set_visible(NULL, false);
115+
return TRUE;
116+
}
117+
118+
dbus_bool_t
119+
dbus_dpms_off (DBusMessage *msg, DBusMessage *reply)
120+
{
121+
plugin_dpms_off ();
122+
123+
return TRUE;
124+
}
125+
108126
dbus_bool_t
109127
dbus_pre_s3 (DBusMessage *msg, DBusMessage *reply)
110128
{

surfman/src/plugin.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@ void plugin_restore_brightness (void)
426426
}
427427
}
428428

429+
void plugin_dpms_on (void)
430+
{
431+
struct plugin *p;
432+
433+
LIST_FOREACH (p, &plugin_list, link)
434+
{
435+
/* dpms_on has been implemented from 2.1.2 */
436+
if (PLUGIN_CHECK_VERSION(p, 2, 1, 2)
437+
&& PLUGIN_HAS_METHOD (p, dpms_on))
438+
PLUGIN_CALL (p, dpms_on);
439+
}
440+
}
441+
442+
void plugin_dpms_off (void)
443+
{
444+
struct plugin *p;
445+
446+
LIST_FOREACH (p, &plugin_list, link)
447+
{
448+
/* dpms_off has been implemented from 2.1.2 */
449+
if (PLUGIN_CHECK_VERSION(p, 2, 1, 2)
450+
&& PLUGIN_HAS_METHOD (p, dpms_off))
451+
PLUGIN_CALL (p, dpms_off);
452+
}
453+
}
454+
429455
#if 0
430456
void
431457
plugin_set_guest_resolution (unsigned int domid)

surfman/src/prototypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern dbus_bool_t dbus_display_image(DBusMessage *msg, DBusMessage *reply);
3636
extern dbus_bool_t dbus_dump_all_screens(DBusMessage *msg, DBusMessage *reply);
3737
extern dbus_bool_t dbus_increase_brightness(DBusMessage *msg, DBusMessage *reply);
3838
extern dbus_bool_t dbus_decrease_brightness(DBusMessage *msg, DBusMessage *reply);
39+
extern dbus_bool_t dbus_dpms_on(DBusMessage *msg, DBusMessage *reply);
40+
extern dbus_bool_t dbus_dpms_off(DBusMessage *msg, DBusMessage *reply);
3941
extern dbus_bool_t dbus_pre_s3(DBusMessage *msg, DBusMessage *reply);
4042
extern dbus_bool_t dbus_post_s3(DBusMessage *msg, DBusMessage *reply);
4143
extern dbus_bool_t dbus_set_pv_display(DBusMessage *msg, DBusMessage *reply);
@@ -114,6 +116,8 @@ extern void plugin_pre_s3(void);
114116
extern void plugin_post_s3(void);
115117
extern void plugin_increase_brightness(void);
116118
extern void plugin_decrease_brightness(void);
119+
extern void plugin_dpms_on(void);
120+
extern void plugin_dpms_off(void);
117121
extern void plugin_restore_brightness(void);
118122
extern unsigned int plugin_stride_align(void);
119123
extern int plugin_need_refresh(struct plugin *p);

surfman/version-micro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1
1+
2

0 commit comments

Comments
 (0)