From owner-svn-src-head@freebsd.org Fri Feb 22 19:54:31 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6F4C614F8C4C; Fri, 22 Feb 2019 19:54:31 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0989684A10; Fri, 22 Feb 2019 19:54:31 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 84032A124; Fri, 22 Feb 2019 19:54:29 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1MJsTKO083466; Fri, 22 Feb 2019 19:54:29 GMT (envelope-from bwidawsk@FreeBSD.org) Received: (from bwidawsk@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1MJsSMq083440; Fri, 22 Feb 2019 19:54:28 GMT (envelope-from bwidawsk@FreeBSD.org) Message-Id: <201902221954.x1MJsSMq083440@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bwidawsk set sender to bwidawsk@FreeBSD.org using -f From: Ben Widawsky Date: Fri, 22 Feb 2019 19:54:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344476 - in head/sys: dev/nvdimm modules/nvdimm X-SVN-Group: head X-SVN-Commit-Author: bwidawsk X-SVN-Commit-Paths: in head/sys: dev/nvdimm modules/nvdimm X-SVN-Commit-Revision: 344476 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0989684A10 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.973,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Feb 2019 19:54:31 -0000 Author: bwidawsk Date: Fri Feb 22 19:54:28 2019 New Revision: 344476 URL: https://svnweb.freebsd.org/changeset/base/344476 Log: nvdimm: Simple namespace support Add support for simple NVDIMM v1.2 namespaces from the UEFI version 2.7 specification. The combination of NVDIMM regions and labels can lead to a wide variety of namespace layouts. Here we support a simple subset of namespaces where each NVDIMM SPA range is composed of a single region per member dimm. Submitted by: D Scott Phillips Discussed with: kib MFC after: 1 week Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D18736 Added: head/sys/dev/nvdimm/nvdimm_ns.c (contents, props changed) Modified: head/sys/dev/nvdimm/nvdimm.c head/sys/dev/nvdimm/nvdimm_var.h head/sys/modules/nvdimm/Makefile Modified: head/sys/dev/nvdimm/nvdimm.c ============================================================================== --- head/sys/dev/nvdimm/nvdimm.c Fri Feb 22 19:54:24 2019 (r344475) +++ head/sys/dev/nvdimm/nvdimm.c Fri Feb 22 19:54:28 2019 (r344476) @@ -462,6 +462,7 @@ nvdimm_root_create_spas(struct nvdimm_root_dev *dev, A free(spa, M_NVDIMM); break; } + nvdimm_create_namespaces(spa_mapping, nfitbl); SLIST_INSERT_HEAD(&dev->spas, spa_mapping, link); } free(spas, M_NVDIMM); @@ -519,6 +520,7 @@ nvdimm_root_detach(device_t dev) 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); Added: head/sys/dev/nvdimm/nvdimm_ns.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/nvdimm/nvdimm_ns.c Fri Feb 22 19:54:28 2019 (r344476) @@ -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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include +#include +#include + +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); + } +} Modified: head/sys/dev/nvdimm/nvdimm_var.h ============================================================================== --- head/sys/dev/nvdimm/nvdimm_var.h Fri Feb 22 19:54:24 2019 (r344475) +++ head/sys/dev/nvdimm/nvdimm_var.h Fri Feb 22 19:54:28 2019 (r344476) @@ -139,11 +139,18 @@ struct g_spa { 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); @@ -167,5 +174,7 @@ int nvdimm_spa_init(struct SPA_mapping *spa, ACPI_NFIT 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__ */ Modified: head/sys/modules/nvdimm/Makefile ============================================================================== --- head/sys/modules/nvdimm/Makefile Fri Feb 22 19:54:24 2019 (r344475) +++ head/sys/modules/nvdimm/Makefile Fri Feb 22 19:54:28 2019 (r344476) @@ -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