xref: /linux-6.15/include/linux/resource_ext.h (revision 494f8b10)
12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
290e97820SJiang Liu /*
390e97820SJiang Liu  * Copyright (C) 2015, Intel Corporation
490e97820SJiang Liu  * Author: Jiang Liu <[email protected]>
590e97820SJiang Liu  */
690e97820SJiang Liu #ifndef _LINUX_RESOURCE_EXT_H
790e97820SJiang Liu #define _LINUX_RESOURCE_EXT_H
890e97820SJiang Liu #include <linux/types.h>
990e97820SJiang Liu #include <linux/list.h>
1090e97820SJiang Liu #include <linux/ioport.h>
1190e97820SJiang Liu #include <linux/slab.h>
1290e97820SJiang Liu 
1390e97820SJiang Liu /* Represent resource window for bridge devices */
1490e97820SJiang Liu struct resource_win {
1590e97820SJiang Liu 	struct resource res;		/* In master (CPU) address space */
1690e97820SJiang Liu 	resource_size_t offset;		/* Translation offset for bridge */
1790e97820SJiang Liu };
1890e97820SJiang Liu 
1990e97820SJiang Liu /*
2090e97820SJiang Liu  * Common resource list management data structure and interfaces to support
2190e97820SJiang Liu  * ACPI, PNP and PCI host bridge etc.
2290e97820SJiang Liu  */
2390e97820SJiang Liu struct resource_entry {
2490e97820SJiang Liu 	struct list_head	node;
2590e97820SJiang Liu 	struct resource		*res;	/* In master (CPU) address space */
2690e97820SJiang Liu 	resource_size_t		offset;	/* Translation offset for bridge */
2790e97820SJiang Liu 	struct resource		__res;	/* Default storage for res */
2890e97820SJiang Liu };
2990e97820SJiang Liu 
3090e97820SJiang Liu extern struct resource_entry *
3190e97820SJiang Liu resource_list_create_entry(struct resource *res, size_t extra_size);
3290e97820SJiang Liu extern void resource_list_free(struct list_head *head);
3390e97820SJiang Liu 
resource_list_add(struct resource_entry * entry,struct list_head * head)3490e97820SJiang Liu static inline void resource_list_add(struct resource_entry *entry,
3590e97820SJiang Liu 				     struct list_head *head)
3690e97820SJiang Liu {
3790e97820SJiang Liu 	list_add(&entry->node, head);
3890e97820SJiang Liu }
3990e97820SJiang Liu 
resource_list_add_tail(struct resource_entry * entry,struct list_head * head)4090e97820SJiang Liu static inline void resource_list_add_tail(struct resource_entry *entry,
4190e97820SJiang Liu 					  struct list_head *head)
4290e97820SJiang Liu {
4390e97820SJiang Liu 	list_add_tail(&entry->node, head);
4490e97820SJiang Liu }
4590e97820SJiang Liu 
resource_list_del(struct resource_entry * entry)4690e97820SJiang Liu static inline void resource_list_del(struct resource_entry *entry)
4790e97820SJiang Liu {
4890e97820SJiang Liu 	list_del(&entry->node);
4990e97820SJiang Liu }
5090e97820SJiang Liu 
resource_list_free_entry(struct resource_entry * entry)5190e97820SJiang Liu static inline void resource_list_free_entry(struct resource_entry *entry)
5290e97820SJiang Liu {
5390e97820SJiang Liu 	kfree(entry);
5490e97820SJiang Liu }
5590e97820SJiang Liu 
5690e97820SJiang Liu static inline void
resource_list_destroy_entry(struct resource_entry * entry)5790e97820SJiang Liu resource_list_destroy_entry(struct resource_entry *entry)
5890e97820SJiang Liu {
5990e97820SJiang Liu 	resource_list_del(entry);
6090e97820SJiang Liu 	resource_list_free_entry(entry);
6190e97820SJiang Liu }
6290e97820SJiang Liu 
6390e97820SJiang Liu #define resource_list_for_each_entry(entry, list)	\
6490e97820SJiang Liu 	list_for_each_entry((entry), (list), node)
6590e97820SJiang Liu 
6690e97820SJiang Liu #define resource_list_for_each_entry_safe(entry, tmp, list)	\
6790e97820SJiang Liu 	list_for_each_entry_safe((entry), (tmp), (list), node)
6890e97820SJiang Liu 
69*494f8b10SRob Herring static inline struct resource_entry *
resource_list_first_type(struct list_head * list,unsigned long type)70*494f8b10SRob Herring resource_list_first_type(struct list_head *list, unsigned long type)
71*494f8b10SRob Herring {
72*494f8b10SRob Herring 	struct resource_entry *entry;
73*494f8b10SRob Herring 
74*494f8b10SRob Herring 	resource_list_for_each_entry(entry, list) {
75*494f8b10SRob Herring 		if (resource_type(entry->res) == type)
76*494f8b10SRob Herring 			return entry;
77*494f8b10SRob Herring 	}
78*494f8b10SRob Herring 	return NULL;
79*494f8b10SRob Herring }
80*494f8b10SRob Herring 
8190e97820SJiang Liu #endif /* _LINUX_RESOURCE_EXT_H */
82