]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - include/rdma/uverbs_std_types.h
IB/core: Change idr objects to use the new schema
[karo-tx-linux.git] / include / rdma / uverbs_std_types.h
index 2edb77648986a2b7a42a0e71bf8ee83018e5e0b4..88856642fdf5734d9d2d660ca5f663c0c22dac7f 100644 (file)
@@ -46,5 +46,68 @@ extern const struct uverbs_obj_idr_type uverbs_type_attrs_mr;
 extern const struct uverbs_obj_idr_type uverbs_type_attrs_mw;
 extern const struct uverbs_obj_idr_type uverbs_type_attrs_pd;
 extern const struct uverbs_obj_idr_type uverbs_type_attrs_xrcd;
+
+static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
+                                           bool write,
+                                           struct ib_ucontext *ucontext,
+                                           int id)
+{
+       return rdma_lookup_get_uobject(type, ucontext, id, write);
+}
+
+#define uobj_get_type(_type) uverbs_type_attrs_##_type.type
+
+#define uobj_get_read(_type, _id, _ucontext)                           \
+        __uobj_get(&(_type), false, _ucontext, _id)
+
+#define uobj_get_obj_read(_type, _id, _ucontext)                       \
+({                                                                     \
+       struct ib_uobject *uobj =                                       \
+               __uobj_get(&uobj_get_type(_type),                       \
+                          false, _ucontext, _id);                      \
+                                                                       \
+       (struct ib_##_type *)(IS_ERR(uobj) ? NULL : uobj->object);      \
+})
+
+#define uobj_get_write(_type, _id, _ucontext)                          \
+        __uobj_get(&(_type), true, _ucontext, _id)
+
+static inline void uobj_put_read(struct ib_uobject *uobj)
+{
+       rdma_lookup_put_uobject(uobj, false);
+}
+
+#define uobj_put_obj_read(_obj)                                        \
+       uobj_put_read((_obj)->uobject)
+
+static inline void uobj_put_write(struct ib_uobject *uobj)
+{
+       rdma_lookup_put_uobject(uobj, true);
+}
+
+static inline int __must_check uobj_remove_commit(struct ib_uobject *uobj)
+{
+       return rdma_remove_commit_uobject(uobj);
+}
+
+static inline void uobj_alloc_commit(struct ib_uobject *uobj)
+{
+       rdma_alloc_commit_uobject(uobj);
+}
+
+static inline void uobj_alloc_abort(struct ib_uobject *uobj)
+{
+       rdma_alloc_abort_uobject(uobj);
+}
+
+static inline struct ib_uobject *__uobj_alloc(const struct uverbs_obj_type *type,
+                                             struct ib_ucontext *ucontext)
+{
+       return rdma_alloc_begin_uobject(type, ucontext);
+}
+
+#define uobj_alloc(_type, ucontext)    \
+       __uobj_alloc(&(_type), ucontext)
+
 #endif