From patchwork Fri Nov 25 11:40:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9447389 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 2B70760778 for ; Fri, 25 Nov 2016 11:40:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E1C327F88 for ; Fri, 25 Nov 2016 11:40:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0151D28068; Fri, 25 Nov 2016 11:40:42 +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 758A727F88 for ; Fri, 25 Nov 2016 11:40:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E5BE66E089; Fri, 25 Nov 2016 11:40:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id D8BE86E089 for ; Fri, 25 Nov 2016 11:40:33 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 25 Nov 2016 03:40:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,547,1473145200"; d="scan'208";a="905367262" Received: from skylake-nuc.fi.intel.com ([10.237.68.38]) by orsmga003.jf.intel.com with ESMTP; 25 Nov 2016 03:40:28 -0800 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Fri, 25 Nov 2016 13:40:31 +0200 Message-Id: <1480074032-26818-1-git-send-email-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20161125091750.GB26057@nuc-i3427.alporthouse.com> References: <20161125091750.GB26057@nuc-i3427.alporthouse.com> Subject: [Intel-gfx] [i-g-t PATCH 2/6] igt_aux: Add some list helpers from the kernel 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 Since we're going to be using lists for keeping track of spinners add some generic list helpers from the kernel. Signed-off-by: Abdiel Janulgue --- lib/igt_aux.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index b5ae854..28af1d4 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1265,3 +1265,42 @@ double igt_stop_siglatency(struct igt_mean *result) return mean; } + +static void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +static void __list_del(struct list_head * prev, struct list_head * next) +{ + next->prev = prev; + prev->next = next; +} + +void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +} + +void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + +void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + entry->next = NULL; + entry->prev = NULL; +} + +bool list_empty(const struct list_head *head) +{ + return head->next == head; +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index d4da499..73836d0 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -274,4 +274,50 @@ 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 derived from the Linux kerne's list.h + */ + +struct list_head { + struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) + +void INIT_LIST_HEAD(struct list_head *list); + +void list_add(struct list_head *new, struct list_head *head); + +void list_del(struct list_head *entry); + +bool list_empty(const struct list_head *head); + +#undef offsetof +#ifdef __compiler_offsetof +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) +#else +#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) +#endif + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + #endif /* IGT_AUX_H */