From: Paulo Zanoni paulo.r.zanoni@intel.com
Same change for intel_display.c and sna_display.c.
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- src/intel_display.c | 104 +++++++++++++++++++++---------------------------- src/sna/sna_display.c | 104 +++++++++++++++++++++---------------------------- 2 files changed, 90 insertions(+), 118 deletions(-)
diff --git a/src/intel_display.c b/src/intel_display.c index 11d0e2b..abdc372 100644 --- a/src/intel_display.c +++ b/src/intel_display.c @@ -992,6 +992,33 @@ intel_property_ignore(drmModePropertyPtr prop) return FALSE; }
+static void +intel_output_create_ranged_atom(xf86OutputPtr output, Atom *atom, + const char *name, INT32 min, INT32 max, + uint64_t value, Bool immutable) +{ + int err; + INT32 atom_range[2]; + + atom_range[0] = min; + atom_range[1] = max; + + *atom = MakeAtom(name, strlen(name), TRUE); + + err = RRConfigureOutputProperty(output->randr_output, *atom, FALSE, + TRUE, immutable, 2, atom_range); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRConfigureOutputProperty error, %d\n", err); + + err = RRChangeOutputProperty(output->randr_output, *atom, XA_INTEGER, + 32, PropModeReplace, 1, &value, FALSE, + TRUE); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); +} + #define BACKLIGHT_NAME "Backlight" #define BACKLIGHT_DEPRECATED_NAME "BACKLIGHT" static Atom backlight_atom, backlight_deprecated_atom; @@ -1031,30 +1058,18 @@ intel_output_create_resources(xf86OutputPtr output) drmModePropertyPtr drmmode_prop = p->mode_prop;
if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 range[2]; - p->num_atoms = 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); if (!p->atoms) continue;
- p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - range[0] = drmmode_prop->values[0]; - range[1] = drmmode_prop->values[1]; - err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], - FALSE, TRUE, - drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, - 2, range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_INTEGER, 32, PropModeReplace, 1, &p->value, FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + intel_output_create_ranged_atom(output, &p->atoms[0], + drmmode_prop->name, + drmmode_prop->values[0], + drmmode_prop->values[1], + p->value, + drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE); + } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { p->num_atoms = drmmode_prop->count_enums + 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); @@ -1090,50 +1105,21 @@ intel_output_create_resources(xf86OutputPtr output) }
if (intel_output->backlight_iface) { - INT32 data, backlight_range[2]; - /* Set up the backlight property, which takes effect * immediately and accepts values only within the * backlight_range. */ - backlight_atom = MakeAtom(BACKLIGHT_NAME, sizeof(BACKLIGHT_NAME) - 1, TRUE); - backlight_deprecated_atom = MakeAtom(BACKLIGHT_DEPRECATED_NAME, - sizeof(BACKLIGHT_DEPRECATED_NAME) - 1, TRUE); - - backlight_range[0] = 0; - backlight_range[1] = intel_output->backlight_max; - err = RRConfigureOutputProperty(output->randr_output, - backlight_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRConfigureOutputProperty(output->randr_output, - backlight_deprecated_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - /* Set the current value of the backlight property */ - data = intel_output->backlight_active_level; - err = RRChangeOutputProperty(output->randr_output, backlight_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, backlight_deprecated_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + intel_output_create_ranged_atom(output, &backlight_atom, + BACKLIGHT_NAME, 0, + intel_output->backlight_max, + intel_output->backlight_active_level, + FALSE); + intel_output_create_ranged_atom(output, + &backlight_deprecated_atom, + BACKLIGHT_DEPRECATED_NAME, 0, + intel_output->backlight_max, + intel_output->backlight_active_level, + FALSE); } }
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index 9401ca4..a5d69dd 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -1205,6 +1205,33 @@ sna_property_ignore(drmModePropertyPtr prop) return FALSE; }
+static void +sna_output_create_ranged_atom(xf86OutputPtr output, Atom *atom, + const char *name, INT32 min, INT32 max, + uint64_t value, Bool immutable) +{ + int err; + INT32 atom_range[2]; + + atom_range[0] = min; + atom_range[1] = max; + + *atom = MakeAtom(name, strlen(name), TRUE); + + err = RRConfigureOutputProperty(output->randr_output, *atom, FALSE, + TRUE, immutable, 2, atom_range); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRConfigureOutputProperty error, %d\n", err); + + err = RRChangeOutputProperty(output->randr_output, *atom, XA_INTEGER, + 32, PropModeReplace, 1, &value, FALSE, + TRUE); + if (err != 0) + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); +} + #define BACKLIGHT_NAME "Backlight" #define BACKLIGHT_DEPRECATED_NAME "BACKLIGHT" static Atom backlight_atom, backlight_deprecated_atom; @@ -1244,30 +1271,18 @@ sna_output_create_resources(xf86OutputPtr output) drmModePropertyPtr drmmode_prop = p->mode_prop;
if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 range[2]; - p->num_atoms = 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); if (!p->atoms) continue;
- p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - range[0] = drmmode_prop->values[0]; - range[1] = drmmode_prop->values[1]; - err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], - FALSE, TRUE, - drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE, - 2, range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_INTEGER, 32, PropModeReplace, 1, &p->value, FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + sna_output_create_ranged_atom(output, &p->atoms[0], + drmmode_prop->name, + drmmode_prop->values[0], + drmmode_prop->values[1], + p->value, + drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE); + } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { p->num_atoms = drmmode_prop->count_enums + 1; p->atoms = calloc(p->num_atoms, sizeof(Atom)); @@ -1303,50 +1318,21 @@ sna_output_create_resources(xf86OutputPtr output) }
if (sna_output->backlight_iface) { - INT32 data, backlight_range[2]; - /* Set up the backlight property, which takes effect * immediately and accepts values only within the * backlight_range. */ - backlight_atom = MakeAtom(BACKLIGHT_NAME, sizeof(BACKLIGHT_NAME) - 1, TRUE); - backlight_deprecated_atom = MakeAtom(BACKLIGHT_DEPRECATED_NAME, - sizeof(BACKLIGHT_DEPRECATED_NAME) - 1, TRUE); - - backlight_range[0] = 0; - backlight_range[1] = sna_output->backlight_max; - err = RRConfigureOutputProperty(output->randr_output, - backlight_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRConfigureOutputProperty(output->randr_output, - backlight_deprecated_atom, - FALSE, TRUE, FALSE, - 2, backlight_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - /* Set the current value of the backlight property */ - data = sna_output->backlight_active_level; - err = RRChangeOutputProperty(output->randr_output, backlight_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, backlight_deprecated_atom, - XA_INTEGER, 32, PropModeReplace, 1, &data, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } + sna_output_create_ranged_atom(output, &backlight_atom, + BACKLIGHT_NAME, 0, + sna_output->backlight_max, + sna_output->backlight_active_level, + FALSE); + sna_output_create_ranged_atom(output, + &backlight_deprecated_atom, + BACKLIGHT_DEPRECATED_NAME, 0, + sna_output->backlight_max, + sna_output->backlight_active_level, + FALSE); } }
From: Paulo Zanoni paulo.r.zanoni@intel.com
Don't worry if that fails: only the KVMr feature will be affected.
We still need to change the sna/ code.
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- src/intel.h | 3 ++ src/intel_display.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/intel_driver.c | 2 + 3 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/src/intel.h b/src/intel.h index f806aea..29df531 100644 --- a/src/intel.h +++ b/src/intel.h @@ -644,4 +644,7 @@ static inline Bool intel_pixmap_is_offscreen(PixmapPtr pixmap) return priv && priv->offscreen; }
+/* intel_display.c */ +void intel_crtc_leave_vt(ScrnInfoPtr scrn); + #endif /* _I830_H_ */ diff --git a/src/intel_display.c b/src/intel_display.c index abdc372..dad0fe1 100644 --- a/src/intel_display.c +++ b/src/intel_display.c @@ -82,6 +82,7 @@ struct intel_crtc { uint32_t rotate_fb_id; xf86CrtcPtr crtc; struct list link; + drmModePropertyPtr rotation_prop; };
struct intel_property { @@ -418,6 +419,44 @@ done: return ret; }
+static void +intel_crtc_inform_rotation(xf86CrtcPtr crtc, Rotation rotation) +{ + struct intel_crtc *intel_crtc = crtc->driver_private; + int ret, int_rotation; + + /* Try to inform the Kernel about our current rotation but don't + * worry if that fails */ + if (intel_crtc->rotation_prop->prop_id) { + + switch (rotation) { + case RR_Rotate_0: + int_rotation = 0; + break; + case RR_Rotate_90: + int_rotation = 90; + break; + case RR_Rotate_180: + int_rotation = 180; + break; + case RR_Rotate_270: + int_rotation = 270; + break; + default: + int_rotation = 0; + } + + ret = drmModeCrtcSetProperty(intel_crtc->mode->fd, + crtc_id(intel_crtc), + intel_crtc->rotation_prop->prop_id, + int_rotation); + if (ret) + xf86DrvMsg(crtc->scrn->scrnIndex, X_WARNING, + "Failed to set CRTC rotation: %s\n", + strerror(-ret)); + } +} + static Bool intel_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, int x, int y) @@ -464,6 +503,8 @@ intel_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, crtc->y = saved_y; crtc->rotation = saved_rotation; crtc->mode = saved_mode; + } else { + intel_crtc_inform_rotation(crtc, rotation); } return ret; } @@ -640,12 +681,48 @@ intel_crtc_destroy(xf86CrtcPtr crtc) intel_crtc->cursor = NULL; }
+ if (intel_crtc->rotation_prop) + drmModeFreeProperty(intel_crtc->rotation_prop); + list_del(&intel_crtc->link); free(intel_crtc);
crtc->driver_private = NULL; }
+static void +intel_crtc_load_properties(struct intel_mode *mode, + struct intel_crtc *crtc) +{ + unsigned int i; + drmModeCrtcPropertiesPtr props; + drmModePropertyPtr prop; + + crtc->rotation_prop = NULL; + + props = drmModeCrtcGetProperties(mode->fd, crtc_id(crtc)); + if (props) { + for (i = 0; i < props->count_props; i++) { + prop = drmModeGetProperty(mode->fd, props->props[i]); + if (!strcmp(prop->name, "rotation")) + crtc->rotation_prop = prop; + else + drmModeFreeProperty(prop); + } + drmModeFreeCrtcProperties(props); + } +} + +void +intel_crtc_leave_vt(ScrnInfoPtr scrn) +{ + int i; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + for (i = 0; i < xf86_config->num_crtc; i++) + intel_crtc_inform_rotation(xf86_config->crtc[i], RR_Rotate_0); +} + static const xf86CrtcFuncsRec intel_crtc_funcs = { .dpms = intel_crtc_dpms, .set_mode_major = intel_crtc_set_mode_major, @@ -692,6 +769,8 @@ intel_crtc_init(ScrnInfoPtr scrn, struct intel_mode *mode, int num)
intel_crtc->crtc = crtc; list_add(&intel_crtc->link, &mode->crtcs); + + intel_crtc_load_properties(mode, intel_crtc); }
static Bool diff --git a/src/intel_driver.c b/src/intel_driver.c index 4265de8..98466a3 100644 --- a/src/intel_driver.c +++ b/src/intel_driver.c @@ -1115,6 +1115,8 @@ static void I830LeaveVT(int scrnIndex, int flags) intel_screen_private *intel = intel_get_screen_private(scrn); int ret;
+ intel_crtc_leave_vt(scrn); + xf86RotateFreeShadow(scrn);
xf86_hide_cursors(scrn);
On Tue, 20 Mar 2012 11:53:22 -0300, Paulo Zanoni przanoni@gmail.com wrote:
From: Paulo Zanoni paulo.r.zanoni@intel.com
Don't worry if that fails: only the KVMr feature will be affected.
This introduces a dependency on libdrm changes that are not yet upstream. -Chris
From: Paulo Zanoni paulo.r.zanoni@intel.com
In the Kernel side, these are crtc properties (since in the hardware, underscan use the panel fitters, which are attached to the pipes). Ideally we should make these as crtc properties too, but since xrandr doesn't have support for them, we expose the atoms as output properties. This is not the best solution, but making the kernel underscan properties be output properties instead of crtc properties would be even more wrong.
We still need to change the sna/ code.
Signed-off-by: Paulo Zanoni paulo.r.zanoni@intel.com --- src/intel_display.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 97 insertions(+), 1 deletions(-)
diff --git a/src/intel_display.c b/src/intel_display.c index dad0fe1..f0cddce 100644 --- a/src/intel_display.c +++ b/src/intel_display.c @@ -83,6 +83,8 @@ struct intel_crtc { xf86CrtcPtr crtc; struct list link; drmModePropertyPtr rotation_prop; + drmModePropertyPtr underscan_x_prop; + drmModePropertyPtr underscan_y_prop; };
struct intel_property { @@ -111,6 +113,8 @@ struct intel_output { int backlight_max; xf86OutputPtr output; struct list link; + Atom underscan_x_atom; + Atom underscan_y_atom; };
static void @@ -683,6 +687,10 @@ intel_crtc_destroy(xf86CrtcPtr crtc)
if (intel_crtc->rotation_prop) drmModeFreeProperty(intel_crtc->rotation_prop); + if (intel_crtc->underscan_x_prop) + drmModeFreeProperty(intel_crtc->underscan_x_prop); + if (intel_crtc->underscan_y_prop) + drmModeFreeProperty(intel_crtc->underscan_y_prop);
list_del(&intel_crtc->link); free(intel_crtc); @@ -699,6 +707,8 @@ intel_crtc_load_properties(struct intel_mode *mode, drmModePropertyPtr prop;
crtc->rotation_prop = NULL; + crtc->underscan_x_prop = NULL; + crtc->underscan_y_prop = NULL;
props = drmModeCrtcGetProperties(mode->fd, crtc_id(crtc)); if (props) { @@ -706,6 +716,10 @@ intel_crtc_load_properties(struct intel_mode *mode, prop = drmModeGetProperty(mode->fd, props->props[i]); if (!strcmp(prop->name, "rotation")) crtc->rotation_prop = prop; + else if (!strcmp(prop->name, "underscan x")) + crtc->underscan_x_prop = prop; + else if (!strcmp(prop->name, "underscan y")) + crtc->underscan_y_prop = prop; else drmModeFreeProperty(prop); } @@ -1200,6 +1214,19 @@ intel_output_create_resources(xf86OutputPtr output) intel_output->backlight_active_level, FALSE); } + intel_output_create_ranged_atom(output, &intel_output->underscan_x_atom, + "underscan x", 0, 100, 0, FALSE); + intel_output_create_ranged_atom(output, &intel_output->underscan_y_atom, + "underscan y", 0, 100, 0, FALSE); +} + +static struct intel_crtc * +intel_output_get_crtc(xf86OutputPtr output) +{ + if (output->crtc) + return output->crtc->driver_private; + else + return 0; }
static Bool @@ -1229,6 +1256,36 @@ intel_output_set_property(xf86OutputPtr output, Atom property, return TRUE; }
+ if (property == intel_output->underscan_x_atom || + property == intel_output->underscan_y_atom) { + uint32_t val; + struct intel_crtc *intel_crtc; + drmModePropertyPtr drm_prop; + + val = *(uint32_t *)value->data; + if (value->type != XA_INTEGER || value->format != 32 || + value->size != 1 || val > 100) + return FALSE; + + intel_crtc = intel_output_get_crtc(output); + if (intel_crtc) { + if (property == intel_output->underscan_x_atom) + drm_prop = intel_crtc->underscan_x_prop; + else + drm_prop = intel_crtc->underscan_y_prop; + + if (!drm_prop) + return FALSE; + + drmModeCrtcSetProperty(mode->fd, + intel_crtc->mode_crtc->crtc_id, + drm_prop->prop_id, + (uint64_t) val); + + } + return TRUE; + } + for (i = 0; i < intel_output->num_props; i++) { struct intel_property *p = &intel_output->props[i];
@@ -1279,10 +1336,11 @@ static Bool intel_output_get_property(xf86OutputPtr output, Atom property) { struct intel_output *intel_output = output->driver_private; + struct intel_mode *mode = intel_output->mode; int err; + INT32 val;
if (property == backlight_atom || property == backlight_deprecated_atom) { - INT32 val;
if (! intel_output->backlight_iface) return FALSE; @@ -1303,6 +1361,44 @@ intel_output_get_property(xf86OutputPtr output, Atom property) return TRUE; }
+ if (property == intel_output->underscan_x_atom || + property == intel_output->underscan_y_atom) { + struct intel_crtc *intel_crtc = NULL; + drmModeCrtcPropertiesPtr props; + unsigned int i; + + intel_crtc = intel_output_get_crtc(output); + + if (!intel_crtc) { + val = 0; + } else { + props = drmModeCrtcGetProperties(mode->fd, + intel_crtc->mode_crtc->crtc_id); + if (!props) + return FALSE; + + for (i = 0; i < props->count_props; i++) { + if (props->props[i] == intel_crtc->underscan_x_prop->prop_id && + property == intel_output->underscan_x_atom) + val = props->prop_values[i]; + else if (props->props[i] == intel_crtc->underscan_y_prop->prop_id && + property == intel_output->underscan_y_atom) + val = props->prop_values[i]; + } + drmModeFreeCrtcProperties(props); + } + + err = RRChangeOutputProperty(output->randr_output, property, + XA_INTEGER, 32, PropModeReplace, + 1, &val, FALSE, TRUE); + if (err != 0) { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "RRChangeOutputProperty error, %d\n", err); + return FALSE; + } + return TRUE; + } + return FALSE; }
On Tue, 20 Mar 2012 11:53:21 -0300, Paulo Zanoni przanoni@gmail.com wrote:
From: Paulo Zanoni paulo.r.zanoni@intel.com
Same change for intel_display.c and sna_display.c.
Applied, thanks. -Chris
dri-devel@lists.freedesktop.org