From patchwork Fri Nov 25 14:41:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9447671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5D58B6071C for ; Fri, 25 Nov 2016 14:41:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FC9027D45 for ; Fri, 25 Nov 2016 14:41:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 447C927E3E; Fri, 25 Nov 2016 14:41:20 +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=-4.2 required=2.0 tests=BAYES_00, 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 3434927D45 for ; Fri, 25 Nov 2016 14:41:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3ADA06E176; Fri, 25 Nov 2016 14:41:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id A499A6E15F for ; Fri, 25 Nov 2016 14:41:14 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP; 25 Nov 2016 06:41:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,547,1473145200"; d="scan'208"; a="1064098152" Received: from skylake-nuc.fi.intel.com ([10.237.68.38]) by orsmga001.jf.intel.com with ESMTP; 25 Nov 2016 06:41:12 -0800 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Fri, 25 Nov 2016 16:41:13 +0200 Message-Id: <1480084874-12943-1-git-send-email-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20161125115456.GL26057@nuc-i3427.alporthouse.com> References: <20161125115456.GL26057@nuc-i3427.alporthouse.com> Cc: Lyude Subject: [Intel-gfx] [i-g-t PATCH 2/6] igt_aux: Add some list helpers from wayland X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Lyude Since we're going to be using lists for keeping track of EDIDs we've allocated on the chamelium, add some generic list helpers from the wayland project. Signed-off-by: Lyude Changes since v1: - Rename list helpers to be more like those from the Linux kernel --- lib/igt_aux.c | 27 +++++++++++++++++++++++++++ lib/igt_aux.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index b5ae854..56bddd6 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1265,3 +1265,30 @@ double igt_stop_siglatency(struct igt_mean *result) return mean; } + +void igt_list_init(struct igt_list *igt_list) +{ + igt_list->prev = igt_list; + igt_list->next = igt_list; +} + +void igt_list_add(struct igt_list *igt_list, struct igt_list *elm) +{ + elm->prev = igt_list; + elm->next = igt_list->next; + igt_list->next = elm; + elm->next->prev = elm; +} + +void igt_list_del(struct igt_list *elm) +{ + elm->prev->next = elm->next; + elm->next->prev = elm->prev; + elm->next = NULL; + elm->prev = NULL; +} + +bool igt_list_empty(const struct igt_list *igt_list) +{ + return igt_list->next == igt_list; +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index d4da499..9d1c44a 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -274,4 +274,42 @@ double igt_stop_siglatency(struct igt_mean *result); void igt_set_module_param(const char *name, const char *val); void igt_set_module_param_int(const char *name, int val); +/* + * This list data structure is a verbatim copy from wayland-util.h from the + * Wayland project; except that wl_ prefix has been removed. + */ + +struct igt_list { + struct igt_list *prev; + struct igt_list *next; +}; + +void igt_list_init(struct igt_list *list); +void igt_list_add(struct igt_list *list, struct igt_list *elm); +void igt_list_del(struct igt_list *elm); +bool igt_list_empty(const struct igt_list *list); + +#ifdef __GNUC__ +#define container_of(ptr, sample, member) \ + (__typeof__(sample))((char *)(ptr) - \ + ((char *)&(sample)->member - (char *)(sample))) +#else +#define container_of(ptr, sample, member) \ + (void *)((char *)(ptr) - \ + ((char *)&(sample)->member - (char *)(sample))) +#endif + +#define igt_list_for_each(pos, head, member) \ + for (pos = 0, pos = container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) + +#define igt_list_for_each_safe(pos, tmp, head, member) \ + for (pos = 0, tmp = 0, \ + pos = container_of((head)->next, pos, member), \ + tmp = container_of((pos)->member.next, tmp, member); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = container_of(pos->member.next, tmp, member)) + #endif /* IGT_AUX_H */