diff options
author | Vishal Verma <vishal.l.verma@intel.com> | 2022-08-12 14:29:11 -0600 |
---|---|---|
committer | Vishal Verma <vishal.l.verma@intel.com> | 2022-08-16 00:15:20 -0600 |
commit | c378ff2b8b7a501d567e4f143c1d175f2cd95bb5 (patch) | |
tree | ac6f64be194938a0cae68beee945c187dbde9736 | |
parent | 9c46b56afb59079e2d936bf4739ab0f80c60b746 (diff) |
cxl/memdev: refactor decoder mode string parsing
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>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
-rw-r--r-- | cxl/libcxl.h | 13 | ||||
-rw-r--r-- | cxl/memdev.c | 11 |
2 files changed, 15 insertions, 9 deletions
diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 33a216ee..c1f8d14a 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -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); diff --git a/cxl/memdev.c b/cxl/memdev.c index e42f5543..0b3ad022 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -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; |