From patchwork Sat Jul 20 08:45:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sam Ravnborg X-Patchwork-Id: 11050815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3A9A13AC for ; Sat, 20 Jul 2019 08:46:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF1382898C for ; Sat, 20 Jul 2019 08:46:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2A3E2898E; Sat, 20 Jul 2019 08:46:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EF5F82898C for ; Sat, 20 Jul 2019 08:46:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 106D06E893; Sat, 20 Jul 2019 08:46:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F4476E88A; Sat, 20 Jul 2019 08:45:55 +0000 (UTC) Received: by mail-lf1-x141.google.com with SMTP id c9so23282276lfh.4; Sat, 20 Jul 2019 01:45:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DLIxb5xG1R1/AMn7Cxx7Gmv1fB7QRIbhWjnyMccdsgs=; b=mdUKUu3T05EuAYPEJ+7t8iU8F0qbw4OywDUQIHTQ6LOD/qWUBmByehQojOfWT4YqIz 9K22d9rCkzh6ApJ0S32/76X9yZVI8LXpNZHtmwftdaDMiaH6hmwqhISa/6ZO0YqtZIAS owazu+fJFJliOw2DhtPGZrKBUCS21j1hCUaFtJ/R5ccnV6XFhDgK/A78oTyH3JYxCDwA hamuK2A1eLxdWhnZPmZL6WVuD7NsdER1zqckh6svV5s3F81fD54i8AqqW2dbZlzOtuf5 Jl7SVc6A1HyO8XnBer5OxVMSDcekGQK1nSbzFi5GlM+6rGbLIGfAbnkIMu8yzz47vnD4 RgfA== X-Gm-Message-State: APjAAAUSjhmMUBWykSUzzIU/Dm0S6y9Tt+MjtB+33FEUbg6pboqUvtHk y7xN+vIOGeWl3Mj1Z7+4WaZ0wyrzYuU= X-Google-Smtp-Source: APXvYqwNuyA0w/+CrxrmuWb8MbtKhoIw9BqxmpQl8svk9III6lWiHYVVNHxjUkd+TR3+0/0Qai58FQ== X-Received: by 2002:ac2:5382:: with SMTP id g2mr25289409lfh.92.1563612353319; Sat, 20 Jul 2019 01:45:53 -0700 (PDT) Received: from saturn.lan (18.158-248-194.customer.lyse.net. [158.248.194.18]) by smtp.gmail.com with ESMTPSA id o3sm5047022lfb.40.2019.07.20.01.45.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 01:45:52 -0700 (PDT) From: Sam Ravnborg To: dri-devel@lists.freedesktop.org, openchrome-devel@lists.freedesktop.org Subject: [PATCH v2 2/4] drm/via: add VIA_WAIT_ON() Date: Sat, 20 Jul 2019 10:45:25 +0200 Message-Id: <20190720084527.12593-3-sam@ravnborg.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190720084527.12593-1-sam@ravnborg.org> References: <20190720084527.12593-1-sam@ravnborg.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DLIxb5xG1R1/AMn7Cxx7Gmv1fB7QRIbhWjnyMccdsgs=; b=M6YQwOtHxwTR0QGMSC1PCZvEqoZ6F40bLYP47IPQKadPckjY9/XTd0SlaU/+dV32Cl UQm2RecdFhp4jPTSbLhbTBd9MPiL++xEk/CkZ+XE8DPUH4Kc5Ggz9BHPgqxN8XPTYTGZ C6wJmS+fYaPdqXG9vMKqrRunJcdw8ewxKsrxX1xR3GK452zcug3Ty3AAJ75e6c0J0nZ/ v4F4j3sLDbJk3Vgd2NYdc6HSN9rKmWTXYTuJQOjwGa6KI7Eyk/gqh2KmB9/ewFyJhQcB CHKaSKxdE1vR97gCafnpQYJiV94ecw0C5jv+yrN6SEzPTutaCwL/Ds2uyhPI84+sa+l+ J+Ag== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , Sam Ravnborg , "Gustavo A. R. Silva" , David Airlie , Daniel Vetter , =?utf-8?q?Michel_D=C3=A4nzer?= , Kevin Brace , Mike Marshall , Ira Weiny , Emil Velikov Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP VIA_WAIT_ON() is a direct copy of DRM_WAIT_ON() from drm_os_linux.h. The copy is made so we can avoid the dependency on the legacy header. A more involved approach had been to introduce wait_event_* but for this legacy driver the simpler and more safe approach with a copy of the macro was selected. Added the relevant header files for the functions used in VIA_WAIT_ON. Users of the macro will come in a follow-up patch. Signed-off-by: Sam Ravnborg Cc: Kevin Brace Cc: Thomas Hellstrom Cc: "Gustavo A. R. Silva" Cc: Mike Marshall Cc: Ira Weiny Cc: Daniel Vetter Cc: Emil Velikov Cc: Michel Dänzer --- drivers/gpu/drm/via/via_drv.h | 42 ++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h index d5a2b1ffd8c1..664b7f8a20c4 100644 --- a/drivers/gpu/drm/via/via_drv.h +++ b/drivers/gpu/drm/via/via_drv.h @@ -24,8 +24,13 @@ #ifndef _VIA_DRV_H_ #define _VIA_DRV_H_ -#include +#include +#include +#include +#include + #include +#include #define DRIVER_AUTHOR "Various" @@ -127,6 +132,41 @@ enum via_family { #define VIA_WRITE8(reg, val) \ writeb(val, ((void __iomem *)VIA_BASE->handle) + (reg)) +/* + * Poll in a loop waiting for 'contidition' to be true. + * Note: A direct replacement with wait_event_interruptible_timeout() + * will not work unless driver is updated to emit wake_up() + * in relevant places that can impact the 'condition' + * + * Returns: + * ret keeps current value if 'condition' becomes true + * ret = -BUSY if timeout happens + * ret = -EINTR if a signal interrupted the waiting period + */ +#define VIA_WAIT_ON( ret, queue, timeout, condition ) \ +do { \ + DECLARE_WAITQUEUE(entry, current); \ + unsigned long end = jiffies + (timeout); \ + add_wait_queue(&(queue), &entry); \ + \ + for (;;) { \ + __set_current_state(TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + if (time_after_eq(jiffies, end)) { \ + ret = -EBUSY; \ + break; \ + } \ + schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ + if (signal_pending(current)) { \ + ret = -EINTR; \ + break; \ + } \ + } \ + __set_current_state(TASK_RUNNING); \ + remove_wait_queue(&(queue), &entry); \ +} while (0) + extern const struct drm_ioctl_desc via_ioctls[]; extern int via_max_ioctl;