From c8c1d02261521b5361a9a0daf28238740edc316d Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Fri, 10 Feb 2017 17:30:41 +0530 Subject: gpu: nvgpu: implement own list APIs Add nvgpu's own implementation of List APIs This implementation is needed to remove nvgpu's dependency on Linux specific list implementation Define a list node as struct nvgpu_list_node *node; Define below common APIs: nvgpu_init_list_node() - initialize list node nvgpu_list_add() - add new node to list nvgpu_list_add_tail() - add new node to end of list nvgpu_list_del() - delete node from list nvgpu_list_empty() - check if list is empty Define below macros to simplify access to list: nvgpu_list_entry() - convert list node to parent nvgpu_list_next_entry() - find next entry in list nvgpu_list_first_entry() - first entry in list nvgpu_list_for_each_entry() - iterator for list nvgpu_list_for_each_entry_safe() - deletion safe iterator Jira NVGPU-13 Change-Id: Icb1d27857148e96b2c6dfa3c2bd50fcff9f896cf Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/1303024 Reviewed-by: svccoveritychecker Reviewed-by: Konsta Holtta Reviewed-by: Sami Kiminki GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/include/nvgpu/list.h | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/list.h (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/include/nvgpu/list.h b/drivers/gpu/nvgpu/include/nvgpu/list.h new file mode 100644 index 00000000..c8d2b37a --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/list.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NVGPU_LIST_H +#define NVGPU_LIST_H + +struct nvgpu_list_node { + struct nvgpu_list_node *prev; + struct nvgpu_list_node *next; +}; + +static inline void nvgpu_init_list_node(struct nvgpu_list_node *node) +{ + node->prev = node; + node->next = node; +} + +static inline void nvgpu_list_add(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head) +{ + new_node->next = head->next; + new_node->next->prev = new_node; + new_node->prev = head; + head->next = new_node; +} + +static inline void nvgpu_list_add_tail(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head) +{ + new_node->prev = head->prev; + new_node->prev->next = new_node; + new_node->next = head; + head->prev = new_node; +} + +static inline void nvgpu_list_del(struct nvgpu_list_node *node) +{ + node->prev->next = node->next; + node->next->prev = node->prev; + nvgpu_init_list_node(node); +} + +static inline int nvgpu_list_empty(struct nvgpu_list_node *head) +{ + return head->next == head; +} + +#define nvgpu_list_entry(ptr, type, member) \ + type ## _from_ ## member(ptr) + +#define nvgpu_list_next_entry(pos, type, member) \ + nvgpu_list_entry((pos)->member.next, type, member) + +#define nvgpu_list_first_entry(ptr, type, member) \ + nvgpu_list_entry((ptr)->next, type, member) + +#define nvgpu_list_for_each_entry(pos, head, type, member) \ + for (pos = nvgpu_list_first_entry(head, type, member); \ + &pos->member != (head); \ + pos = nvgpu_list_next_entry(pos, type, member)) + +#define nvgpu_list_for_each_entry_safe(pos, n, head, type, member) \ + for (pos = nvgpu_list_first_entry(head, type, member), \ + n = nvgpu_list_next_entry(pos, type, member); \ + &pos->member != (head); \ + pos = n, n = nvgpu_list_next_entry(n, type, member)) + +#endif /* NVGPU_LIST_H */ -- cgit v1.2.2