]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - include/linux/ioasid.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_IOASID_H
3 #define __LINUX_IOASID_H
5 #include <linux/types.h>
6 #include <linux/errno.h>
8 #define INVALID_IOASID ((ioasid_t)-1)
9 typedef unsigned int ioasid_t
;
10 typedef ioasid_t (*ioasid_alloc_fn_t
)(ioasid_t min
, ioasid_t max
, void *data
);
11 typedef void (*ioasid_free_fn_t
)(ioasid_t ioasid
, void *data
);
18 * struct ioasid_allocator_ops - IOASID allocator helper functions and data
20 * @alloc: helper function to allocate IOASID
21 * @free: helper function to free IOASID
22 * @list: for tracking ops that share helper functions but not data
23 * @pdata: data belong to the allocator, provided when calling alloc()
25 struct ioasid_allocator_ops
{
26 ioasid_alloc_fn_t alloc
;
27 ioasid_free_fn_t free
;
28 struct list_head list
;
32 #define DECLARE_IOASID_SET(name) struct ioasid_set name = { 0 }
34 #if IS_ENABLED(CONFIG_IOASID)
35 ioasid_t
ioasid_alloc(struct ioasid_set
*set
, ioasid_t min
, ioasid_t max
,
37 void ioasid_get(ioasid_t ioasid
);
38 bool ioasid_put(ioasid_t ioasid
);
39 void *ioasid_find(struct ioasid_set
*set
, ioasid_t ioasid
,
40 bool (*getter
)(void *));
41 int ioasid_register_allocator(struct ioasid_allocator_ops
*allocator
);
42 void ioasid_unregister_allocator(struct ioasid_allocator_ops
*allocator
);
43 int ioasid_set_data(ioasid_t ioasid
, void *data
);
45 #else /* !CONFIG_IOASID */
46 static inline ioasid_t
ioasid_alloc(struct ioasid_set
*set
, ioasid_t min
,
47 ioasid_t max
, void *private)
49 return INVALID_IOASID
;
52 static inline void ioasid_get(ioasid_t ioasid
)
56 static inline bool ioasid_put(ioasid_t ioasid
)
61 static inline void *ioasid_find(struct ioasid_set
*set
, ioasid_t ioasid
,
62 bool (*getter
)(void *))
67 static inline int ioasid_register_allocator(struct ioasid_allocator_ops
*allocator
)
72 static inline void ioasid_unregister_allocator(struct ioasid_allocator_ops
*allocator
)
76 static inline int ioasid_set_data(ioasid_t ioasid
, void *data
)
81 #endif /* CONFIG_IOASID */
82 #endif /* __LINUX_IOASID_H */