2 * Copyright(c) 2019 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
6 #ifndef __UTILS_IO_ALLOCATOR_H__
7 #define __UTILS_IO_ALLOCATOR_H__
9 #include "ocf/ocf_types.h"
11 typedef struct ocf_io_allocator
*ocf_io_allocator_t
;
13 struct ocf_io_allocator_ops
{
14 int (*allocator_init
)(ocf_io_allocator_t allocator
,
15 uint32_t priv_size
, const char *name
);
16 void (*allocator_deinit
)(ocf_io_allocator_t allocator
);
17 void *(*allocator_new
)(ocf_io_allocator_t allocator
,
18 ocf_volume_t volume
, ocf_queue_t queue
,
19 uint64_t addr
, uint32_t bytes
, uint32_t dir
);
20 void (*allocator_del
)(ocf_io_allocator_t allocator
, void *obj
);
23 struct ocf_io_allocator_type
{
24 struct ocf_io_allocator_ops ops
;
27 typedef const struct ocf_io_allocator_type
*ocf_io_allocator_type_t
;
29 struct ocf_io_allocator
{
30 const struct ocf_io_allocator_type
*type
;
34 static inline void *ocf_io_allocator_new(ocf_io_allocator_t allocator
,
35 ocf_volume_t volume
, ocf_queue_t queue
,
36 uint64_t addr
, uint32_t bytes
, uint32_t dir
)
38 return allocator
->type
->ops
.allocator_new(allocator
, volume
, queue
,
42 static inline void ocf_io_allocator_del(ocf_io_allocator_t allocator
, void *obj
)
44 allocator
->type
->ops
.allocator_del(allocator
, obj
);
47 static inline int ocf_io_allocator_init(ocf_io_allocator_t allocator
,
48 ocf_io_allocator_type_t type
, uint32_t size
, const char *name
)
51 allocator
->type
= type
;
52 return allocator
->type
->ops
.allocator_init(allocator
, size
, name
);
55 static inline void ocf_io_allocator_deinit(ocf_io_allocator_t allocator
)
57 allocator
->type
->ops
.allocator_deinit(allocator
);
60 ocf_io_allocator_type_t
ocf_io_allocator_get_type_default(void);
62 #endif /* __UTILS_IO_ALLOCATOR__ */