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