From patchwork Wed Jul 1 16:29:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nastya Vicodin X-Patchwork-Id: 1321276 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=RfN5J5i9; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yFrH46XPz9sR4 for ; Thu, 2 Jul 2020 21:15:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9E2FC82178; Thu, 2 Jul 2020 13:13:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RfN5J5i9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C6F581B47; Wed, 1 Jul 2020 18:30:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 28CBF81B48 for ; Wed, 1 Jul 2020 18:30:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vicooodin@gmail.com Received: by mail-lj1-x244.google.com with SMTP id q7so14640610ljm.1 for ; Wed, 01 Jul 2020 09:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JHiiEnTBPuqOqVOSujjK8911PQ/lX6sZGYJicOBLdPo=; b=RfN5J5i9VCdfYDtryhy1vP690jTBXej+8bKTYAG0jSxwgwGvZ1xaIqKEIP5fgdWPzQ aW1urD8LSPwZ4F0QAiJL7Pj5BqSWvXfar8m9ghNpHa2zXLlOnLdk+hsM2xXEZLNjeeR1 qv8dM8jY1yfC0zKttx5OcLclwFXFodWAQS/rQZT/BCNNouAwxCZKwMvqHixp3TqSmK1h IgTpVYEpRDIqDTz/iyI6Tij+FrJ6DePbp8yDHoj4Qqe9yDoO7G3vNnOXb7LmtM7m2jpb 1FQrdN8TSYG34jt9Wm+bC96MQux3HEVO9BrB9j1uBsaJVdhejc2a7qPozGFq3YunTkBL yhPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JHiiEnTBPuqOqVOSujjK8911PQ/lX6sZGYJicOBLdPo=; b=L2lPV6J6YiB0+w5FHtzhaD9f3IlA1gYP0YQZPTTG+leZ3ErcLQdAw5F9OEiqemHkqX YA1XPItStqGrvwCNiBR5tAnYz8h/49a0kr9CkPCTvi6DBm7bSXM/20w2XrgRgzyE5XpU oeeTtH4rFEHoOV5GOYjg2tj8QdrDSv+rnW7KHI5DXja5hufTuw/jeCVI4JtJLrUKw9Vk K1OO1kIGMSU2I5VP3MDNEYD/tjENTLml/QI3OmN9IW7d4sXZ1aiQtQRbuMZm+fLCZrII 1e6C+PaBf2URXobSMnX11zRt2dj/EmT81zUsLX281LpXh85Lxn3XiDnf8bU35so2pUf5 a/XQ== X-Gm-Message-State: AOAM530kMfpVS3PYZAXopu8NmZBcyOLC6O0r+lUWr3LeIpPDVKXGr2Lz 0HuKWXp68WpjXvwqwHU1PQisnyrhvBEIXQ== X-Google-Smtp-Source: ABdhPJza+aO2nPt06dAge0JzZDKTBmYTXPb6upcpq8EBRk60/TdJoDUMJ7KHDf8Tgdre/usK5Fju1w== X-Received: by 2002:a2e:9a82:: with SMTP id p2mr14217735lji.129.1593621021236; Wed, 01 Jul 2020 09:30:21 -0700 (PDT) Received: from localhost.localdomain (host-176-36-213-80.la.net.ua. [176.36.213.80]) by smtp.gmail.com with ESMTPSA id v20sm1943322lfr.74.2020.07.01.09.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 09:30:20 -0700 (PDT) From: Anastasiia Lukianenko To: u-boot@lists.denx.de, sjg@chromium.org, ye.li@nxp.com, bmeng.cn@gmail.com, xypron.glpk@gmx.de Cc: julien@xen.org, sstabellini@kernel.org, peng.fan@nxp.com, roman@zededa.com, volodymyr_babchuk@epam.com, Oleksandr Andrushchenko , Anastasiia Lukianenko Subject: [PATCH 08/17] linux/compat.h: Add wait_event_timeout macro Date: Wed, 1 Jul 2020 19:29:50 +0300 Message-Id: <20200701162959.9814-9-vicooodin@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200701162959.9814-1-vicooodin@gmail.com> References: <20200701162959.9814-1-vicooodin@gmail.com> X-Mailman-Approved-At: Thu, 02 Jul 2020 13:12:53 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Oleksandr Andrushchenko Add wait_event_timeout - sleep until a condition gets true or a timeout elapses. This is a stripped version of the same from Linux kernel with the following u-boot specific modifications: - no wait queues supported - use u-boot timer to detect timeouts - check for Ctrl-C pressed during wait Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Anastasiia Lukianenko --- include/linux/compat.h | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/linux/compat.h b/include/linux/compat.h index 712eeaef4e..5375b7d3b8 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -1,12 +1,20 @@ #ifndef _LINUX_COMPAT_H_ #define _LINUX_COMPAT_H_ +#include #include #include + +#include + #include #include #include +#ifdef CONFIG_XEN +#include +#endif + struct unused {}; typedef struct unused unused_t; @@ -122,6 +130,43 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep) #define add_wait_queue(...) do { } while (0) #define remove_wait_queue(...) do { } while (0) +#ifndef CONFIG_XEN +#define eventchn_poll() +#endif + +#define __wait_event_timeout(condition, timeout, ret) \ +({ \ + ulong __ret = ret; /* explicit shadow */ \ + ulong start = get_timer(0); \ + for (;;) { \ + eventchn_poll(); \ + if (condition) { \ + __ret = 1; \ + break; \ + } \ + if ((get_timer(start) > timeout) || ctrlc()) { \ + __ret = 0; \ + break; \ + } \ + cpu_relax(); \ + } \ + __ret; \ +}) + +/* + * 0 if the @condition evaluated to %false after the @timeout elapsed, + * 1 if the @condition evaluated to %true + */ +#define wait_event_timeout(wq_head, condition, timeout) \ +({ \ + ulong __ret; \ + if (condition) \ + __ret = 1; \ + else \ + __ret = __wait_event_timeout(condition, timeout, __ret);\ + __ret; \ +}) + #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) /* This is also defined in ARMv8's mmu.h */