From patchwork Tue Mar 19 14:55:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2301671 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id DC60A3FC8A for ; Tue, 19 Mar 2013 15:10:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0F17E6021 for ; Tue, 19 Mar 2013 08:10:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [95.142.166.194]) by gabe.freedesktop.org (Postfix) with ESMTP id 71151E5F94 for ; Tue, 19 Mar 2013 07:55:32 -0700 (PDT) Received: from avalon.ideasonboard.com (unknown [91.178.238.129]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBAC7366F9 for ; Tue, 19 Mar 2013 15:55:12 +0100 (CET) From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 15/21] modetest: Store the crtc in the connector_arg structure Date: Tue, 19 Mar 2013 15:55:56 +0100 Message-Id: <1363704962-14077-16-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1363704962-14077-1-git-send-email-laurent.pinchart@ideasonboard.com> References: <1363704962-14077-1-git-send-email-laurent.pinchart@ideasonboard.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org This prepares the code for the split in separate functions of CRTC and planes setup. Signed-off-by: Laurent Pinchart --- tests/modetest/modetest.c | 58 ++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index ba025d6..74e82ef 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -633,11 +633,12 @@ error: */ struct connector_arg { uint32_t id; + uint32_t crtc_id; char mode_str[64]; char format_str[5]; unsigned int fourcc; drmModeModeInfo *mode; - int crtc; + struct crtc *crtc; unsigned int fb_id[2], current_fb_id; struct timeval start; @@ -688,18 +689,33 @@ static void connector_find_mode(struct device *dev, struct connector_arg *c) return; } - /* Now get the encoder */ - for (i = 0; i < dev->resources->res->count_encoders; i++) { - encoder = dev->resources->encoders[i].encoder; - if (!encoder) - continue; + /* If the CRTC ID was specified, get the corresponding CRTC. Otherwise + * locate a CRTC that can be attached to the connector. + */ + if (c->crtc_id == (uint32_t)-1) { + for (i = 0; i < dev->resources->res->count_encoders; i++) { + encoder = dev->resources->encoders[i].encoder; + if (!encoder) + continue; + + if (encoder->encoder_id == connector->encoder_id) { + c->crtc_id = encoder->crtc_id; + break; + } + } + } + + if (c->crtc_id == (uint32_t)-1) + return; - if (encoder->encoder_id == connector->encoder_id) + for (i = 0; i < dev->resources->res->count_crtcs; i++) { + struct crtc *crtc = &dev->resources->crtcs[i]; + + if (c->crtc_id == crtc->crtc->crtc_id) { + c->crtc = crtc; break; + } } - - if (c->crtc == -1) - c->crtc = encoder->crtc_id; } /* ----------------------------------------------------------------------------- @@ -794,7 +810,7 @@ page_flip_handler(int fd, unsigned int frame, else new_fb_id = c->fb_id[0]; - drmModePageFlip(fd, c->crtc, new_fb_id, + drmModePageFlip(fd, c->crtc_id, new_fb_id, DRM_MODE_PAGE_FLIP_EVENT, c); c->current_fb_id = new_fb_id; c->swap_count++; @@ -824,14 +840,14 @@ set_plane(struct device *dev, struct connector_arg *c, struct plane_arg *p) * CRTC index first, then iterate over available planes. */ for (i = 0; i < (unsigned int)dev->resources->res->count_crtcs; i++) { - if (c->crtc == (int)dev->resources->res->crtcs[i]) { + if (c->crtc_id == dev->resources->res->crtcs[i]) { pipe = i; break; } } if (pipe == (unsigned int)dev->resources->res->count_crtcs) { - fprintf(stderr, "CRTC %u not found\n", c->crtc); + fprintf(stderr, "CRTC %u not found\n", c->crtc_id); return -1; } @@ -845,7 +861,7 @@ set_plane(struct device *dev, struct connector_arg *c, struct plane_arg *p) } if (!plane_id) { - fprintf(stderr, "no unused plane available for CRTC %u\n", c->crtc); + fprintf(stderr, "no unused plane available for CRTC %u\n", c->crtc_id); return -1; } @@ -876,7 +892,7 @@ set_plane(struct device *dev, struct connector_arg *c, struct plane_arg *p) crtc_h = p->h; /* note src coords (last 4 args) are in Q16 format */ - if (drmModeSetPlane(dev->fd, plane_id, c->crtc, p->fb_id, + if (drmModeSetPlane(dev->fd, plane_id, c->crtc_id, p->fb_id, plane_flags, crtc_x, crtc_y, crtc_w, crtc_h, 0, 0, p->w << 16, p->h << 16)) { fprintf(stderr, "failed to enable plane: %s\n", @@ -884,7 +900,7 @@ set_plane(struct device *dev, struct connector_arg *c, struct plane_arg *p) return -1; } - ovr->crtc_id = c->crtc; + ovr->crtc_id = c->crtc_id; return 0; } @@ -928,9 +944,9 @@ static void set_mode(struct device *dev, struct connector_arg *c, int count, continue; printf("setting mode %s@%s on connector %d, crtc %d\n", - c[i].mode_str, c[i].format_str, c[i].id, c[i].crtc); + c[i].mode_str, c[i].format_str, c[i].id, c[i].crtc_id); - ret = drmModeSetCrtc(dev->fd, c[i].crtc, fb_id, x, 0, + ret = drmModeSetCrtc(dev->fd, c[i].crtc_id, fb_id, x, 0, &c[i].id, 1, c[i].mode); /* XXX: Actually check if this is needed */ @@ -969,7 +985,7 @@ static void set_mode(struct device *dev, struct connector_arg *c, int count, if (c[i].mode == NULL) continue; - ret = drmModePageFlip(dev->fd, c[i].crtc, other_fb_id, + ret = drmModePageFlip(dev->fd, c[i].crtc_id, other_fb_id, DRM_MODE_PAGE_FLIP_EVENT, &c[i]); if (ret) { fprintf(stderr, "failed to page flip: %s\n", strerror(errno)); @@ -1037,13 +1053,13 @@ static int parse_connector(struct connector_arg *c, const char *arg) const char *p; char *endp; - c->crtc = -1; + c->crtc_id = (uint32_t)-1; strcpy(c->format_str, "XR24"); c->id = strtoul(arg, &endp, 10); if (*endp == '@') { arg = endp + 1; - c->crtc = strtoul(arg, &endp, 10); + c->crtc_id = strtoul(arg, &endp, 10); } if (*endp != ':') return -1;