1 /*
2  * Copyright (C) 2015, Intel Corporation
3  * Author: Jiang Liu <jiang.liu@linux.intel.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14 #ifndef _LINUX_RESOURCE_EXT_H
15 #define _LINUX_RESOURCE_EXT_H
16 #include <linux/types.h>
17 #include <linux/list.h>
18 #include <linux/ioport.h>
19 #include <linux/slab.h>
20 
21 /* Represent resource window for bridge devices */
22 struct resource_win {
23 	struct resource res;		/* In master (CPU) address space */
24 	resource_size_t offset;		/* Translation offset for bridge */
25 };
26 
27 /*
28  * Common resource list management data structure and interfaces to support
29  * ACPI, PNP and PCI host bridge etc.
30  */
31 struct resource_entry {
32 	struct list_head	node;
33 	struct resource		*res;	/* In master (CPU) address space */
34 	resource_size_t		offset;	/* Translation offset for bridge */
35 	struct resource		__res;	/* Default storage for res */
36 };
37 
38 extern struct resource_entry *
39 resource_list_create_entry(struct resource *res, size_t extra_size);
40 extern void resource_list_free(struct list_head *head);
41 
resource_list_add(struct resource_entry * entry,struct list_head * head)42 static inline void resource_list_add(struct resource_entry *entry,
43 				     struct list_head *head)
44 {
45 	list_add(&entry->node, head);
46 }
47 
resource_list_add_tail(struct resource_entry * entry,struct list_head * head)48 static inline void resource_list_add_tail(struct resource_entry *entry,
49 					  struct list_head *head)
50 {
51 	list_add_tail(&entry->node, head);
52 }
53 
resource_list_del(struct resource_entry * entry)54 static inline void resource_list_del(struct resource_entry *entry)
55 {
56 	list_del(&entry->node);
57 }
58 
resource_list_free_entry(struct resource_entry * entry)59 static inline void resource_list_free_entry(struct resource_entry *entry)
60 {
61 	kfree(entry);
62 }
63 
64 static inline void
resource_list_destroy_entry(struct resource_entry * entry)65 resource_list_destroy_entry(struct resource_entry *entry)
66 {
67 	resource_list_del(entry);
68 	resource_list_free_entry(entry);
69 }
70 
71 #define resource_list_for_each_entry(entry, list)	\
72 	list_for_each_entry((entry), (list), node)
73 
74 #define resource_list_for_each_entry_safe(entry, tmp, list)	\
75 	list_for_each_entry_safe((entry), (tmp), (list), node)
76 
77 #endif /* _LINUX_RESOURCE_EXT_H */
78