Skip to content

Commit

Permalink
Merge pull request #6 from jctemkin/master
Browse files Browse the repository at this point in the history
Add DPMS support to DRM plugin, and add according RPCs. [OXT-47]
  • Loading branch information
eric-ch committed Jan 20, 2016
2 parents 0ea6c4d + aac53d5 commit e2d4e5d
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 7 deletions.
10 changes: 10 additions & 0 deletions libsurfman/src/surfman-head.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,14 @@ extern "C"
*/
void (*restore_brightness)(struct surfman_plugin *plugin);

/*
* dpms_on : power screen on
*/
void (*dpms_on)(struct surfman_plugin *plugin);

/*
* dpms_off : power screen off
*/
void (*dpms_off)(struct surfman_plugin *plugin);

} surfman_plugin_t;
2 changes: 1 addition & 1 deletion libsurfman/version-micro
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1
2
51 changes: 51 additions & 0 deletions plugins/drm/src/drm-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,52 @@ INTERNAL void drmp_restore_brightness(surfman_plugin_t *plugin)
backlight_restore(backlight);
}

INTERNAL void drmp_dpms_on(surfman_plugin_t *plugin)
{
(void) plugin;
struct drm_device *d;
struct drm_monitor *m;
int rc;

DRM_DBG("%s, dpms on", __FUNCTION__);

list_for_each_entry(d, &devices, l) {
drm_device_set_master(d);
list_for_each_entry(m, &(d->monitors), l_dev) {
rc = drm_monitor_dpms_on(m);
if (rc) {
DRM_DBG("%s, dpms on failed for monitor at conn=%d, enc=%d, "
"crtc=%d - %s", __FUNCTION__, m->connector, m->encoder,
m->crtc, strerror(rc));
}
}
drm_device_drop_master(d);
}
}

INTERNAL void drmp_dpms_off(surfman_plugin_t *plugin)
{
(void) plugin;
struct drm_device *d;
struct drm_monitor *m;
int rc;

DRM_DBG("%s, dpms off", __FUNCTION__);

list_for_each_entry(d, &devices, l) {
drm_device_set_master(d);
list_for_each_entry(m, &(d->monitors), l_dev) {
rc = drm_monitor_dpms_off(m);
if (rc) {
DRM_DBG("%s, dpms off failed for monitor at conn=%d, enc=%d, "
"crtc=%d - %s", __FUNCTION__, m->connector, m->encoder,
m->crtc, strerror(rc));
}
}
drm_device_drop_master(d);
}
}

#define OPTIONAL (NULL)
#define REQUIRED ((void*)0xDEADBEEF)
/* Surfman plugin interface. */
Expand Down Expand Up @@ -504,6 +550,11 @@ surfman_plugin_t surfman_plugin = {
.increase_brightness = drmp_increase_brightness,
.decrease_brightness = drmp_decrease_brightness,
.restore_brightness = drmp_restore_brightness,

/* DPMS mode management. */
.dpms_on = drmp_dpms_on,
.dpms_off = drmp_dpms_off,

.options = {
64, /* libDRM requires a 64 bytes alignment (not 64bit ;). */
0 /* TODO: SURFMAN_FEATURE_NEED_REFRESH triggers a cache-incohrency with xenfb2
Expand Down
33 changes: 28 additions & 5 deletions plugins/drm/src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ static int drmModeSetDpmsProp(int fd, drmModeConnector *connector, int value)
}

static int drm_monitor_disable_dpms(struct drm_monitor *monitor)
{
/* TODO for now, set DPMS to On for each monitor as it is initialized. I believe
* this will disable the default power saving timeout. It may end up that this is
* the best place to initially set DPMS state to On in the end and we manage timing
* it out into power saving states with xenmgr.
*/
return drm_monitor_dpms_on(monitor);
}

/*
* Set the DPMS mode of a monitor for power saving purposes.
*/
int drm_monitor_dpms_on(struct drm_monitor *monitor)
{
drmModeConnector *c;
int rc;
Expand All @@ -170,16 +183,26 @@ static int drm_monitor_disable_dpms(struct drm_monitor *monitor)
return -errno;
}

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

int drm_monitor_dpms_off(struct drm_monitor *monitor)
{
drmModeConnector *c;
int rc;

c = drmModeGetConnector(monitor->device->fd, monitor->connector);
if (!c) {
return -errno;
}

rc = drmModeSetDpmsProp(monitor->device->fd, c, DRM_MODE_DPMS_OFF);
drmModeFreeConnector(c);
return rc;
}

/*
* Check that default connector configuration is suitable for this monitor.
*/
Expand Down
2 changes: 2 additions & 0 deletions plugins/drm/src/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ extern const struct drm_framebuffer_ops framebuffer_foreign_ops;
extern void drm_monitor_info(const struct drm_monitor *m);
extern int drm_monitors_scan(struct drm_device *device);
extern int drm_monitor_init(struct drm_monitor *monitor);
extern int drm_monitor_dpms_on(struct drm_monitor *monitor);
extern int drm_monitor_dpms_off(struct drm_monitor *monitor);
/* udev.c */
extern int udev_process_subsystem(struct udev *udev, const char *subsystem, void *(*action)(struct udev *, struct udev_device *));
extern void udev_settle(struct udev *udev, unsigned int timeout);
Expand Down
2 changes: 2 additions & 0 deletions surfman/src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static const struct
{ "dump_all_screens", dbus_dump_all_screens },
{ "increase_brightness", dbus_increase_brightness },
{ "decrease_brightness", dbus_decrease_brightness },
{ "dpms_on", dbus_dpms_on },
{ "dpms_off", dbus_dpms_off },
{ "pre_s3", dbus_pre_s3 },
{ "post_s3", dbus_post_s3 },
{ "display_image", dbus_display_image },
Expand Down
18 changes: 18 additions & 0 deletions surfman/src/dbus_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ dbus_decrease_brightness (DBusMessage *msg, DBusMessage *reply)
return TRUE;
}

