@@ -4,6 +4,7 @@
#define _LIBCXL_H_
#include <stdarg.h>
+#include <string.h>
#include <unistd.h>
#include <stdbool.h>
@@ -154,6 +155,18 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)
return names[mode];
}
+static inline enum cxl_decoder_mode
+cxl_decoder_mode_from_ident(const char *ident)
+{
+ if (strcmp(ident, "ram") == 0)
+ return CXL_DECODER_MODE_RAM;
+ else if (strcmp(ident, "volatile") == 0)
+ return CXL_DECODER_MODE_RAM;
+ else if (strcmp(ident, "pmem") == 0)
+ return CXL_DECODER_MODE_PMEM;
+ return CXL_DECODER_MODE_NONE;
+}
+
enum cxl_decoder_mode cxl_decoder_get_mode(struct cxl_decoder *decoder);
int cxl_decoder_set_mode(struct cxl_decoder *decoder,
enum cxl_decoder_mode mode);
@@ -154,15 +154,8 @@ static int __reserve_dpa(struct cxl_memdev *memdev,
int rc;
if (param.type) {
- if (strcmp(param.type, "ram") == 0)
- mode = CXL_DECODER_MODE_RAM;
- else if (strcmp(param.type, "volatile") == 0)
- mode = CXL_DECODER_MODE_RAM;
- else if (strcmp(param.type, "ram") == 0)
- mode = CXL_DECODER_MODE_RAM;
- else if (strcmp(param.type, "pmem") == 0)
- mode = CXL_DECODER_MODE_PMEM;
- else {
+ mode = cxl_decoder_mode_from_ident(param.type);
+ if (mode == CXL_DECODER_MODE_NONE) {
log_err(&ml, "%s: unsupported type: %s\n", devname,
param.type);
return -EINVAL;
In preparation for create-region to use a similar decoder mode string to enum operation, break out the mode string parsing into its own inline helper in libcxl.h, and call it from memdev.c:__reserve_dpa(). Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> --- cxl/libcxl.h | 13 +++++++++++++ cxl/memdev.c | 11 ++--------- 2 files changed, 15 insertions(+), 9 deletions(-)