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