2019-10-03 03:42:41 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef __LINUX_IOASID_H
|
|
|
|
#define __LINUX_IOASID_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
|
|
|
#define INVALID_IOASID ((ioasid_t)-1)
|
|
|
|
typedef unsigned int ioasid_t;
|
2019-10-03 03:42:42 +08:00
|
|
|
typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
|
|
|
|
typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
|
2019-10-03 03:42:41 +08:00
|
|
|
|
|
|
|
struct ioasid_set {
|
|
|
|
int dummy;
|
|
|
|
};
|
|
|
|
|
2019-10-03 03:42:42 +08:00
|
|
|
/**
|
|
|
|
* struct ioasid_allocator_ops - IOASID allocator helper functions and data
|
|
|
|
*
|
|
|
|
* @alloc: helper function to allocate IOASID
|
|
|
|
* @free: helper function to free IOASID
|
|
|
|
* @list: for tracking ops that share helper functions but not data
|
|
|
|
* @pdata: data belong to the allocator, provided when calling alloc()
|
|
|
|
*/
|
|
|
|
struct ioasid_allocator_ops {
|
|
|
|
ioasid_alloc_fn_t alloc;
|
|
|
|
ioasid_free_fn_t free;
|
|
|
|
struct list_head list;
|
|
|
|
void *pdata;
|
|
|
|
};
|
|
|
|
|
2019-10-03 03:42:41 +08:00
|
|
|
#define DECLARE_IOASID_SET(name) struct ioasid_set name = { 0 }
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IOASID)
|
|
|
|
ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max,
|
|
|
|
void *private);
|
2022-02-08 07:02:48 +08:00
|
|
|
void ioasid_free(ioasid_t ioasid);
|
2019-10-03 03:42:41 +08:00
|
|
|
void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
|
|
|
|
bool (*getter)(void *));
|
2019-10-03 03:42:42 +08:00
|
|
|
int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
|
|
|
|
void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
|
2019-10-03 03:42:41 +08:00
|
|
|
int ioasid_set_data(ioasid_t ioasid, void *data);
|
2022-02-08 07:02:46 +08:00
|
|
|
static inline bool pasid_valid(ioasid_t ioasid)
|
|
|
|
{
|
|
|
|
return ioasid != INVALID_IOASID;
|
|
|
|
}
|
2019-10-03 03:42:41 +08:00
|
|
|
|
|
|
|
#else /* !CONFIG_IOASID */
|
|
|
|
static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
|
|
|
|
ioasid_t max, void *private)
|
|
|
|
{
|
|
|
|
return INVALID_IOASID;
|
|
|
|
}
|
|
|
|
|
2022-02-08 07:02:48 +08:00
|
|
|
static inline void ioasid_free(ioasid_t ioasid) { }
|
2020-11-06 23:50:47 +08:00
|
|
|
|
2019-10-03 03:42:41 +08:00
|
|
|
static inline void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
|
|
|
|
bool (*getter)(void *))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-03 03:42:42 +08:00
|
|
|
static inline int ioasid_register_allocator(struct ioasid_allocator_ops *allocator)
|
|
|
|
{
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-03 03:42:41 +08:00
|
|
|
static inline int ioasid_set_data(ioasid_t ioasid, void *data)
|
|
|
|
{
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
2022-02-08 07:02:46 +08:00
|
|
|
static inline bool pasid_valid(ioasid_t ioasid)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-03 03:42:41 +08:00
|
|
|
#endif /* CONFIG_IOASID */
|
|
|
|
#endif /* __LINUX_IOASID_H */
|