|
|
26ccd9 |
From 14565442634cfab0aac8823129a175be572fb11e Mon Sep 17 00:00:00 2001
|
|
|
26ccd9 |
From: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
26ccd9 |
Date: Mon, 15 Aug 2022 13:22:06 -0600
|
|
|
26ccd9 |
Subject: [PATCH 191/217] cxl/memdev: refactor decoder mode string parsing
|
|
|
26ccd9 |
|
|
|
26ccd9 |
In preparation for create-region to use a similar decoder mode string
|
|
|
26ccd9 |
to enum operation, break out the mode string parsing into its own inline
|
|
|
26ccd9 |
helper in libcxl.h, and call it from memdev.c:__reserve_dpa().
|
|
|
26ccd9 |
|
|
|
26ccd9 |
Link: https://lore.kernel.org/r/20220815192214.545800-4-vishal.l.verma@intel.com
|
|
|
26ccd9 |
Cc: Dan Williams <dan.j.williams@intel.com>
|
|
|
26ccd9 |
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
|
|
|
26ccd9 |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
26ccd9 |
---
|
|
|
26ccd9 |
cxl/libcxl.h | 13 +++++++++++++
|
|
|
26ccd9 |
cxl/memdev.c | 11 ++---------
|
|
|
26ccd9 |
2 files changed, 15 insertions(+), 9 deletions(-)
|
|
|
26ccd9 |
|
|
|
26ccd9 |
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
|
|
|
26ccd9 |
index 33a216e..c1f8d14 100644
|
|
|
26ccd9 |
--- a/cxl/libcxl.h
|
|
|
26ccd9 |
+++ b/cxl/libcxl.h
|
|
|
26ccd9 |
@@ -4,6 +4,7 @@
|
|
|
26ccd9 |
#define _LIBCXL_H_
|
|
|
26ccd9 |
|
|
|
26ccd9 |
#include <stdarg.h>
|
|
|
26ccd9 |
+#include <string.h>
|
|
|
26ccd9 |
#include <unistd.h>
|
|
|
26ccd9 |
#include <stdbool.h>
|
|
|
26ccd9 |
|
|
|
26ccd9 |
@@ -154,6 +155,18 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)
|
|
|
26ccd9 |
return names[mode];
|
|
|
26ccd9 |
}
|
|
|
26ccd9 |
|
|
|
26ccd9 |
+static inline enum cxl_decoder_mode
|
|
|
26ccd9 |
+cxl_decoder_mode_from_ident(const char *ident)
|
|
|
26ccd9 |
+{
|
|
|
26ccd9 |
+ if (strcmp(ident, "ram") == 0)
|
|
|
26ccd9 |
+ return CXL_DECODER_MODE_RAM;
|
|
|
26ccd9 |
+ else if (strcmp(ident, "volatile") == 0)
|
|
|
26ccd9 |
+ return CXL_DECODER_MODE_RAM;
|
|
|
26ccd9 |
+ else if (strcmp(ident, "pmem") == 0)
|
|
|
26ccd9 |
+ return CXL_DECODER_MODE_PMEM;
|
|
|
26ccd9 |
+ return CXL_DECODER_MODE_NONE;
|
|
|
26ccd9 |
+}
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
enum cxl_decoder_mode cxl_decoder_get_mode(struct cxl_decoder *decoder);
|
|
|
26ccd9 |
int cxl_decoder_set_mode(struct cxl_decoder *decoder,
|
|
|
26ccd9 |
enum cxl_decoder_mode mode);
|
|
|
26ccd9 |
diff --git a/cxl/memdev.c b/cxl/memdev.c
|
|
|
26ccd9 |
index e42f554..0b3ad02 100644
|
|
|
26ccd9 |
--- a/cxl/memdev.c
|
|
|
26ccd9 |
+++ b/cxl/memdev.c
|
|
|
26ccd9 |
@@ -154,15 +154,8 @@ static int __reserve_dpa(struct cxl_memdev *memdev,
|
|
|
26ccd9 |
int rc;
|
|
|
26ccd9 |
|
|
|
26ccd9 |
if (param.type) {
|
|
|
26ccd9 |
- if (strcmp(param.type, "ram") == 0)
|
|
|
26ccd9 |
- mode = CXL_DECODER_MODE_RAM;
|
|
|
26ccd9 |
- else if (strcmp(param.type, "volatile") == 0)
|
|
|
26ccd9 |
- mode = CXL_DECODER_MODE_RAM;
|
|
|
26ccd9 |
- else if (strcmp(param.type, "ram") == 0)
|
|
|
26ccd9 |
- mode = CXL_DECODER_MODE_RAM;
|
|
|
26ccd9 |
- else if (strcmp(param.type, "pmem") == 0)
|
|
|
26ccd9 |
- mode = CXL_DECODER_MODE_PMEM;
|
|
|
26ccd9 |
- else {
|
|
|
26ccd9 |
+ mode = cxl_decoder_mode_from_ident(param.type);
|
|
|
26ccd9 |
+ if (mode == CXL_DECODER_MODE_NONE) {
|
|
|
26ccd9 |
log_err(&ml, "%s: unsupported type: %s\n", devname,
|
|
|
26ccd9 |
param.type);
|
|
|
26ccd9 |
return -EINVAL;
|
|
|
26ccd9 |
--
|
|
|
26ccd9 |
2.27.0
|
|
|
26ccd9 |
|