Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007 Red Hat, Inc. |
| 3 | * Copyright © 2008 Maarten Maathuis |
| 4 | * Copyright © 2011 Texas Instruments, Inc |
| 5 | * |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Dave Airlie <airlied@redhat.com> |
| 28 | * Ian Elliott <ianelliottus@yahoo.com> |
| 29 | */ |
| 30 | |
| 31 | #ifdef HAVE_CONFIG_H |
| 32 | #include "config.h" |
| 33 | #endif |
| 34 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 35 | #include "xf86DDC.h" |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 36 | #include "xf86RandR12.h" |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 37 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 38 | #ifdef HAVE_XEXTPROTO_71 |
| 39 | #include <X11/extensions/dpmsconst.h> |
| 40 | #else |
| 41 | #define DPMS_SERVER |
| 42 | #include <X11/extensions/dpms.h> |
| 43 | #endif |
| 44 | |
Paul Geary | f8b9969 | 2013-04-15 10:55:17 +0100 | [diff] [blame] | 45 | #include "armsoc_driver.h" |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 46 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 47 | #include "xf86drmMode.h" |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 48 | #include "drm_fourcc.h" |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 49 | #include "X11/Xatom.h" |
| 50 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 51 | #include <libudev.h> |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 52 | #include "drmmode_driver.h" |
| 53 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 54 | struct drmmode_cursor_rec { |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 55 | /* hardware cursor: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 56 | struct armsoc_bo *bo; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 57 | int x, y; |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 58 | /* These are used for HWCURSOR_API_PLANE */ |
| 59 | drmModePlane *ovr; |
| 60 | uint32_t fb_id; |
| 61 | /* This is used for HWCURSOR_API_STANDARD */ |
| 62 | uint32_t handle; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 63 | }; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 64 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 65 | struct drmmode_rec { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 66 | int fd; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 67 | drmModeResPtr mode_res; |
| 68 | int cpp; |
| 69 | struct udev_monitor *uevent_monitor; |
| 70 | InputHandlerProc uevent_handler; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 71 | struct drmmode_cursor_rec *cursor; |
| 72 | }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 73 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 74 | struct drmmode_crtc_private_rec { |
| 75 | struct drmmode_rec *drmmode; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 76 | drmModeCrtcPtr mode_crtc; |
Stéphane Marchesin | b8b3520 | 2012-10-02 20:27:40 -0700 | [diff] [blame] | 77 | int cursor_visible; |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 78 | /* settings retained on last good modeset */ |
| 79 | int last_good_x; |
| 80 | int last_good_y; |
| 81 | Rotation last_good_rotation; |
| 82 | DisplayModePtr last_good_mode; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 83 | }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 84 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 85 | struct drmmode_prop_rec { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 86 | drmModePropertyPtr mode_prop; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 87 | /* Index within the kernel-side property arrays for this connector. */ |
| 88 | int index; |
| 89 | /* if range prop, num_atoms == 1; |
| 90 | * if enum prop, num_atoms == num_enums + 1 |
| 91 | */ |
| 92 | int num_atoms; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 93 | Atom *atoms; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 94 | }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 95 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 96 | struct drmmode_output_priv { |
| 97 | struct drmmode_rec *drmmode; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 98 | int output_id; |
| 99 | drmModeConnectorPtr mode_output; |
| 100 | drmModeEncoderPtr mode_encoder; |
| 101 | drmModePropertyBlobPtr edid_blob; |
| 102 | int num_props; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 103 | struct drmmode_prop_rec *props; |
| 104 | }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 105 | |
| 106 | static void drmmode_output_dpms(xf86OutputPtr output, int mode); |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 107 | static Bool resize_scanout_bo(ScrnInfoPtr pScrn, int width, int height); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 108 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 109 | static struct drmmode_rec * |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 110 | drmmode_from_scrn(ScrnInfoPtr pScrn) |
| 111 | { |
| 112 | xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 113 | struct drmmode_crtc_private_rec *drmmode_crtc; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 114 | |
| 115 | drmmode_crtc = xf86_config->crtc[0]->driver_private; |
| 116 | return drmmode_crtc->drmmode; |
| 117 | } |
| 118 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 119 | static void |
| 120 | drmmode_ConvertFromKMode(ScrnInfoPtr pScrn, drmModeModeInfo *kmode, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 121 | DisplayModePtr mode) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 122 | { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 123 | memset(mode, 0, sizeof(DisplayModeRec)); |
| 124 | mode->status = MODE_OK; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 125 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 126 | mode->Clock = kmode->clock; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 127 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 128 | mode->HDisplay = kmode->hdisplay; |
| 129 | mode->HSyncStart = kmode->hsync_start; |
| 130 | mode->HSyncEnd = kmode->hsync_end; |
| 131 | mode->HTotal = kmode->htotal; |
| 132 | mode->HSkew = kmode->hskew; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 133 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 134 | mode->VDisplay = kmode->vdisplay; |
| 135 | mode->VSyncStart = kmode->vsync_start; |
| 136 | mode->VSyncEnd = kmode->vsync_end; |
| 137 | mode->VTotal = kmode->vtotal; |
| 138 | mode->VScan = kmode->vscan; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 139 | |
Dave Barnish | 01b5c17 | 2013-04-10 11:01:17 +0100 | [diff] [blame] | 140 | mode->Flags = kmode->flags; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 141 | mode->name = strdup(kmode->name); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 142 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 143 | DEBUG_MSG("copy mode %s (%p %p)", kmode->name, mode->name, mode); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 144 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 145 | if (kmode->type & DRM_MODE_TYPE_DRIVER) |
| 146 | mode->type = M_T_DRIVER; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 147 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 148 | if (kmode->type & DRM_MODE_TYPE_PREFERRED) |
| 149 | mode->type |= M_T_PREFERRED; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 150 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 151 | xf86SetModeCrtc(mode, pScrn->adjustFlags); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 152 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 153 | |
| 154 | static void |
| 155 | drmmode_ConvertToKMode(ScrnInfoPtr pScrn, drmModeModeInfo *kmode, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 156 | DisplayModePtr mode) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 157 | { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 158 | memset(kmode, 0, sizeof(*kmode)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 159 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 160 | kmode->clock = mode->Clock; |
| 161 | kmode->hdisplay = mode->HDisplay; |
| 162 | kmode->hsync_start = mode->HSyncStart; |
| 163 | kmode->hsync_end = mode->HSyncEnd; |
| 164 | kmode->htotal = mode->HTotal; |
| 165 | kmode->hskew = mode->HSkew; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 166 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 167 | kmode->vdisplay = mode->VDisplay; |
| 168 | kmode->vsync_start = mode->VSyncStart; |
| 169 | kmode->vsync_end = mode->VSyncEnd; |
| 170 | kmode->vtotal = mode->VTotal; |
| 171 | kmode->vscan = mode->VScan; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 172 | |
Dave Barnish | 01b5c17 | 2013-04-10 11:01:17 +0100 | [diff] [blame] | 173 | kmode->flags = mode->Flags; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 174 | if (mode->name) |
| 175 | strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN); |
| 176 | kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
| 177 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 178 | |
| 179 | static void |
| 180 | drmmode_crtc_dpms(xf86CrtcPtr drmmode_crtc, int mode) |
| 181 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 182 | /* TODO: MIDEGL-1431: Implement this function */ |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 183 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 184 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 185 | static int |
| 186 | drmmode_revert_mode(xf86CrtcPtr crtc, uint32_t *output_ids, int output_count) |
| 187 | { |
| 188 | ScrnInfoPtr pScrn = crtc->scrn; |
| 189 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 190 | uint32_t fb_id; |
| 191 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 192 | drmModeModeInfo kmode; |
| 193 | |
| 194 | if (!drmmode_crtc->last_good_mode) { |
| 195 | DEBUG_MSG("No last good values to use"); |
| 196 | return FALSE; |
| 197 | } |
| 198 | |
| 199 | /* revert to last good settings */ |
| 200 | DEBUG_MSG("Reverting to last_good values"); |
| 201 | if (!resize_scanout_bo(pScrn, |
| 202 | drmmode_crtc->last_good_mode->HDisplay, |
| 203 | drmmode_crtc->last_good_mode->VDisplay)) { |
| 204 | ERROR_MSG("Could not revert to last good mode"); |
| 205 | return FALSE; |
| 206 | } |
| 207 | |
| 208 | fb_id = armsoc_bo_get_fb(pARMSOC->scanout); |
| 209 | drmmode_ConvertToKMode(crtc->scrn, &kmode, |
| 210 | drmmode_crtc->last_good_mode); |
| 211 | drmModeSetCrtc(drmmode_crtc->drmmode->fd, |
| 212 | drmmode_crtc->mode_crtc->crtc_id, |
| 213 | fb_id, |
| 214 | drmmode_crtc->last_good_x, |
| 215 | drmmode_crtc->last_good_y, |
| 216 | output_ids, output_count, &kmode); |
| 217 | |
| 218 | /* let RandR know we changed things */ |
| 219 | xf86RandR12TellChanged(pScrn->pScreen); |
| 220 | |
| 221 | return TRUE; |
| 222 | } |
| 223 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 224 | static Bool |
| 225 | drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 226 | Rotation rotation, int x, int y) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 227 | { |
| 228 | ScrnInfoPtr pScrn = crtc->scrn; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 229 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 230 | xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 231 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 232 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 233 | uint32_t *output_ids = NULL; |
| 234 | int output_count = 0; |
| 235 | int ret = TRUE; |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 236 | int err; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 237 | int i; |
David Garbett | 7171c52 | 2012-05-11 13:12:50 +0100 | [diff] [blame] | 238 | uint32_t fb_id; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 239 | drmModeModeInfo kmode; |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 240 | drmModeCrtcPtr newcrtc = NULL; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 241 | |
| 242 | TRACE_ENTER(); |
| 243 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 244 | fb_id = armsoc_bo_get_fb(pARMSOC->scanout); |
David Garbett | 7171c52 | 2012-05-11 13:12:50 +0100 | [diff] [blame] | 245 | |
| 246 | if (fb_id == 0) { |
David Garbett | 7171c52 | 2012-05-11 13:12:50 +0100 | [diff] [blame] | 247 | DEBUG_MSG("create framebuffer: %dx%d", |
| 248 | pScrn->virtualX, pScrn->virtualY); |
| 249 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 250 | err = armsoc_bo_add_fb(pARMSOC->scanout); |
| 251 | if (err) { |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 252 | ERROR_MSG( |
| 253 | "Failed to add framebuffer to the scanout buffer"); |
David Garbett | 7171c52 | 2012-05-11 13:12:50 +0100 | [diff] [blame] | 254 | return FALSE; |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 255 | } |
Dave Barnish | 523c9ff | 2013-03-12 10:59:03 +0000 | [diff] [blame] | 256 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 257 | fb_id = armsoc_bo_get_fb(pARMSOC->scanout); |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 258 | if (0 == fb_id) |
| 259 | return FALSE; |
David Garbett | 7171c52 | 2012-05-11 13:12:50 +0100 | [diff] [blame] | 260 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 261 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 262 | /* Set the new mode: */ |
| 263 | crtc->mode = *mode; |
| 264 | crtc->x = x; |
| 265 | crtc->y = y; |
| 266 | crtc->rotation = rotation; |
| 267 | |
| 268 | output_ids = calloc(sizeof(uint32_t), xf86_config->num_output); |
| 269 | if (!output_ids) { |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 270 | ERROR_MSG( |
| 271 | "memory allocation failed in drmmode_set_mode_major()"); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 272 | ret = FALSE; |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 273 | goto cleanup; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | for (i = 0; i < xf86_config->num_output; i++) { |
| 277 | xf86OutputPtr output = xf86_config->output[i]; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 278 | struct drmmode_output_priv *drmmode_output; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 279 | |
| 280 | if (output->crtc != crtc) |
| 281 | continue; |
| 282 | |
| 283 | drmmode_output = output->driver_private; |
| 284 | output_ids[output_count] = |
| 285 | drmmode_output->mode_output->connector_id; |
| 286 | output_count++; |
| 287 | } |
| 288 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 289 | if (!xf86CrtcRotate(crtc)) { |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 290 | ERROR_MSG( |
| 291 | "failed to assign rotation in drmmode_set_mode_major()"); |
Dave Barnish | 523c9ff | 2013-03-12 10:59:03 +0000 | [diff] [blame] | 292 | ret = FALSE; |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 293 | goto cleanup; |
Dave Barnish | 523c9ff | 2013-03-12 10:59:03 +0000 | [diff] [blame] | 294 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 295 | |
Mandeep Singh Baines | c874fcb | 2012-09-13 15:30:00 +0200 | [diff] [blame] | 296 | if (crtc->funcs->gamma_set) |
| 297 | crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, |
| 298 | crtc->gamma_blue, crtc->gamma_size); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 299 | |
| 300 | drmmode_ConvertToKMode(crtc->scrn, &kmode, mode); |
| 301 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 302 | err = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 303 | fb_id, x, y, output_ids, output_count, &kmode); |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 304 | if (err) { |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 305 | ERROR_MSG( |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 306 | "drm failed to set mode: %s", strerror(-err)); |
| 307 | |
Dave Barnish | 523c9ff | 2013-03-12 10:59:03 +0000 | [diff] [blame] | 308 | ret = FALSE; |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 309 | if (!drmmode_revert_mode(crtc, output_ids, output_count)) |
| 310 | goto cleanup; |
| 311 | else |
| 312 | goto done_setting; |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /* get the actual crtc info */ |
| 316 | newcrtc = drmModeGetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id); |
| 317 | if (!newcrtc) { |
| 318 | ERROR_MSG("couldn't get actual mode back"); |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 319 | |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 320 | ret = FALSE; |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 321 | if (!drmmode_revert_mode(crtc, output_ids, output_count)) |
| 322 | goto cleanup; |
| 323 | else |
| 324 | goto done_setting; |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | if (kmode.hdisplay != newcrtc->mode.hdisplay || |
| 328 | kmode.vdisplay != newcrtc->mode.vdisplay) { |
| 329 | |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 330 | ERROR_MSG( |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 331 | "drm did not set requested mode! (requested %dx%d, actual %dx%d)", |
| 332 | kmode.hdisplay, kmode.vdisplay, |
| 333 | newcrtc->mode.hdisplay, |
| 334 | newcrtc->mode.vdisplay); |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 335 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 336 | ret = FALSE; |
| 337 | if (!drmmode_revert_mode(crtc, output_ids, output_count)) |
| 338 | goto cleanup; |
| 339 | else |
| 340 | goto done_setting; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 341 | } |
| 342 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 343 | /* When called on a resize, crtc->mode already contains the |
| 344 | * resized values so we can't use this for recovery. |
| 345 | * We can't read it out of the crtc either as mode_valid is 0. |
| 346 | * Instead we save the last good mode set here & fallback to |
| 347 | * that on failure. |
| 348 | */ |
| 349 | DEBUG_MSG("Saving last good values"); |
| 350 | drmmode_crtc->last_good_x = crtc->x; |
| 351 | drmmode_crtc->last_good_y = crtc->y; |
| 352 | drmmode_crtc->last_good_rotation = crtc->rotation; |
| 353 | if (drmmode_crtc->last_good_mode) { |
| 354 | if (drmmode_crtc->last_good_mode->name) |
| 355 | free(drmmode_crtc->last_good_mode->name); |
| 356 | free(drmmode_crtc->last_good_mode); |
| 357 | } |
| 358 | drmmode_crtc->last_good_mode = xf86DuplicateMode(&crtc->mode); |
| 359 | |
| 360 | ret = TRUE; |
| 361 | |
| 362 | done_setting: |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 363 | /* Turn on any outputs on this crtc that may have been disabled: */ |
| 364 | for (i = 0; i < xf86_config->num_output; i++) { |
| 365 | xf86OutputPtr output = xf86_config->output[i]; |
| 366 | |
| 367 | if (output->crtc != crtc) |
| 368 | continue; |
| 369 | |
| 370 | drmmode_output_dpms(output, DPMSModeOn); |
| 371 | } |
| 372 | |
Dave Barnish | af04615 | 2013-05-31 09:12:44 +0100 | [diff] [blame] | 373 | /* if hw cursor is initialized, reload it */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 374 | if (drmmode->cursor) |
Dave Barnish | af04615 | 2013-05-31 09:12:44 +0100 | [diff] [blame] | 375 | xf86_reload_cursors(pScrn->pScreen); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 376 | |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 377 | cleanup: |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 378 | if (newcrtc) |
| 379 | drmModeFreeCrtc(newcrtc); |
| 380 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 381 | if (output_ids) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 382 | free(output_ids); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 383 | |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 384 | if (!ret && !drmmode_crtc->last_good_mode) { |
Dave Barnish | f256ebe | 2013-08-22 15:05:58 +0100 | [diff] [blame] | 385 | /* If there was a problem, restore the last good mode: */ |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 386 | crtc->x = drmmode_crtc->last_good_x; |
| 387 | crtc->y = drmmode_crtc->last_good_y; |
| 388 | crtc->rotation = drmmode_crtc->last_good_rotation; |
| 389 | crtc->mode = *drmmode_crtc->last_good_mode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | TRACE_EXIT(); |
| 393 | return ret; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 394 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 395 | |
| 396 | static void |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 397 | drmmode_hide_cursor(xf86CrtcPtr crtc) |
| 398 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 399 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 400 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
| 401 | struct drmmode_cursor_rec *cursor = drmmode->cursor; |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 402 | ScrnInfoPtr pScrn = crtc->scrn; |
| 403 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 404 | |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 405 | if (!cursor) |
| 406 | return; |
| 407 | |
Stéphane Marchesin | b8b3520 | 2012-10-02 20:27:40 -0700 | [diff] [blame] | 408 | drmmode_crtc->cursor_visible = FALSE; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 409 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 410 | if (pARMSOC->drmmode_interface->cursor_api == HWCURSOR_API_PLANE) { |
| 411 | /* set plane's fb_id to 0 to disable it */ |
| 412 | drmModeSetPlane(drmmode->fd, cursor->ovr->plane_id, |
| 413 | drmmode_crtc->mode_crtc->crtc_id, 0, 0, |
| 414 | 0, 0, 0, 0, 0, 0, 0, 0); |
| 415 | } else { /* HWCURSOR_API_STANDARD */ |
| 416 | /* set handle to 0 to disable the cursor */ |
| 417 | drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, |
| 418 | 0, 0, 0); |
| 419 | } |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 420 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 421 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 422 | /* |
| 423 | * The argument "update_image" controls whether the cursor image needs |
| 424 | * to be updated by the HW or not. This is ignored by HWCURSOR_API_PLANE |
| 425 | * which doesn't allow changing the cursor possition without updating |
| 426 | * the image too. |
| 427 | */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 428 | static void |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 429 | drmmode_show_cursor_image(xf86CrtcPtr crtc, Bool update_image) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 430 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 431 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 432 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
| 433 | struct drmmode_cursor_rec *cursor = drmmode->cursor; |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 434 | int crtc_x, crtc_y, src_x, src_y; |
| 435 | int w, h, pad; |
| 436 | ScrnInfoPtr pScrn = crtc->scrn; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 437 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 438 | |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 439 | if (!cursor) |
| 440 | return; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 441 | |
Stéphane Marchesin | b8b3520 | 2012-10-02 20:27:40 -0700 | [diff] [blame] | 442 | drmmode_crtc->cursor_visible = TRUE; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 443 | |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 444 | w = pARMSOC->drmmode_interface->cursor_width; |
| 445 | h = pARMSOC->drmmode_interface->cursor_height; |
| 446 | pad = pARMSOC->drmmode_interface->cursor_padding; |
| 447 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 448 | /* get padded width */ |
| 449 | w = w + 2 * pad; |
| 450 | /* get x of padded cursor */ |
| 451 | crtc_x = cursor->x - pad; |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 452 | crtc_y = cursor->y; |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 453 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 454 | if (pARMSOC->drmmode_interface->cursor_api == HWCURSOR_API_PLANE) { |
| 455 | src_x = 0; |
| 456 | src_y = 0; |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 457 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 458 | /* calculate clipped x, y, w & h if cursor is off edges */ |
| 459 | if (crtc_x < 0) { |
| 460 | src_x += -crtc_x; |
| 461 | w -= -crtc_x; |
| 462 | crtc_x = 0; |
| 463 | } |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 464 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 465 | if (crtc_y < 0) { |
| 466 | src_y += -crtc_y; |
| 467 | h -= -crtc_y; |
| 468 | crtc_y = 0; |
| 469 | } |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 470 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 471 | if ((crtc_x + w) > crtc->mode.HDisplay) |
| 472 | w = crtc->mode.HDisplay - crtc_x; |
Rob Clark | 60f5bad | 2012-01-22 18:35:28 -0600 | [diff] [blame] | 473 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 474 | if ((crtc_y + h) > crtc->mode.VDisplay) |
| 475 | h = crtc->mode.VDisplay - crtc_y; |
| 476 | |
| 477 | /* note src coords (last 4 args) are in Q16 format */ |
| 478 | drmModeSetPlane(drmmode->fd, cursor->ovr->plane_id, |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 479 | drmmode_crtc->mode_crtc->crtc_id, cursor->fb_id, 0, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 480 | crtc_x, crtc_y, w, h, src_x<<16, src_y<<16, |
| 481 | w<<16, h<<16); |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 482 | } else { |
| 483 | if (update_image) |
| 484 | drmModeSetCursor(drmmode->fd, |
| 485 | drmmode_crtc->mode_crtc->crtc_id, |
| 486 | cursor->handle, w, h); |
| 487 | drmModeMoveCursor(drmmode->fd, |
| 488 | drmmode_crtc->mode_crtc->crtc_id, |
| 489 | crtc_x, crtc_y); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | static void |
| 494 | drmmode_show_cursor(xf86CrtcPtr crtc) |
| 495 | { |
| 496 | drmmode_show_cursor_image(crtc, TRUE); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void |
| 500 | drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y) |
| 501 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 502 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 503 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
| 504 | struct drmmode_cursor_rec *cursor = drmmode->cursor; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 505 | |
| 506 | if (!cursor) |
| 507 | return; |
| 508 | |
| 509 | cursor->x = x; |
| 510 | cursor->y = y; |
| 511 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 512 | /* |
| 513 | * Show the cursor at a different possition without updating the image |
| 514 | * when possible (HWCURSOR_API_PLANE doesn't have a way to update |
| 515 | * cursor position without updating the image too). |
| 516 | */ |
| 517 | drmmode_show_cursor_image(crtc, FALSE); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 518 | } |
| 519 | |
Javier Martin | a7e316f | 2013-09-16 15:22:41 +0100 | [diff] [blame^] | 520 | /* |
| 521 | * The cursor format is ARGB so the image can be copied straight over. |
| 522 | * Columns of CURSORPAD blank pixels are maintained down either side |
| 523 | * of the destination image. This is a workaround for a bug causing |
| 524 | * corruption when the cursor reaches the screen edges in some DRM |
| 525 | * drivers. |
| 526 | */ |
| 527 | static void set_cursor_image(xf86CrtcPtr crtc, uint32_t *d, CARD32 *s) |
| 528 | { |
| 529 | ScrnInfoPtr pScrn = crtc->scrn; |
| 530 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 531 | int row; |
| 532 | void *dst; |
| 533 | const char *src_row; |
| 534 | char *dst_row; |
| 535 | uint32_t cursorh = pARMSOC->drmmode_interface->cursor_height; |
| 536 | uint32_t cursorw = pARMSOC->drmmode_interface->cursor_width; |
| 537 | uint32_t cursorpad = pARMSOC->drmmode_interface->cursor_padding; |
| 538 | |
| 539 | dst = d; |
| 540 | for (row = 0; row < cursorh; row += 1) { |
| 541 | /* we're operating with ARGB data (4 bytes per pixel) */ |
| 542 | src_row = (const char *)s + row * 4 * cursorw; |
| 543 | dst_row = (char *)dst + row * 4 * (cursorw + 2 * cursorpad); |
| 544 | |
| 545 | /* set first CURSORPAD pixels in row to 0 */ |
| 546 | memset(dst_row, 0, (4 * cursorpad)); |
| 547 | /* copy cursor image pixel row across */ |
| 548 | memcpy(dst_row + (4 * cursorpad), src_row, 4 * cursorw); |
| 549 | /* set last CURSORPAD pixels in row to 0 */ |
| 550 | memset(dst_row + 4 * (cursorpad + cursorw), |
| 551 | 0, (4 * cursorpad)); |
| 552 | } |
| 553 | } |
| 554 | |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 555 | static void |
| 556 | drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image) |
| 557 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 558 | uint32_t *d; |
| 559 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 560 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
| 561 | struct drmmode_cursor_rec *cursor = drmmode->cursor; |
Rob Clark | 979add5 | 2012-02-21 18:35:24 -0600 | [diff] [blame] | 562 | int visible; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 563 | |
| 564 | if (!cursor) |
| 565 | return; |
| 566 | |
Stéphane Marchesin | b8b3520 | 2012-10-02 20:27:40 -0700 | [diff] [blame] | 567 | visible = drmmode_crtc->cursor_visible; |
Rob Clark | 979add5 | 2012-02-21 18:35:24 -0600 | [diff] [blame] | 568 | |
| 569 | if (visible) |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 570 | drmmode_hide_cursor(crtc); |
| 571 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 572 | d = armsoc_bo_map(cursor->bo); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 573 | if (!d) { |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 574 | xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, |
| 575 | "load_cursor_argb map failure\n"); |
| 576 | if (visible) |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 577 | drmmode_show_cursor_image(crtc, TRUE); |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 578 | return; |
| 579 | } |
John Rees | 292ae50 | 2013-03-21 16:24:35 +0000 | [diff] [blame] | 580 | |
Javier Martin | a7e316f | 2013-09-16 15:22:41 +0100 | [diff] [blame^] | 581 | set_cursor_image(crtc, d, image); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 582 | |
Rob Clark | 979add5 | 2012-02-21 18:35:24 -0600 | [diff] [blame] | 583 | if (visible) |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 584 | drmmode_show_cursor_image(crtc, TRUE); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 585 | } |
| 586 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 587 | static Bool |
| 588 | drmmode_cursor_init_plane(ScreenPtr pScreen) |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 589 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 590 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 591 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 592 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
| 593 | struct drmmode_cursor_rec *cursor; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 594 | drmModePlaneRes *plane_resources; |
| 595 | drmModePlane *ovr; |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 596 | int w, h, pad; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 597 | uint32_t handles[4], pitches[4], offsets[4]; /* we only use [0] */ |
| 598 | |
| 599 | if (drmmode->cursor) { |
| 600 | INFO_MSG("cursor already initialized"); |
| 601 | return TRUE; |
| 602 | } |
| 603 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 604 | if (!xf86LoaderCheckSymbol("drmModeGetPlaneResources")) { |
| 605 | ERROR_MSG( |
| 606 | "HW cursor not supported (needs libdrm 2.4.30 or higher)"); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 607 | return FALSE; |
| 608 | } |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 609 | |
| 610 | /* find an unused plane which can be used as a mouse cursor. Note |
| 611 | * that we cheat a bit, in order to not burn one overlay per crtc, |
| 612 | * and only show the mouse cursor on one crtc at a time |
| 613 | */ |
| 614 | plane_resources = drmModeGetPlaneResources(drmmode->fd); |
| 615 | if (!plane_resources) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 616 | ERROR_MSG("HW cursor: drmModeGetPlaneResources failed: %s", |
| 617 | strerror(errno)); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 618 | return FALSE; |
| 619 | } |
| 620 | |
| 621 | if (plane_resources->count_planes < 1) { |
| 622 | ERROR_MSG("not enough planes for HW cursor"); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 623 | drmModeFreePlaneResources(plane_resources); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 624 | return FALSE; |
| 625 | } |
| 626 | |
| 627 | ovr = drmModeGetPlane(drmmode->fd, plane_resources->planes[0]); |
| 628 | if (!ovr) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 629 | ERROR_MSG("HW cursor: drmModeGetPlane failed: %s", |
| 630 | strerror(errno)); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 631 | drmModeFreePlaneResources(plane_resources); |
| 632 | return FALSE; |
| 633 | } |
| 634 | |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 635 | if (pARMSOC->drmmode_interface->init_plane_for_cursor && |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 636 | pARMSOC->drmmode_interface->init_plane_for_cursor( |
| 637 | drmmode->fd, ovr->plane_id)) { |
Ray Smith | b93cd89 | 2013-04-03 10:06:18 +0100 | [diff] [blame] | 638 | ERROR_MSG("Failed driver-specific cursor initialization"); |
| 639 | drmModeFreePlaneResources(plane_resources); |
| 640 | return FALSE; |
| 641 | } |
| 642 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 643 | cursor = calloc(1, sizeof(struct drmmode_cursor_rec)); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 644 | if (!cursor) { |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 645 | ERROR_MSG("HW cursor: calloc failed"); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 646 | drmModeFreePlane(ovr); |
| 647 | drmModeFreePlaneResources(plane_resources); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 648 | return FALSE; |
| 649 | } |
| 650 | |
| 651 | cursor->ovr = ovr; |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 652 | |
| 653 | w = pARMSOC->drmmode_interface->cursor_width; |
| 654 | h = pARMSOC->drmmode_interface->cursor_height; |
| 655 | pad = pARMSOC->drmmode_interface->cursor_padding; |
| 656 | |
| 657 | /* allow for cursor padding in the bo */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 658 | cursor->bo = armsoc_bo_new_with_dim(pARMSOC->dev, |
| 659 | w + 2 * pad, h, |
| 660 | 0, 32, ARMSOC_BO_SCANOUT); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 661 | |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 662 | if (!cursor->bo) { |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 663 | ERROR_MSG("HW cursor: buffer allocation failed"); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 664 | free(cursor); |
| 665 | drmModeFreePlane(ovr); |
| 666 | drmModeFreePlaneResources(plane_resources); |
| 667 | return FALSE; |
| 668 | } |
| 669 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 670 | handles[0] = armsoc_bo_handle(cursor->bo); |
| 671 | pitches[0] = armsoc_bo_pitch(cursor->bo); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 672 | offsets[0] = 0; |
| 673 | |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 674 | /* allow for cursor padding in the fb */ |
| 675 | if (drmModeAddFB2(drmmode->fd, w + 2 * pad, h, DRM_FORMAT_ARGB8888, |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 676 | handles, pitches, offsets, &cursor->fb_id, 0)) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 677 | ERROR_MSG("HW cursor: drmModeAddFB2 failed: %s", |
| 678 | strerror(errno)); |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 679 | armsoc_bo_unreference(cursor->bo); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 680 | free(cursor); |
| 681 | drmModeFreePlane(ovr); |
| 682 | drmModeFreePlaneResources(plane_resources); |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 683 | return FALSE; |
| 684 | } |
| 685 | |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 686 | if (!xf86_cursors_init(pScreen, w, h, HARDWARE_CURSOR_ARGB)) { |
| 687 | ERROR_MSG("xf86_cursors_init() failed"); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 688 | if (drmModeRmFB(drmmode->fd, cursor->fb_id)) |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 689 | ERROR_MSG("drmModeRmFB() failed"); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 690 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 691 | armsoc_bo_unreference(cursor->bo); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 692 | free(cursor); |
| 693 | drmModeFreePlane(ovr); |
| 694 | drmModeFreePlaneResources(plane_resources); |
| 695 | return FALSE; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 696 | } |
| 697 | |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 698 | INFO_MSG("HW cursor initialized"); |
| 699 | drmmode->cursor = cursor; |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 700 | drmModeFreePlaneResources(plane_resources); |
Ray Smith | 003cf5e | 2013-03-19 10:44:07 +0000 | [diff] [blame] | 701 | return TRUE; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 702 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 703 | |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 704 | static Bool |
| 705 | drmmode_cursor_init_standard(ScreenPtr pScreen) |
| 706 | { |
| 707 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
| 708 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 709 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
| 710 | struct drmmode_cursor_rec *cursor; |
| 711 | int w, h, pad; |
| 712 | |
| 713 | if (drmmode->cursor) { |
| 714 | INFO_MSG("cursor already initialized"); |
| 715 | return TRUE; |
| 716 | } |
| 717 | |
| 718 | if (!xf86LoaderCheckSymbol("drmModeSetCursor") || |
| 719 | !xf86LoaderCheckSymbol("drmModeMoveCursor")) { |
Dave Barnish | 8e9ac7b | 2013-09-12 14:17:33 +0100 | [diff] [blame] | 720 | ERROR_MSG( |
| 721 | "Standard HW cursor not supported (needs libdrm 2.4.3 or higher)"); |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 722 | return FALSE; |
| 723 | } |
| 724 | |
| 725 | cursor = calloc(1, sizeof(struct drmmode_cursor_rec)); |
| 726 | if (!cursor) { |
| 727 | ERROR_MSG("HW cursor (standard): calloc failed"); |
| 728 | return FALSE; |
| 729 | } |
| 730 | |
| 731 | w = pARMSOC->drmmode_interface->cursor_width; |
| 732 | h = pARMSOC->drmmode_interface->cursor_height; |
| 733 | pad = pARMSOC->drmmode_interface->cursor_padding; |
| 734 | |
| 735 | /* allow for cursor padding in the bo */ |
| 736 | cursor->bo = armsoc_bo_new_with_dim(pARMSOC->dev, |
| 737 | w + 2 * pad, h, |
| 738 | 0, 32, ARMSOC_BO_SCANOUT); |
| 739 | |
| 740 | if (!cursor->bo) { |
| 741 | ERROR_MSG("HW cursor (standard): buffer allocation failed"); |
| 742 | free(cursor); |
| 743 | return FALSE; |
| 744 | } |
| 745 | |
| 746 | cursor->handle = armsoc_bo_handle(cursor->bo); |
| 747 | |
| 748 | if (!xf86_cursors_init(pScreen, w, h, HARDWARE_CURSOR_ARGB)) { |
| 749 | ERROR_MSG("xf86_cursors_init() failed"); |
| 750 | if (drmModeRmFB(drmmode->fd, cursor->fb_id)) |
| 751 | ERROR_MSG("drmModeRmFB() failed"); |
| 752 | |
| 753 | armsoc_bo_unreference(cursor->bo); |
| 754 | free(cursor); |
| 755 | return FALSE; |
| 756 | } |
| 757 | |
| 758 | INFO_MSG("HW cursor initialized"); |
| 759 | drmmode->cursor = cursor; |
| 760 | return TRUE; |
| 761 | } |
| 762 | |
| 763 | Bool drmmode_cursor_init(ScreenPtr pScreen) |
| 764 | { |
| 765 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
| 766 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 767 | |
| 768 | INFO_MSG("HW cursor init()"); |
| 769 | |
| 770 | if (pARMSOC->drmmode_interface->cursor_api == HWCURSOR_API_PLANE) |
| 771 | return drmmode_cursor_init_plane(pScreen); |
| 772 | else /* HWCURSOR_API_STANDARD */ |
| 773 | return drmmode_cursor_init_standard(pScreen); |
| 774 | } |
| 775 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 776 | void drmmode_cursor_fini(ScreenPtr pScreen) |
| 777 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 778 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 779 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
| 780 | struct drmmode_cursor_rec *cursor = drmmode->cursor; |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 781 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 782 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 783 | if (!cursor) |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 784 | return; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 785 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 786 | drmmode->cursor = NULL; |
| 787 | xf86_cursors_fini(pScreen); |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 788 | if (pARMSOC->drmmode_interface->cursor_api == HWCURSOR_API_PLANE) |
| 789 | drmModeRmFB(drmmode->fd, cursor->fb_id); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 790 | armsoc_bo_unreference(cursor->bo); |
Javier Martin | 4c57279 | 2013-09-11 15:08:19 +0100 | [diff] [blame] | 791 | if (pARMSOC->drmmode_interface->cursor_api == HWCURSOR_API_PLANE) |
| 792 | drmModeFreePlane(cursor->ovr); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 793 | free(cursor); |
| 794 | } |
| 795 | |
| 796 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 797 | #if 1 == ARMSOC_SUPPORT_GAMMA |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 798 | static void |
| 799 | drmmode_gamma_set(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 800 | int size) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 801 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 802 | struct drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; |
| 803 | struct drmmode_rec *drmmode = drmmode_crtc->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 804 | int ret; |
| 805 | |
| 806 | ret = drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 807 | size, red, green, blue); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 808 | if (ret != 0) { |
| 809 | xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 810 | "failed to set gamma: %s\n", strerror(-ret)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 811 | } |
| 812 | } |
Mandeep Singh Baines | c874fcb | 2012-09-13 15:30:00 +0200 | [diff] [blame] | 813 | #endif |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 814 | |
| 815 | static const xf86CrtcFuncsRec drmmode_crtc_funcs = { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 816 | .dpms = drmmode_crtc_dpms, |
| 817 | .set_mode_major = drmmode_set_mode_major, |
| 818 | .set_cursor_position = drmmode_set_cursor_position, |
| 819 | .show_cursor = drmmode_show_cursor, |
| 820 | .hide_cursor = drmmode_hide_cursor, |
| 821 | .load_cursor_argb = drmmode_load_cursor_argb, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 822 | #if 1 == ARMSOC_SUPPORT_GAMMA |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 823 | .gamma_set = drmmode_gamma_set, |
Mandeep Singh Baines | c874fcb | 2012-09-13 15:30:00 +0200 | [diff] [blame] | 824 | #endif |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 825 | }; |
| 826 | |
| 827 | |
| 828 | static void |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 829 | drmmode_crtc_init(ScrnInfoPtr pScrn, struct drmmode_rec *drmmode, int num) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 830 | { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 831 | xf86CrtcPtr crtc; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 832 | struct drmmode_crtc_private_rec *drmmode_crtc; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 833 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 834 | TRACE_ENTER(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 835 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 836 | crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs); |
| 837 | if (crtc == NULL) |
| 838 | return; |
| 839 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 840 | drmmode_crtc = xnfcalloc(sizeof(struct drmmode_crtc_private_rec), 1); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 841 | drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, |
| 842 | drmmode->mode_res->crtcs[num]); |
| 843 | drmmode_crtc->drmmode = drmmode; |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 844 | drmmode_crtc->last_good_mode = NULL; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 845 | |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 846 | INFO_MSG("Got CRTC: %d (id: %d)", |
| 847 | num, drmmode_crtc->mode_crtc->crtc_id); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 848 | crtc->driver_private = drmmode_crtc; |
| 849 | |
| 850 | TRACE_EXIT(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 851 | return; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 852 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 853 | |
| 854 | static xf86OutputStatus |
| 855 | drmmode_output_detect(xf86OutputPtr output) |
| 856 | { |
| 857 | /* go to the hw and retrieve a new output struct */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 858 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
| 859 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 860 | xf86OutputStatus status; |
| 861 | drmModeFreeConnector(drmmode_output->mode_output); |
| 862 | |
| 863 | drmmode_output->mode_output = |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 864 | drmModeGetConnector(drmmode->fd, |
| 865 | drmmode_output->output_id); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 866 | |
| 867 | switch (drmmode_output->mode_output->connection) { |
| 868 | case DRM_MODE_CONNECTED: |
| 869 | status = XF86OutputStatusConnected; |
| 870 | break; |
| 871 | case DRM_MODE_DISCONNECTED: |
| 872 | status = XF86OutputStatusDisconnected; |
| 873 | break; |
| 874 | default: |
| 875 | case DRM_MODE_UNKNOWNCONNECTION: |
| 876 | status = XF86OutputStatusUnknown; |
| 877 | break; |
| 878 | } |
| 879 | return status; |
| 880 | } |
| 881 | |
| 882 | static Bool |
| 883 | drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr mode) |
| 884 | { |
| 885 | if (mode->type & M_T_DEFAULT) |
| 886 | /* Default modes are harmful here. */ |
| 887 | return MODE_BAD; |
| 888 | |
| 889 | return MODE_OK; |
| 890 | } |
| 891 | |
| 892 | static DisplayModePtr |
| 893 | drmmode_output_get_modes(xf86OutputPtr output) |
| 894 | { |
| 895 | ScrnInfoPtr pScrn = output->scrn; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 896 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 897 | drmModeConnectorPtr koutput = drmmode_output->mode_output; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 898 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 899 | DisplayModePtr modes = NULL; |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 900 | drmModePropertyPtr prop; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 901 | xf86MonPtr ddc_mon = NULL; |
| 902 | int i; |
| 903 | |
| 904 | /* look for an EDID property */ |
| 905 | for (i = 0; i < koutput->count_props; i++) { |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 906 | prop = drmModeGetProperty(drmmode->fd, koutput->props[i]); |
| 907 | if (!prop) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 908 | continue; |
| 909 | |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 910 | if ((prop->flags & DRM_MODE_PROP_BLOB) && |
| 911 | !strcmp(prop->name, "EDID")) { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 912 | if (drmmode_output->edid_blob) |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 913 | drmModeFreePropertyBlob( |
| 914 | drmmode_output->edid_blob); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 915 | drmmode_output->edid_blob = |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 916 | drmModeGetPropertyBlob(drmmode->fd, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 917 | koutput->prop_values[i]); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 918 | } |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 919 | drmModeFreeProperty(prop); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | if (drmmode_output->edid_blob) |
| 923 | ddc_mon = xf86InterpretEDID(pScrn->scrnIndex, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 924 | drmmode_output->edid_blob->data); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 925 | |
| 926 | if (ddc_mon) { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 927 | xf86OutputSetEDID(output, ddc_mon); |
| 928 | xf86SetDDCproperties(pScrn, ddc_mon); |
| 929 | } |
| 930 | |
| 931 | DEBUG_MSG("count_modes: %d", koutput->count_modes); |
| 932 | |
| 933 | /* modes should already be available */ |
| 934 | for (i = 0; i < koutput->count_modes; i++) { |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 935 | DisplayModePtr mode = xnfalloc(sizeof(DisplayModeRec)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 936 | |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 937 | drmmode_ConvertFromKMode(pScrn, &koutput->modes[i], mode); |
| 938 | modes = xf86ModesAdd(modes, mode); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 939 | } |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 940 | return modes; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static void |
| 944 | drmmode_output_destroy(xf86OutputPtr output) |
| 945 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 946 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 947 | int i; |
| 948 | |
| 949 | if (drmmode_output->edid_blob) |
| 950 | drmModeFreePropertyBlob(drmmode_output->edid_blob); |
| 951 | for (i = 0; i < drmmode_output->num_props; i++) { |
| 952 | drmModeFreeProperty(drmmode_output->props[i].mode_prop); |
| 953 | free(drmmode_output->props[i].atoms); |
| 954 | } |
Daniel Kurtz | f5a38ad | 2012-10-17 02:03:34 +0800 | [diff] [blame] | 955 | free(drmmode_output->props); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 956 | drmModeFreeConnector(drmmode_output->mode_output); |
| 957 | free(drmmode_output); |
| 958 | output->driver_private = NULL; |
| 959 | } |
| 960 | |
| 961 | static void |
| 962 | drmmode_output_dpms(xf86OutputPtr output, int mode) |
| 963 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 964 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 965 | drmModeConnectorPtr koutput = drmmode_output->mode_output; |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 966 | drmModePropertyPtr prop; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 967 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 968 | int mode_id = -1, i; |
| 969 | |
| 970 | for (i = 0; i < koutput->count_props; i++) { |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 971 | prop = drmModeGetProperty(drmmode->fd, koutput->props[i]); |
| 972 | if (!prop) |
| 973 | continue; |
| 974 | if ((prop->flags & DRM_MODE_PROP_ENUM) && |
| 975 | !strcmp(prop->name, "DPMS")) { |
| 976 | mode_id = koutput->props[i]; |
| 977 | drmModeFreeProperty(prop); |
| 978 | break; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 979 | } |
Daniel Kurtz | b813189 | 2012-10-17 01:39:54 +0800 | [diff] [blame] | 980 | drmModeFreeProperty(prop); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | if (mode_id < 0) |
| 984 | return; |
| 985 | |
| 986 | drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 987 | mode_id, mode); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static Bool |
| 991 | drmmode_property_ignore(drmModePropertyPtr prop) |
| 992 | { |
| 993 | if (!prop) |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 994 | return TRUE; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 995 | /* ignore blob prop */ |
| 996 | if (prop->flags & DRM_MODE_PROP_BLOB) |
| 997 | return TRUE; |
| 998 | /* ignore standard property */ |
| 999 | if (!strcmp(prop->name, "EDID") || |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1000 | !strcmp(prop->name, "DPMS")) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1001 | return TRUE; |
| 1002 | |
| 1003 | return FALSE; |
| 1004 | } |
| 1005 | |
| 1006 | static void |
| 1007 | drmmode_output_create_resources(xf86OutputPtr output) |
| 1008 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1009 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1010 | drmModeConnectorPtr mode_output = drmmode_output->mode_output; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1011 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1012 | drmModePropertyPtr drmmode_prop; |
| 1013 | uint32_t value; |
| 1014 | int i, j, err; |
| 1015 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1016 | drmmode_output->props = |
| 1017 | calloc(mode_output->count_props, |
| 1018 | sizeof(struct drmmode_prop_rec)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1019 | if (!drmmode_output->props) |
| 1020 | return; |
| 1021 | |
| 1022 | drmmode_output->num_props = 0; |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 1023 | for (i = 0; i < mode_output->count_props; i++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1024 | drmmode_prop = drmModeGetProperty(drmmode->fd, |
| 1025 | mode_output->props[i]); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1026 | if (drmmode_property_ignore(drmmode_prop)) { |
| 1027 | drmModeFreeProperty(drmmode_prop); |
| 1028 | continue; |
| 1029 | } |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1030 | drmmode_output->props[drmmode_output->num_props].mode_prop = |
| 1031 | drmmode_prop; |
Dave Barnish | 0bdb738 | 2013-06-06 12:04:04 +0100 | [diff] [blame] | 1032 | drmmode_output->props[drmmode_output->num_props].index = i; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1033 | drmmode_output->num_props++; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | for (i = 0; i < drmmode_output->num_props; i++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1037 | struct drmmode_prop_rec *p = &drmmode_output->props[i]; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1038 | drmmode_prop = p->mode_prop; |
| 1039 | |
| 1040 | value = drmmode_output->mode_output->prop_values[p->index]; |
| 1041 | |
| 1042 | if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { |
| 1043 | INT32 range[2]; |
| 1044 | |
| 1045 | p->num_atoms = 1; |
| 1046 | p->atoms = calloc(p->num_atoms, sizeof(Atom)); |
| 1047 | if (!p->atoms) |
| 1048 | continue; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1049 | p->atoms[0] = MakeAtom(drmmode_prop->name, |
| 1050 | strlen(drmmode_prop->name), |
| 1051 | TRUE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1052 | range[0] = drmmode_prop->values[0]; |
| 1053 | range[1] = drmmode_prop->values[1]; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1054 | err = RRConfigureOutputProperty(output->randr_output, |
| 1055 | p->atoms[0], |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1056 | FALSE, TRUE, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1057 | drmmode_prop->flags & |
| 1058 | DRM_MODE_PROP_IMMUTABLE ? |
| 1059 | TRUE : FALSE, |
| 1060 | 2, range); |
| 1061 | |
| 1062 | if (err != 0) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1063 | xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1064 | "RRConfigureOutputProperty error, %d\n", |
| 1065 | err); |
| 1066 | |
| 1067 | err = RRChangeOutputProperty(output->randr_output, |
| 1068 | p->atoms[0], |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1069 | XA_INTEGER, 32, PropModeReplace, 1, |
| 1070 | &value, FALSE, FALSE); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1071 | if (err != 0) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1072 | xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1073 | "RRChangeOutputProperty error, %d\n", |
| 1074 | err); |
| 1075 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1076 | } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { |
| 1077 | p->num_atoms = drmmode_prop->count_enums + 1; |
| 1078 | p->atoms = calloc(p->num_atoms, sizeof(Atom)); |
| 1079 | if (!p->atoms) |
| 1080 | continue; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1081 | p->atoms[0] = MakeAtom(drmmode_prop->name, |
| 1082 | strlen(drmmode_prop->name), |
| 1083 | TRUE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1084 | for (j = 1; j <= drmmode_prop->count_enums; j++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1085 | struct drm_mode_property_enum *e = |
| 1086 | &drmmode_prop->enums[j-1]; |
| 1087 | p->atoms[j] = MakeAtom(e->name, |
| 1088 | strlen(e->name), TRUE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1089 | } |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1090 | err = RRConfigureOutputProperty(output->randr_output, |
| 1091 | p->atoms[0], |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1092 | FALSE, FALSE, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1093 | drmmode_prop->flags & |
| 1094 | DRM_MODE_PROP_IMMUTABLE ? |
| 1095 | TRUE : FALSE, |
| 1096 | p->num_atoms - 1, |
| 1097 | (INT32 *)&p->atoms[1]); |
| 1098 | |
| 1099 | if (err != 0) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1100 | xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1101 | "RRConfigureOutputProperty error, %d\n", |
| 1102 | err); |
| 1103 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1104 | for (j = 0; j < drmmode_prop->count_enums; j++) |
| 1105 | if (drmmode_prop->enums[j].value == value) |
| 1106 | break; |
| 1107 | /* there's always a matching value */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1108 | err = RRChangeOutputProperty(output->randr_output, |
| 1109 | p->atoms[0], |
| 1110 | XA_ATOM, 32, PropModeReplace, 1, |
| 1111 | &p->atoms[j+1], FALSE, FALSE); |
| 1112 | if (err != 0) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1113 | xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1114 | "RRChangeOutputProperty error, %d\n", |
| 1115 | err); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | static Bool |
| 1121 | drmmode_output_set_property(xf86OutputPtr output, Atom property, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1122 | RRPropertyValuePtr value) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1123 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1124 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
| 1125 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1126 | int i, ret; |
| 1127 | |
| 1128 | for (i = 0; i < drmmode_output->num_props; i++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1129 | struct drmmode_prop_rec *p = &drmmode_output->props[i]; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1130 | |
| 1131 | if (p->atoms[0] != property) |
| 1132 | continue; |
| 1133 | |
| 1134 | if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) { |
| 1135 | uint32_t val; |
| 1136 | |
| 1137 | if (value->type != XA_INTEGER || value->format != 32 || |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1138 | value->size != 1) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1139 | return FALSE; |
| 1140 | val = *(uint32_t *)value->data; |
| 1141 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1142 | ret = drmModeConnectorSetProperty(drmmode->fd, |
| 1143 | drmmode_output->output_id, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1144 | p->mode_prop->prop_id, (uint64_t)val); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1145 | |
| 1146 | if (ret) |
| 1147 | return FALSE; |
| 1148 | |
| 1149 | return TRUE; |
| 1150 | |
| 1151 | } else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) { |
| 1152 | Atom atom; |
| 1153 | const char *name; |
| 1154 | int j; |
| 1155 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1156 | if (value->type != XA_ATOM || |
| 1157 | value->format != 32 || |
| 1158 | value->size != 1) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1159 | return FALSE; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1160 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1161 | memcpy(&atom, value->data, 4); |
| 1162 | name = NameForAtom(atom); |
Daniel Kurtz | 2314837 | 2013-03-27 20:19:45 +0800 | [diff] [blame] | 1163 | if (name == NULL) |
| 1164 | return FALSE; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1165 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1166 | /* search for matching name string, then |
| 1167 | * set its value down |
| 1168 | */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1169 | for (j = 0; j < p->mode_prop->count_enums; j++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1170 | if (!strcmp(p->mode_prop->enums[j].name, |
| 1171 | name)) { |
| 1172 | ret = drmModeConnectorSetProperty( |
| 1173 | drmmode->fd, |
| 1174 | drmmode_output->output_id, |
| 1175 | p->mode_prop->prop_id, |
| 1176 | p->mode_prop->enums[j].value); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1177 | |
| 1178 | if (ret) |
| 1179 | return FALSE; |
| 1180 | |
| 1181 | return TRUE; |
| 1182 | } |
| 1183 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1184 | return FALSE; |
| 1185 | } |
| 1186 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1187 | return TRUE; |
| 1188 | } |
| 1189 | |
| 1190 | static Bool |
| 1191 | drmmode_output_get_property(xf86OutputPtr output, Atom property) |
| 1192 | { |
| 1193 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1194 | struct drmmode_output_priv *drmmode_output = output->driver_private; |
| 1195 | struct drmmode_rec *drmmode = drmmode_output->drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1196 | uint32_t value; |
| 1197 | int err, i; |
| 1198 | |
| 1199 | if (output->scrn->vtSema) { |
| 1200 | drmModeFreeConnector(drmmode_output->mode_output); |
| 1201 | drmmode_output->mode_output = |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1202 | drmModeGetConnector(drmmode->fd, |
| 1203 | drmmode_output->output_id); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | for (i = 0; i < drmmode_output->num_props; i++) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1207 | struct drmmode_prop_rec *p = &drmmode_output->props[i]; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1208 | if (p->atoms[0] != property) |
| 1209 | continue; |
| 1210 | |
| 1211 | value = drmmode_output->mode_output->prop_values[p->index]; |
| 1212 | |
| 1213 | if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) { |
| 1214 | err = RRChangeOutputProperty(output->randr_output, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1215 | property, XA_INTEGER, 32, |
| 1216 | PropModeReplace, 1, &value, |
| 1217 | FALSE, FALSE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1218 | |
| 1219 | return !err; |
| 1220 | } else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) { |
| 1221 | int j; |
| 1222 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1223 | /* search for matching name string, then set |
| 1224 | * its value down |
| 1225 | */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1226 | for (j = 0; j < p->mode_prop->count_enums; j++) { |
| 1227 | if (p->mode_prop->enums[j].value == value) |
| 1228 | break; |
| 1229 | } |
| 1230 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1231 | err = RRChangeOutputProperty(output->randr_output, |
| 1232 | property, |
| 1233 | XA_ATOM, 32, PropModeReplace, 1, |
| 1234 | &p->atoms[j+1], FALSE, FALSE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1235 | |
| 1236 | return !err; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | return FALSE; |
| 1241 | } |
| 1242 | |
| 1243 | static const xf86OutputFuncsRec drmmode_output_funcs = { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1244 | .create_resources = drmmode_output_create_resources, |
| 1245 | .dpms = drmmode_output_dpms, |
| 1246 | .detect = drmmode_output_detect, |
| 1247 | .mode_valid = drmmode_output_mode_valid, |
| 1248 | .get_modes = drmmode_output_get_modes, |
| 1249 | .set_property = drmmode_output_set_property, |
| 1250 | .get_property = drmmode_output_get_property, |
| 1251 | .destroy = drmmode_output_destroy |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1252 | }; |
| 1253 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1254 | const char *output_names[] = { "None", |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1255 | "VGA", |
| 1256 | "DVI-I", |
| 1257 | "DVI-D", |
| 1258 | "DVI-A", |
| 1259 | "Composite", |
| 1260 | "SVIDEO", |
| 1261 | "LVDS", |
| 1262 | "CTV", |
| 1263 | "DIN", |
| 1264 | "DP", |
| 1265 | "HDMI", |
| 1266 | "HDMI", |
| 1267 | "TV", |
| 1268 | "eDP", |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1269 | }; |
| 1270 | #define NUM_OUTPUT_NAMES (sizeof(output_names) / sizeof(output_names[0])) |
| 1271 | |
| 1272 | static void |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1273 | drmmode_output_init(ScrnInfoPtr pScrn, struct drmmode_rec *drmmode, int num) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1274 | { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1275 | xf86OutputPtr output; |
| 1276 | drmModeConnectorPtr koutput; |
| 1277 | drmModeEncoderPtr kencoder; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1278 | struct drmmode_output_priv *drmmode_output; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1279 | char name[32]; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1280 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1281 | TRACE_ENTER(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1282 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1283 | koutput = drmModeGetConnector(drmmode->fd, |
| 1284 | drmmode->mode_res->connectors[num]); |
| 1285 | if (!koutput) |
| 1286 | return; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1287 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1288 | kencoder = drmModeGetEncoder(drmmode->fd, koutput->encoders[0]); |
| 1289 | if (!kencoder) { |
| 1290 | drmModeFreeConnector(koutput); |
| 1291 | return; |
| 1292 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1293 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1294 | if (koutput->connector_type >= NUM_OUTPUT_NAMES) |
| 1295 | snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, |
| 1296 | koutput->connector_type_id); |
| 1297 | else |
| 1298 | snprintf(name, 32, "%s-%d", |
| 1299 | output_names[koutput->connector_type], |
| 1300 | koutput->connector_type_id); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1301 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1302 | output = xf86OutputCreate(pScrn, &drmmode_output_funcs, name); |
| 1303 | if (!output) { |
| 1304 | drmModeFreeEncoder(kencoder); |
| 1305 | drmModeFreeConnector(koutput); |
| 1306 | return; |
| 1307 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1308 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1309 | drmmode_output = calloc(sizeof(struct drmmode_output_priv), 1); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1310 | if (!drmmode_output) { |
| 1311 | xf86OutputDestroy(output); |
| 1312 | drmModeFreeConnector(koutput); |
| 1313 | drmModeFreeEncoder(kencoder); |
| 1314 | return; |
| 1315 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1316 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1317 | drmmode_output->output_id = drmmode->mode_res->connectors[num]; |
| 1318 | drmmode_output->mode_output = koutput; |
| 1319 | drmmode_output->mode_encoder = kencoder; |
| 1320 | drmmode_output->drmmode = drmmode; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1321 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1322 | output->mm_width = koutput->mmWidth; |
| 1323 | output->mm_height = koutput->mmHeight; |
| 1324 | output->driver_private = drmmode_output; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1325 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1326 | if (ARMSOCPTR(pScrn)->crtcNum >= 0) { |
| 1327 | /* Only single crtc per screen - see if this output can use it*/ |
| 1328 | output->possible_crtcs = |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1329 | (kencoder->possible_crtcs >> |
| 1330 | (ARMSOCPTR(pScrn)->crtcNum) |
| 1331 | )&1; |
| 1332 | } else |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1333 | output->possible_crtcs = kencoder->possible_crtcs; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1334 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1335 | output->possible_clones = kencoder->possible_clones; |
| 1336 | output->interlaceAllowed = TRUE; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1337 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1338 | TRACE_EXIT(); |
| 1339 | return; |
| 1340 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1341 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1342 | void set_scanout_bo(ScrnInfoPtr pScrn, struct armsoc_bo *bo) |
David Garbett | 3688b33 | 2012-05-11 12:17:34 +0100 | [diff] [blame] | 1343 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1344 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
David Garbett | 3688b33 | 2012-05-11 12:17:34 +0100 | [diff] [blame] | 1345 | |
| 1346 | /* It had better have a framebuffer if we're scanning it out */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1347 | assert(armsoc_bo_get_fb(bo)); |
David Garbett | 3688b33 | 2012-05-11 12:17:34 +0100 | [diff] [blame] | 1348 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1349 | pARMSOC->scanout = bo; |
David Garbett | 3688b33 | 2012-05-11 12:17:34 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 1352 | static Bool resize_scanout_bo(ScrnInfoPtr pScrn, int width, int height) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1353 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1354 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1355 | ScreenPtr pScreen = pScrn->pScreen; |
Sean Paul | 3e10730 | 2012-08-30 12:08:12 -0700 | [diff] [blame] | 1356 | uint32_t pitch; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1357 | |
| 1358 | TRACE_ENTER(); |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1359 | DEBUG_MSG("Resize: %dx%d", width, height); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1360 | |
| 1361 | pScrn->virtualX = width; |
| 1362 | pScrn->virtualY = height; |
| 1363 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1364 | if ((width != armsoc_bo_width(pARMSOC->scanout)) |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1365 | || (height != armsoc_bo_height(pARMSOC->scanout)) |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1366 | || (pScrn->bitsPerPixel != armsoc_bo_bpp(pARMSOC->scanout))) { |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1367 | struct armsoc_bo *new_scanout; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1368 | |
| 1369 | /* allocate new scanout buffer */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1370 | new_scanout = armsoc_bo_new_with_dim(pARMSOC->dev, |
| 1371 | width, height, |
| 1372 | pScrn->depth, pScrn->bitsPerPixel, |
| 1373 | ARMSOC_BO_SCANOUT); |
| 1374 | if (!new_scanout) { |
| 1375 | /* Try to use the previous buffer if the new resolution |
| 1376 | * is smaller than the one on buffer creation |
| 1377 | */ |
| 1378 | DEBUG_MSG( |
| 1379 | "allocate new scanout buffer failed - resizing existing bo"); |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1380 | /* Remove the old fb from the bo */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1381 | if (armsoc_bo_rm_fb(pARMSOC->scanout)) |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1382 | return FALSE; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1383 | |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1384 | /* Resize the bo */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1385 | if (armsoc_bo_resize(pARMSOC->scanout, width, height)) { |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1386 | armsoc_bo_clear(pARMSOC->scanout); |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1387 | if (armsoc_bo_add_fb(pARMSOC->scanout)) |
| 1388 | ERROR_MSG( |
| 1389 | "Failed to add framebuffer to the existing scanout buffer"); |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1390 | return FALSE; |
| 1391 | } |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1392 | |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1393 | /* Add new fb to the bo */ |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1394 | if (armsoc_bo_clear(pARMSOC->scanout)) |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1395 | return FALSE; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1396 | |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1397 | if (armsoc_bo_add_fb(pARMSOC->scanout)) { |
| 1398 | ERROR_MSG( |
| 1399 | "Failed to add framebuffer to the existing scanout buffer"); |
| 1400 | return FALSE; |
| 1401 | } |
| 1402 | |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1403 | pitch = armsoc_bo_pitch(pARMSOC->scanout); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1404 | } else { |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1405 | DEBUG_MSG("allocated new scanout buffer okay"); |
| 1406 | pitch = armsoc_bo_pitch(new_scanout); |
| 1407 | /* clear new BO and add FB */ |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1408 | if (armsoc_bo_clear(new_scanout)) { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1409 | armsoc_bo_unreference(new_scanout); |
David Garbett | ae5a636 | 2012-07-02 10:15:47 +0100 | [diff] [blame] | 1410 | return FALSE; |
| 1411 | } |
Ray Smith | b4299f8 | 2013-03-13 10:08:36 +0000 | [diff] [blame] | 1412 | |
| 1413 | if (armsoc_bo_add_fb(new_scanout)) { |
| 1414 | ERROR_MSG( |
| 1415 | "Failed to add framebuffer to the new scanout buffer"); |
| 1416 | armsoc_bo_unreference(new_scanout); |
| 1417 | return FALSE; |
| 1418 | } |
| 1419 | |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1420 | /* Handle dma_buf fd that may be attached to old bo */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1421 | if (armsoc_bo_has_dmabuf(pARMSOC->scanout)) { |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1422 | int res; |
| 1423 | |
| 1424 | armsoc_bo_clear_dmabuf(pARMSOC->scanout); |
| 1425 | res = armsoc_bo_set_dmabuf(new_scanout); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1426 | if (res) { |
| 1427 | ERROR_MSG( |
| 1428 | "Unable to attach dma_buf fd to new scanout buffer - %d (%s)\n", |
| 1429 | res, strerror(res)); |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1430 | armsoc_bo_unreference(new_scanout); |
| 1431 | return FALSE; |
| 1432 | } |
| 1433 | } |
| 1434 | /* delete old scanout buffer */ |
| 1435 | armsoc_bo_unreference(pARMSOC->scanout); |
| 1436 | /* use new scanout buffer */ |
| 1437 | set_scanout_bo(pScrn, new_scanout); |
David Garbett | ae5a636 | 2012-07-02 10:15:47 +0100 | [diff] [blame] | 1438 | } |
Daniel Kurtz | 34e72b0 | 2012-10-19 14:02:05 -0700 | [diff] [blame] | 1439 | pScrn->displayWidth = pitch / ((pScrn->bitsPerPixel + 7) / 8); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1440 | } else |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1441 | pitch = armsoc_bo_pitch(pARMSOC->scanout); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1442 | |
| 1443 | if (pScreen && pScreen->ModifyPixmapHeader) { |
| 1444 | PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); |
Dave Barnish | 3386605 | 2013-03-18 10:57:40 +0000 | [diff] [blame] | 1445 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1446 | pScreen->ModifyPixmapHeader(rootPixmap, |
| 1447 | pScrn->virtualX, pScrn->virtualY, |
| 1448 | pScrn->depth, pScrn->bitsPerPixel, pitch, |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1449 | armsoc_bo_map(pARMSOC->scanout)); |
Ray Smith | edccfd8 | 2013-05-31 15:57:12 +0100 | [diff] [blame] | 1450 | |
Dave Barnish | e762b12 | 2013-08-12 17:13:46 +0100 | [diff] [blame] | 1451 | /* Bump the serial number to ensure that all existing DRI2 |
| 1452 | * buffers are invalidated. |
Ray Smith | edccfd8 | 2013-05-31 15:57:12 +0100 | [diff] [blame] | 1453 | * |
Dave Barnish | e762b12 | 2013-08-12 17:13:46 +0100 | [diff] [blame] | 1454 | * This is particularly required for when the resolution is |
| 1455 | * changed and then reverted to the original size without a |
| 1456 | * DRI2 client/s getting a new buffer. Without this, the |
| 1457 | * drawable is the same size and serial number so the old |
| 1458 | * DRI2Buffer will be returned, even though the backing buffer |
| 1459 | * has been deleted. |
Ray Smith | edccfd8 | 2013-05-31 15:57:12 +0100 | [diff] [blame] | 1460 | */ |
| 1461 | rootPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1462 | } |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 1463 | TRACE_EXIT(); |
| 1464 | return TRUE; |
| 1465 | } |
| 1466 | |
| 1467 | static Bool |
| 1468 | drmmode_xf86crtc_resize(ScrnInfoPtr pScrn, int width, int height) |
| 1469 | { |
| 1470 | int i; |
| 1471 | xf86CrtcConfigPtr xf86_config; |
| 1472 | |
| 1473 | TRACE_ENTER(); |
Dave Barnish | f245da3 | 2013-08-30 12:16:58 +0100 | [diff] [blame] | 1474 | if (!resize_scanout_bo(pScrn, width, height)) |
| 1475 | return FALSE; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1476 | |
Brian Starkey | cd68442 | 2012-09-20 09:28:04 +0100 | [diff] [blame] | 1477 | /* Framebuffer needs to be reset on all CRTCs, not just |
| 1478 | * those that have repositioned */ |
| 1479 | xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); |
| 1480 | for (i = 0; i < xf86_config->num_crtc; i++) { |
| 1481 | xf86CrtcPtr crtc = xf86_config->crtc[i]; |
| 1482 | |
| 1483 | if (!crtc->enabled) |
| 1484 | continue; |
| 1485 | |
| 1486 | drmmode_set_mode_major(crtc, &crtc->mode, |
| 1487 | crtc->rotation, crtc->x, crtc->y); |
| 1488 | } |
| 1489 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1490 | TRACE_EXIT(); |
| 1491 | return TRUE; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1492 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1493 | |
| 1494 | static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = { |
Daniel Kurtz | e81fdab | 2012-12-25 16:43:04 +0800 | [diff] [blame] | 1495 | .resize = drmmode_xf86crtc_resize |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1496 | }; |
| 1497 | |
| 1498 | |
| 1499 | Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp) |
| 1500 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1501 | struct drmmode_rec *drmmode; |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1502 | int i; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1503 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1504 | TRACE_ENTER(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1505 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1506 | drmmode = calloc(1, sizeof *drmmode); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1507 | if (!drmmode) |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 1508 | return FALSE; |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 1509 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1510 | drmmode->fd = fd; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1511 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1512 | xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1513 | |
| 1514 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1515 | drmmode->cpp = cpp; |
| 1516 | drmmode->mode_res = drmModeGetResources(drmmode->fd); |
| 1517 | if (!drmmode->mode_res) { |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 1518 | free(drmmode); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1519 | return FALSE; |
| 1520 | } else { |
| 1521 | DEBUG_MSG("Got KMS resources"); |
| 1522 | DEBUG_MSG(" %d connectors, %d encoders", |
| 1523 | drmmode->mode_res->count_connectors, |
| 1524 | drmmode->mode_res->count_encoders); |
| 1525 | DEBUG_MSG(" %d crtcs, %d fbs", |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1526 | drmmode->mode_res->count_crtcs, |
| 1527 | drmmode->mode_res->count_fbs); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1528 | DEBUG_MSG(" %dx%d minimum resolution", |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1529 | drmmode->mode_res->min_width, |
| 1530 | drmmode->mode_res->min_height); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1531 | DEBUG_MSG(" %dx%d maximum resolution", |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1532 | drmmode->mode_res->max_width, |
| 1533 | drmmode->mode_res->max_height); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1534 | } |
| 1535 | xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width, |
| 1536 | drmmode->mode_res->max_height); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1537 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1538 | if (ARMSOCPTR(pScrn)->crtcNum == -1) { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1539 | INFO_MSG("Adding all CRTCs"); |
| 1540 | for (i = 0; i < drmmode->mode_res->count_crtcs; i++) |
| 1541 | drmmode_crtc_init(pScrn, drmmode, i); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1542 | } else if (ARMSOCPTR(pScrn)->crtcNum < drmmode->mode_res->count_crtcs) { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1543 | drmmode_crtc_init(pScrn, drmmode, ARMSOCPTR(pScrn)->crtcNum); |
| 1544 | } else { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1545 | ERROR_MSG( |
| 1546 | "Specified more Screens in xorg.conf than there are DRM CRTCs"); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1547 | return FALSE; |
| 1548 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1549 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1550 | if (ARMSOCPTR(pScrn)->crtcNum != -1) { |
| 1551 | if (ARMSOCPTR(pScrn)->crtcNum < |
| 1552 | drmmode->mode_res->count_connectors) |
| 1553 | drmmode_output_init(pScrn, |
| 1554 | drmmode, ARMSOCPTR(pScrn)->crtcNum); |
Ray Smith | c9c2faf | 2013-06-07 15:37:19 +0100 | [diff] [blame] | 1555 | else |
| 1556 | return FALSE; |
| 1557 | } else { |
| 1558 | for (i = 0; i < drmmode->mode_res->count_connectors; i++) |
| 1559 | drmmode_output_init(pScrn, drmmode, i); |
| 1560 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1561 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1562 | xf86InitialConfiguration(pScrn, TRUE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1563 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1564 | TRACE_EXIT(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1565 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1566 | return TRUE; |
| 1567 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1568 | |
| 1569 | void |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1570 | drmmode_adjust_frame(ScrnInfoPtr pScrn, int x, int y) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1571 | { |
| 1572 | xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); |
| 1573 | xf86OutputPtr output = config->output[config->compat_output]; |
| 1574 | xf86CrtcPtr crtc = output->crtc; |
| 1575 | |
| 1576 | if (!crtc || !crtc->enabled) |
| 1577 | return; |
| 1578 | |
| 1579 | drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, x, y); |
| 1580 | } |
| 1581 | |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1582 | /* |
| 1583 | * Page Flipping |
| 1584 | */ |
| 1585 | |
| 1586 | static void |
| 1587 | page_flip_handler(int fd, unsigned int sequence, unsigned int tv_sec, |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1588 | unsigned int tv_usec, void *user_data) |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1589 | { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1590 | ARMSOCDRI2SwapComplete(user_data); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | static drmEventContext event_context = { |
| 1594 | .version = DRM_EVENT_CONTEXT_VERSION, |
| 1595 | .page_flip_handler = page_flip_handler, |
| 1596 | }; |
| 1597 | |
John Sheu | 022833e | 2012-08-15 11:40:11 -0700 | [diff] [blame] | 1598 | int |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1599 | drmmode_page_flip(DrawablePtr draw, uint32_t fb_id, void *priv) |
| 1600 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 1601 | ScreenPtr pScreen = draw->pScreen; |
| 1602 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1603 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 1604 | xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1605 | struct drmmode_crtc_private_rec *crtc = config->crtc[0]->driver_private; |
| 1606 | struct drmmode_rec *mode = crtc->drmmode; |
John Sheu | 022833e | 2012-08-15 11:40:11 -0700 | [diff] [blame] | 1607 | int ret, i, failed = 0, num_flipped = 0; |
Raymond Smith | 16a910e | 2012-05-09 13:04:51 +0100 | [diff] [blame] | 1608 | unsigned int flags = 0; |
| 1609 | |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 1610 | if (pARMSOC->drmmode_interface->use_page_flip_events) |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 1611 | flags |= DRM_MODE_PAGE_FLIP_EVENT; |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1612 | |
| 1613 | /* if we can flip, we must be fullscreen.. so flip all CRTC's.. */ |
| 1614 | for (i = 0; i < config->num_crtc; i++) { |
| 1615 | crtc = config->crtc[i]->driver_private; |
| 1616 | |
Ray Smith | e20b381 | 2013-04-08 12:53:53 +0100 | [diff] [blame] | 1617 | if (!config->crtc[i]->enabled) |
| 1618 | continue; |
| 1619 | |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1620 | ret = drmModePageFlip(mode->fd, crtc->mode_crtc->crtc_id, |
Raymond Smith | 16a910e | 2012-05-09 13:04:51 +0100 | [diff] [blame] | 1621 | fb_id, flags, priv); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1622 | if (ret) { |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 1623 | xf86DrvMsg(pScrn->scrnIndex, X_WARNING, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1624 | "flip queue failed: %s\n", |
| 1625 | strerror(errno)); |
John Sheu | 022833e | 2012-08-15 11:40:11 -0700 | [diff] [blame] | 1626 | failed = 1; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1627 | } else |
John Sheu | 022833e | 2012-08-15 11:40:11 -0700 | [diff] [blame] | 1628 | num_flipped += 1; |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1629 | } |
| 1630 | |
John Sheu | 022833e | 2012-08-15 11:40:11 -0700 | [diff] [blame] | 1631 | if (failed) |
| 1632 | return -(num_flipped + 1); |
| 1633 | else |
| 1634 | return num_flipped; |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1635 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1636 | |
| 1637 | /* |
| 1638 | * Hot Plug Event handling: |
David Garbett | dbecfdd | 2013-08-28 10:45:03 +0100 | [diff] [blame] | 1639 | * TODO: MIDEGL-1441: Do we need to keep this handler, which |
| 1640 | * Rob originally wrote? |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1641 | */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1642 | static void |
| 1643 | drmmode_handle_uevents(int fd, void *closure) |
| 1644 | { |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1645 | ScrnInfoPtr pScrn = closure; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1646 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 1647 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1648 | struct udev_device *dev; |
| 1649 | const char *hotplug; |
| 1650 | struct stat s; |
| 1651 | dev_t udev_devnum; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1652 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1653 | dev = udev_monitor_receive_device(drmmode->uevent_monitor); |
| 1654 | if (!dev) |
| 1655 | return; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1656 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1657 | /* |
| 1658 | * Check to make sure this event is directed at our |
| 1659 | * device (by comparing dev_t values), then make |
| 1660 | * sure it's a hotplug event (HOTPLUG=1) |
| 1661 | */ |
| 1662 | udev_devnum = udev_device_get_devnum(dev); |
David Garbett | dbecfdd | 2013-08-28 10:45:03 +0100 | [diff] [blame] | 1663 | if (fstat(pARMSOC->drmFD, &s)) { |
| 1664 | ERROR_MSG("fstat failed: %s", strerror(errno)); |
| 1665 | udev_device_unref(dev); |
| 1666 | return; |
| 1667 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1668 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1669 | hotplug = udev_device_get_property_value(dev, "HOTPLUG"); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1670 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1671 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "hotplug=%s, match=%d\n", hotplug, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1672 | !memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t))); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1673 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1674 | if (memcmp(&s.st_rdev, &udev_devnum, sizeof(dev_t)) == 0 && |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1675 | hotplug && atoi(hotplug) == 1) { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 1676 | RRGetInfo(xf86ScrnToScreen(pScrn), TRUE); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1677 | } |
| 1678 | udev_device_unref(dev); |
| 1679 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1680 | |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1681 | static void |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1682 | drmmode_uevent_init(ScrnInfoPtr pScrn) |
| 1683 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1684 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1685 | struct udev *u; |
| 1686 | struct udev_monitor *mon; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1687 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1688 | TRACE_ENTER(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1689 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1690 | u = udev_new(); |
| 1691 | if (!u) |
| 1692 | return; |
| 1693 | mon = udev_monitor_new_from_netlink(u, "udev"); |
| 1694 | if (!mon) { |
| 1695 | udev_unref(u); |
| 1696 | return; |
| 1697 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1698 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1699 | if (udev_monitor_filter_add_match_subsystem_devtype(mon, |
| 1700 | "drm", |
| 1701 | "drm_minor") < 0 || |
| 1702 | udev_monitor_enable_receiving(mon) < 0) { |
| 1703 | udev_monitor_unref(mon); |
| 1704 | udev_unref(u); |
| 1705 | return; |
| 1706 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1707 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1708 | drmmode->uevent_handler = |
| 1709 | xf86AddGeneralHandler(udev_monitor_get_fd(mon), |
| 1710 | drmmode_handle_uevents, pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1711 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1712 | drmmode->uevent_monitor = mon; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1713 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1714 | TRACE_EXIT(); |
| 1715 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1716 | |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1717 | static void |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1718 | drmmode_uevent_fini(ScrnInfoPtr pScrn) |
| 1719 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1720 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1721 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1722 | TRACE_ENTER(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1723 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1724 | if (drmmode->uevent_handler) { |
| 1725 | struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor); |
| 1726 | xf86RemoveGeneralHandler(drmmode->uevent_handler); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1727 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1728 | udev_monitor_unref(drmmode->uevent_monitor); |
| 1729 | udev_unref(u); |
| 1730 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1731 | |
Rob Clark | 74210d5 | 2012-01-08 17:59:08 -0600 | [diff] [blame] | 1732 | TRACE_EXIT(); |
| 1733 | } |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1734 | |
| 1735 | static void |
| 1736 | drmmode_wakeup_handler(pointer data, int err, pointer p) |
| 1737 | { |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 1738 | int fd = (int)data; |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1739 | fd_set *read_mask = p; |
| 1740 | |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 1741 | if (err < 0) |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1742 | return; |
| 1743 | |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 1744 | if (FD_ISSET(fd, read_mask)) |
| 1745 | drmHandleEvent(fd, &event_context); |
| 1746 | } |
Paul Geary | 6fe52f3 | 2013-04-03 11:12:24 +0100 | [diff] [blame] | 1747 | |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 1748 | void drmmode_init_wakeup_handler(int fd) |
| 1749 | { |
| 1750 | AddGeneralSocket(fd); |
| 1751 | RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, |
| 1752 | drmmode_wakeup_handler, (pointer)fd); |
| 1753 | } |
| 1754 | |
| 1755 | void drmmode_fini_wakeup_handler(int fd) |
| 1756 | { |
| 1757 | RemoveBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, |
| 1758 | drmmode_wakeup_handler, (pointer)fd); |
| 1759 | RemoveGeneralSocket(fd); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | void |
Rob Clark | 67b875f | 2012-04-20 19:13:57 -0500 | [diff] [blame] | 1763 | drmmode_wait_for_event(ScrnInfoPtr pScrn) |
| 1764 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1765 | struct drmmode_rec *drmmode = drmmode_from_scrn(pScrn); |
Rob Clark | 67b875f | 2012-04-20 19:13:57 -0500 | [diff] [blame] | 1766 | drmHandleEvent(drmmode->fd, &event_context); |
| 1767 | } |
| 1768 | |
| 1769 | void |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1770 | drmmode_screen_init(ScrnInfoPtr pScrn) |
| 1771 | { |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1772 | drmmode_uevent_init(pScrn); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void |
| 1776 | drmmode_screen_fini(ScrnInfoPtr pScrn) |
| 1777 | { |
| 1778 | drmmode_uevent_fini(pScrn); |
| 1779 | } |