Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_IOASID_H
0003 #define __LINUX_IOASID_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/errno.h>
0007 
0008 #define INVALID_IOASID ((ioasid_t)-1)
0009 typedef unsigned int ioasid_t;
0010 typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
0011 typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
0012 
0013 struct ioasid_set {
0014     int dummy;
0015 };
0016 
0017 /**
0018  * struct ioasid_allocator_ops - IOASID allocator helper functions and data
0019  *
0020  * @alloc:  helper function to allocate IOASID
0021  * @free:   helper function to free IOASID
0022  * @list:   for tracking ops that share helper functions but not data
0023  * @pdata:  data belong to the allocator, provided when calling alloc()
0024  */
0025 struct ioasid_allocator_ops {
0026     ioasid_alloc_fn_t alloc;
0027     ioasid_free_fn_t free;
0028     struct list_head list;
0029     void *pdata;
0030 };
0031 
0032 #define DECLARE_IOASID_SET(name) struct ioasid_set name = { 0 }
0033 
0034 #if IS_ENABLED(CONFIG_IOASID)
0035 ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max,
0036               void *private);
0037 void ioasid_free(ioasid_t ioasid);
0038 void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
0039           bool (*getter)(void *));
0040 int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
0041 void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
0042 int ioasid_set_data(ioasid_t ioasid, void *data);
0043 static inline bool pasid_valid(ioasid_t ioasid)
0044 {
0045     return ioasid != INVALID_IOASID;
0046 }
0047 
0048 #else /* !CONFIG_IOASID */
0049 static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
0050                     ioasid_t max, void *private)
0051 {
0052     return INVALID_IOASID;
0053 }
0054 
0055 static inline void ioasid_free(ioasid_t ioasid) { }
0056 
0057 static inline void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
0058                 bool (*getter)(void *))
0059 {
0060     return NULL;
0061 }
0062 
0063 static inline int ioasid_register_allocator(struct ioasid_allocator_ops *allocator)
0064 {
0065     return -ENOTSUPP;
0066 }
0067 
0068 static inline void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator)
0069 {
0070 }
0071 
0072 static inline int ioasid_set_data(ioasid_t ioasid, void *data)
0073 {
0074     return -ENOTSUPP;
0075 }
0076 
0077 static inline bool pasid_valid(ioasid_t ioasid)
0078 {
0079     return false;
0080 }
0081 
0082 #endif /* CONFIG_IOASID */
0083 #endif /* __LINUX_IOASID_H */