1
2#ifndef __LINUX_IOASID_H
3#define __LINUX_IOASID_H
4
5#include <linux/types.h>
6#include <linux/errno.h>
7
8#define INVALID_IOASID ((ioasid_t)-1)
9typedef unsigned int ioasid_t;
10typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
11typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
12
13struct ioasid_set {
14 int dummy;
15};
16
17
18
19
20
21
22
23
24
25struct ioasid_allocator_ops {
26 ioasid_alloc_fn_t alloc;
27 ioasid_free_fn_t free;
28 struct list_head list;
29 void *pdata;
30};
31
32#define DECLARE_IOASID_SET(name) struct ioasid_set name = { 0 }
33
34#if IS_ENABLED(CONFIG_IOASID)
35ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max,
36 void *private);
37void ioasid_get(ioasid_t ioasid);
38bool ioasid_put(ioasid_t ioasid);
39void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
40 bool (*getter)(void *));
41int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
42void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
43int ioasid_set_data(ioasid_t ioasid, void *data);
44
45#else
46static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
47 ioasid_t max, void *private)
48{
49 return INVALID_IOASID;
50}
51
52static inline void ioasid_get(ioasid_t ioasid)
53{
54}
55
56static inline bool ioasid_put(ioasid_t ioasid)
57{
58 return false;
59}
60
61static inline void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
62 bool (*getter)(void *))
63{
64 return NULL;
65}
66
67static inline int ioasid_register_allocator(struct ioasid_allocator_ops *allocator)
68{
69 return -ENOTSUPP;
70}
71
72static inline void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator)
73{
74}
75
76static inline int ioasid_set_data(ioasid_t ioasid, void *data)
77{
78 return -ENOTSUPP;
79}
80
81#endif
82#endif
83