Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146667742
D17619.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D17619.diff
View Options
Index: sys/dev/nvdimm/nvdimm.c
===================================================================
--- sys/dev/nvdimm/nvdimm.c
+++ sys/dev/nvdimm/nvdimm.c
@@ -461,6 +461,7 @@
free(spa, M_NVDIMM);
break;
}
+ nvdimm_create_namespaces(spa, nfitbl);
SLIST_INSERT_HEAD(&dev->spas, spa, link);
}
free(spas, M_NVDIMM);
@@ -518,6 +519,7 @@
root = device_get_softc(dev);
SLIST_FOREACH_SAFE(spa, &root->spas, link, next) {
+ nvdimm_destroy_namespaces(spa);
nvdimm_spa_fini(spa);
SLIST_REMOVE_HEAD(&root->spas, link);
free(spa, M_NVDIMM);
Index: sys/dev/nvdimm/nvdimm_ns.c
===================================================================
--- /dev/null
+++ sys/dev/nvdimm/nvdimm_ns.c
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2018 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bio.h>
+#include <sys/bus.h>
+#include <sys/malloc.h>
+#include <sys/uuid.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
+#include <dev/acpica/acpivar.h>
+#include <dev/nvdimm/nvdimm_var.h>
+
+int
+nvdimm_create_namespaces(struct SPA_mapping *spa, ACPI_TABLE_NFIT *nfitbl)
+{
+ ACPI_NFIT_MEMORY_MAP **regions;
+ struct nvdimm_dev *nv;
+ struct nvdimm_label_entry *e;
+ struct nvdimm_namespace *ns;
+ nfit_handle_t dimm_handle;
+ char *name;
+ int i, error, num_regions;
+
+ acpi_nfit_get_region_mappings_by_spa_range(nfitbl, spa->spa_nfit_idx,
+ ®ions, &num_regions);
+ if (num_regions == 0 || num_regions != regions[0]->InterleaveWays) {
+ free(regions, M_NVDIMM);
+ return (ENXIO);
+ }
+ dimm_handle = regions[0]->DeviceHandle;
+ nv = nvdimm_find_by_handle(dimm_handle);
+ if (nv == NULL) {
+ free(regions, M_NVDIMM);
+ return (ENXIO);
+ }
+ i = 0;
+ error = 0;
+ SLIST_FOREACH(e, &nv->labels, link) {
+ ns = malloc(sizeof(struct nvdimm_namespace), M_NVDIMM,
+ M_WAITOK | M_ZERO);
+ ns->dev.spa_domain = spa->dev.spa_domain;
+ ns->dev.spa_phys_base = spa->dev.spa_phys_base +
+ regions[0]->RegionOffset +
+ num_regions *
+ (e->label.dimm_phys_addr - regions[0]->Address);
+ ns->dev.spa_len = num_regions * e->label.raw_size;
+ ns->dev.spa_efi_mem_flags = spa->dev.spa_efi_mem_flags;
+ asprintf(&name, M_NVDIMM, "spa%dns%d", spa->spa_nfit_idx, i);
+ error = nvdimm_spa_dev_init(&ns->dev, name);
+ free(name, M_NVDIMM);
+ if (error != 0)
+ break;
+ SLIST_INSERT_HEAD(&spa->namespaces, ns, link);
+ i++;
+ }
+ free(regions, M_NVDIMM);
+ return (error);
+}
+
+void
+nvdimm_destroy_namespaces(struct SPA_mapping *spa)
+{
+ struct nvdimm_namespace *ns, *next;
+
+ SLIST_FOREACH_SAFE(ns, &spa->namespaces, link, next) {
+ SLIST_REMOVE_HEAD(&spa->namespaces, link);
+ nvdimm_spa_dev_fini(&ns->dev);
+ free(ns, M_NVDIMM);
+ }
+}
Index: sys/dev/nvdimm/nvdimm_var.h
===================================================================
--- sys/dev/nvdimm/nvdimm_var.h
+++ sys/dev/nvdimm/nvdimm_var.h
@@ -138,11 +138,18 @@
bool spa_g_proc_exiting;
};
+struct nvdimm_namespace {
+ SLIST_ENTRY(nvdimm_namespace) link;
+ struct SPA_mapping *spa;
+ struct nvdimm_spa_dev dev;
+};
+
struct SPA_mapping {
SLIST_ENTRY(SPA_mapping) link;
enum SPA_mapping_type spa_type;
int spa_nfit_idx;
struct nvdimm_spa_dev dev;
+ SLIST_HEAD(, nvdimm_namespace) namespaces;
};
MALLOC_DECLARE(M_NVDIMM);
@@ -166,5 +173,7 @@
void nvdimm_spa_fini(struct SPA_mapping *spa);
int nvdimm_spa_dev_init(struct nvdimm_spa_dev *dev, const char *name);
void nvdimm_spa_dev_fini(struct nvdimm_spa_dev *dev);
+int nvdimm_create_namespaces(struct SPA_mapping *spa, ACPI_TABLE_NFIT *nfitbl);
+void nvdimm_destroy_namespaces(struct SPA_mapping *spa);
#endif /* __DEV_NVDIMM_VAR_H__ */
Index: sys/modules/nvdimm/Makefile
===================================================================
--- sys/modules/nvdimm/Makefile
+++ sys/modules/nvdimm/Makefile
@@ -5,6 +5,7 @@
KMOD= nvdimm
SRCS= nvdimm.c \
nvdimm_nfit.c \
+ nvdimm_ns.c \
nvdimm_spa.c
SRCS+= acpi_if.h bus_if.h device_if.h
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 5, 1:51 PM (18 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29287189
Default Alt Text
D17619.diff (5 KB)
Attached To
Mode
D17619: nvdimm: Simple namespace support
Attached
Detach File
Event Timeline
Log In to Comment