From patchwork Sat Feb 26 18:30:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 592731 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1QIeDh7011692 for ; Sat, 26 Feb 2011 18:40:34 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69F509F307 for ; Sat, 26 Feb 2011 10:40:13 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-iw0-f177.google.com (mail-iw0-f177.google.com [209.85.214.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 694C79E949 for ; Sat, 26 Feb 2011 10:30:41 -0800 (PST) Received: by mail-iw0-f177.google.com with SMTP id 36so2094154iwn.36 for ; Sat, 26 Feb 2011 10:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=mYZaVyI+pcwlCo4QKlowuSHWF8rkNFaRbLBygw/XS9o=; b=w44179cZ52e+hI3wPXAiaZWPpg7ACRmhPw3bZE/iJuFJDxHW0178/IIunGU1/hWBVk f/S8z0t+ZYpFyT84k0CVAjdO9x2u8rI1w78BqFdBMVFO1EweVlUBnf7THx8Ezr1Wa+V9 HZ2orGJIp2mP5CrIfSeufaWODnpWhlWg614zI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=guqRtzbbjaNKiLvtVntcQ62Vk/EpXa/PycHxnv+gKTU9a0KbBqbW1hU6hCk4B8+u9q a6lSsIuO55iHIH4m18rwo8LVarMqLTWOamCmrLUSgdevOD/bM0YuuFVNh4Teh1RvTbsC 25Lb+J8qWp+7evmoeNrh55UVt+JmHbf2Bnvdk= Received: by 10.43.61.197 with SMTP id wx5mr1439474icb.354.1298745041270; Sat, 26 Feb 2011 10:30:41 -0800 (PST) Received: from localhost.localdomain ([67.208.96.87]) by mx.google.com with ESMTPS id wd12sm1519339icb.17.2011.02.26.10.30.39 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 Feb 2011 10:30:40 -0800 (PST) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Sat, 26 Feb 2011 10:30:16 -0800 Message-Id: <1298745018-5937-7-git-send-email-bwidawsk@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1298745018-5937-1-git-send-email-bwidawsk@gmail.com> References: <1298745018-5937-1-git-send-email-bwidawsk@gmail.com> Subject: [Intel-gfx] [RFC] [PATCH 6/8] drm/i915/context: context init implementation X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 26 Feb 2011 18:40:34 +0000 (UTC) diff --git a/drivers/gpu/drm/i915/i915_context.c b/drivers/gpu/drm/i915/i915_context.c index 45b5181..2e38fa8 100644 --- a/drivers/gpu/drm/i915/i915_context.c +++ b/drivers/gpu/drm/i915/i915_context.c @@ -99,13 +99,70 @@ static int context_init(struct drm_i915_gem_context *ctx, bool wait_for_switch) { struct drm_i915_private *dev_priv = ctx->dev->dev_private; - struct drm_i915_gem_context *last; + struct drm_i915_gem_context *last = NULL; int ret; if (ring->context_switch == NULL) return 0; - return -ENOMEM; + drm_gem_object_reference(&ctx->obj->base); + ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false); + if (ret) { + drm_gem_object_unreference(&ctx->obj->base); + return ret; + } + + if (ctx->is_default) { + /* + * XXX default context is always first. The first context needs + * to do an extra save because the first save (according to the + * spec) doesn't actually do anything. So the outcome is + * 1. Save without restore (no context saved) + * 2. Save without restore (context is saved) + * 3. Save with restore (loads the ctx from step 2) + */ + last = ring->context_switch(ring, ctx, 0, + I915_CONTEXT_SAVE_ONLY); + if (!last) { + ret = EIO; + goto err_out; + } + last = ring->context_switch(ring, ctx, 0, + I915_CONTEXT_SAVE_ONLY | + I915_CONTEXT_FORCED_SWITCH); + if (!last) { + ret = EIO; + goto err_out; + } + last = ring->context_switch(ring, ctx, 0, + I915_CONTEXT_NORMAL_SWITCH | + I915_CONTEXT_FORCED_SWITCH); + } else { + last = ring->context_switch(ring, ctx, 0, + I915_CONTEXT_SAVE_ONLY); + } + + if (!last) { + ret = EIO; + goto err_out; + } + + if (!last->is_default) + i915_release_context(last); + + if (wait_for_switch) { + ret = wait_for_context_switch(ring); + if (ret) + goto err_out; + } + + return 0; + +err_out: + WARN_ON(ctx->is_default); + i915_gem_object_unpin(ctx->obj); + drm_gem_object_unreference(&ctx->obj->base); + return ret; } /* @@ -316,3 +373,9 @@ struct drm_i915_gem_context *i915_get_context(struct drm_file *file, { return NULL; } + +void i915_release_context(struct drm_i915_gem_context *ctx) +{ + i915_gem_object_unpin(ctx->obj); + drm_gem_object_unreference(&ctx->obj->base); +} diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 15f86fb..98ccbd9 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -914,6 +914,10 @@ struct drm_i915_gem_context { int slot_count; }; +#define I915_CONTEXT_NORMAL_SWITCH (1 << 0) +#define I915_CONTEXT_SAVE_ONLY (1 << 1) +#define I915_CONTEXT_FORCED_SWITCH (1 << 2) + enum intel_chip_family { CHIP_I8XX = 0x01, CHIP_I9XX = 0x02, @@ -1157,6 +1161,7 @@ extern void i915_context_open(struct drm_device *dev, struct drm_file *file); extern void i915_context_close(struct drm_device *dev, struct drm_file *file); extern struct drm_i915_gem_context *i915_get_context(struct drm_file *file, uint32_t id); +extern void i915_release_context(struct drm_i915_gem_context *ctx); /** * Returns true if seq1 is later than seq2.