dbus_bool_t
dbus_dpms_on (DBusMessage *msg, DBusMessage *reply)
{
plugin_dpms_on ();

//Re-display the most recently displayed domain.
domain_set_visible(NULL, false);
return TRUE;
}

dbus_bool_t
dbus_dpms_off (DBusMessage *msg, DBusMessage *reply)
{
plugin_dpms_off ();

return TRUE;
}

dbus_bool_t
dbus_pre_s3 (DBusMessage *msg, DBusMessage *reply)
{
Expand Down
26 changes: 26 additions & 0 deletions surfman/src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,32 @@ void plugin_restore_brightness (void)
}
}

void plugin_dpms_on (void)
{
struct plugin *p;

LIST_FOREACH (p, &plugin_list, link)
{
/* dpms_on has been implemented from 2.1.2 */
if (PLUGIN_CHECK_VERSION(p, 2, 1, 2)
&& PLUGIN_HAS_METHOD (p, dpms_on))
PLUGIN_CALL (p, dpms_on);
}
}

void plugin_dpms_off (void)
{
struct plugin *p;

LIST_FOREACH (p, &plugin_list, link)
{
/* dpms_off has been implemented from 2.1.2 */
if (PLUGIN_CHECK_VERSION(p, 2, 1, 2)
&& PLUGIN_HAS_METHOD (p, dpms_off))
PLUGIN_CALL (p, dpms_off);
}
}

#if 0
void
plugin_set_guest_resolution (unsigned int domid)
Expand Down
4 changes: 4 additions & 0 deletions surfman/src/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern dbus_bool_t dbus_display_image(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_dump_all_screens(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_increase_brightness(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_decrease_brightness(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_dpms_on(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_dpms_off(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_pre_s3(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_post_s3(DBusMessage *msg, DBusMessage *reply);
extern dbus_bool_t dbus_set_pv_display(DBusMessage *msg, DBusMessage *reply);
Expand Down Expand Up @@ -114,6 +116,8 @@ extern void plugin_pre_s3(void);
extern void plugin_post_s3(void);
extern void plugin_increase_brightness(void);
extern void plugin_decrease_brightness(void);
extern void plugin_dpms_on(void);
extern void plugin_dpms_off(void);
extern void plugin_restore_brightness(void);
extern unsigned int plugin_stride_align(void);
extern int plugin_need_refresh(struct plugin *p);
Expand Down
2 changes: 1 addition & 1 deletion surfman/version-micro
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1
2

0 comments on commit e2d4e5d

Please sign in to comment.