From patchwork Fri Mar 23 08:12:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10302899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7739F600F6 for ; Fri, 23 Mar 2018 08:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6954128C84 for ; Fri, 23 Mar 2018 08:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E23C28C8B; Fri, 23 Mar 2018 08:12:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0559E28C85 for ; Fri, 23 Mar 2018 08:12:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 10CC12228352E; Fri, 23 Mar 2018 01:05:56 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c01::243; helo=mail-pl0-x243.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DEC54223E0BB5 for ; Fri, 23 Mar 2018 01:05:54 -0700 (PDT) Received: by mail-pl0-x243.google.com with SMTP id 61-v6so7023886plf.3 for ; Fri, 23 Mar 2018 01:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OhPSyAqauZu4OcCPzSjC1rUS42tb5ogkdPbbCbLPdGw=; b=I9EhcSPoyZ4qn/NpR6bD1LJSex7j2sXDYTYi53fWOLRlT/NlR1ukqSMG/DkzcZK8/v wrFU+u8pv5YjxckMbQ5TIWgmvuVoCxd0rKu3A1Q2/ImU0uUlN15XYAqBCXQCALvF7UX1 iXM/fpwP+9psD/XWcGqEA7vvNTpEMcRqt5ndsLPR+ZrE6W2GNFxUjnCIIzQ0haO+FX15 aSbSAzwPTOXIOdoIUJdPAUHVcL3WQJ8h7vK4CBFLU+Z9LtlVVtFNAKwjiLn2/oXYBD8l 2TNKpcEgJBe2e/J7m+kPp2uiI4D3/EdWmgUp9WhgmdES/vdjXhpxFfpoWYfxyQ7KNaWq k8SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OhPSyAqauZu4OcCPzSjC1rUS42tb5ogkdPbbCbLPdGw=; b=EBaR2Rno0LBFbyvxVaOzffzs4+Z6Qr+YP61R3XsqOYo7lcKrifLZAJbLQmTHFwpLQE JS+IJ3bmjeBJo3RPEFOlr4dxXFOBxJuaHPdzxcOMyEj28NGteBUlB9vq91wbdz1+cgFW NRtv8NH1uhD4Zts/d8gw+8zEAm3dL9LlfYSRTTyltOX3hn5gH/cenQheb3xnU+6d9uGf 1JCgbY9r7/YTcbBs6s9G/724kNsH7anB8crxOMs5qCmRwWYVVnVN3Wtf/gty3nXfaBvW V56RGH9Iap9R0WNOsaEHNRZ69RzlMQz/Ym9m2l0NQDGl3cVvE/y5YVzJ4uXmKHF4KYkm kp/w== X-Gm-Message-State: AElRT7H0ZN29BqIshimCES9il+KUvSQ4r5A5dYIbNgyA3pDktUKNaFo0 5VjWx9BxKeNQSSM6164uWIzxLg== X-Google-Smtp-Source: AG47ELsxtwE8/K80jrPEs1vi11uexnUicHlDSCdY/pQkjjiP8/kN17nqnhtBvWj1UIrg05EfGR1yDg== X-Received: by 2002:a17:902:309:: with SMTP id 9-v6mr29033125pld.63.1521792747141; Fri, 23 Mar 2018 01:12:27 -0700 (PDT) Received: from localhost.localdomain ([203.220.205.233]) by smtp.gmail.com with ESMTPSA id q67sm7474808pfg.39.2018.03.23.01.12.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Mar 2018 01:12:26 -0700 (PDT) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 3/6] libnvdimm: Add device-tree based driver Date: Fri, 23 Mar 2018 19:12:06 +1100 Message-Id: <20180323081209.31387-3-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180323081209.31387-1-oohall@gmail.com> References: <20180323081209.31387-1-oohall@gmail.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds peliminary device-tree bindings for the NVDIMM driver. Currently this only supports one bus (created at probe time) which all regions are added to with individual regions being created by a platform device driver. Signed-off-by: Oliver O'Halloran --- I suspect the platform driver should be holding a reference to the created region. I left that out here since previously Dan has said he'd rather keep the struct device internal to libnvdimm and the only other way a region device can disappear is when the bus is unregistered. --- MAINTAINERS | 8 +++ drivers/nvdimm/Kconfig | 10 ++++ drivers/nvdimm/Makefile | 1 + drivers/nvdimm/of_nvdimm.c | 130 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 drivers/nvdimm/of_nvdimm.c diff --git a/MAINTAINERS b/MAINTAINERS index 4e62756936fa..e3fc47fbfc7a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8035,6 +8035,14 @@ Q: https://patchwork.kernel.org/project/linux-nvdimm/list/ S: Supported F: drivers/nvdimm/pmem* +LIBNVDIMM: DEVICETREE BINDINGS +M: Oliver O'Halloran +L: linux-nvdimm@lists.01.org +Q: https://patchwork.kernel.org/project/linux-nvdimm/list/ +S: Supported +F: drivers/nvdimm/of_nvdimm.c +F: Documentation/devicetree/bindings/nvdimm/nvdimm-bus.txt + LIBNVDIMM: NON-VOLATILE MEMORY DEVICE SUBSYSTEM M: Dan Williams L: linux-nvdimm@lists.01.org diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index a65f2e1d9f53..505a9bbbe49f 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -102,4 +102,14 @@ config NVDIMM_DAX Select Y if unsure +config OF_NVDIMM + tristate "Device-tree support for NVDIMMs" + depends on OF + default LIBNVDIMM + help + Allows byte addressable persistent memory regions to be described in the + device-tree. + + Select Y if unsure. + endif diff --git a/drivers/nvdimm/Makefile b/drivers/nvdimm/Makefile index 70d5f3ad9909..fd6a5838aa25 100644 --- a/drivers/nvdimm/Makefile +++ b/drivers/nvdimm/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_BLK_DEV_PMEM) += nd_pmem.o obj-$(CONFIG_ND_BTT) += nd_btt.o obj-$(CONFIG_ND_BLK) += nd_blk.o obj-$(CONFIG_X86_PMEM_LEGACY) += nd_e820.o +obj-$(CONFIG_OF_NVDIMM) += of_nvdimm.o nd_pmem-y := pmem.o diff --git a/drivers/nvdimm/of_nvdimm.c b/drivers/nvdimm/of_nvdimm.c new file mode 100644 index 000000000000..79c28291f420 --- /dev/null +++ b/drivers/nvdimm/of_nvdimm.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#define pr_fmt(fmt) "of_nvdimm: " fmt + +#include +#include +#include +#include +#include +#include + +/* + * Container bus stuff. For now we just chunk regions into a default + * bus with no ndctl support. In the future we'll add some mechanism + * for dispatching regions into the correct bus type, but this is useful + * for now. + */ +struct nvdimm_bus_descriptor bus_desc; +struct nvdimm_bus *bus; + +/* region driver */ + +static const struct attribute_group *region_attr_groups[] = { + &nd_region_attribute_group, + &nd_device_attribute_group, + NULL, +}; + +static const struct attribute_group *bus_attr_groups[] = { + &nvdimm_bus_attribute_group, + NULL, +}; + +static int of_nd_region_probe(struct platform_device *pdev) +{ + struct nd_region_desc ndr_desc; + struct resource temp_res; + struct nd_region *region; + struct device_node *np; + + np = dev_of_node(&pdev->dev); + if (!np) + return -ENXIO; + + pr_err("registering region for %pOF\n", np); + + if (of_address_to_resource(np, 0, &temp_res)) { + pr_warn("Unable to parse reg[0] for %pOF\n", np); + return -ENXIO; + } + + memset(&ndr_desc, 0, sizeof(ndr_desc)); + ndr_desc.res = &temp_res; + ndr_desc.of_node = np; + ndr_desc.attr_groups = region_attr_groups; + ndr_desc.numa_node = of_node_to_nid(np); + set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags); + + /* + * NB: libnvdimm copies the data from ndr_desc into it's own structures + * so passing stack pointers is fine. + */ + if (of_get_property(np, "volatile", NULL)) + region = nvdimm_volatile_region_create(bus, &ndr_desc); + else + region = nvdimm_pmem_region_create(bus, &ndr_desc); + + pr_warn("registered pmem region %px\n", region); + if (!region) + return -ENXIO; + + platform_set_drvdata(pdev, region); + + return 0; +} + +static int of_nd_region_remove(struct platform_device *pdev) +{ + struct nd_region *r = platform_get_drvdata(pdev); + + nd_region_destroy(r); + + return 0; +} + +static const struct of_device_id of_nd_region_match[] = { + { .compatible = "nvdimm-region" }, + { }, +}; + +static struct platform_driver of_nd_region_driver = { + .probe = of_nd_region_probe, + .remove = of_nd_region_remove, + .driver = { + .name = "of_nd_region", + .owner = THIS_MODULE, + .of_match_table = of_nd_region_match, + }, +}; + +/* bus wrangling */ + +static int __init of_nvdimm_init(void) +{ + /* register */ + bus_desc.attr_groups = bus_attr_groups; + bus_desc.provider_name = "of_nvdimm"; + bus_desc.module = THIS_MODULE; + + /* does parent == NULL work? */ + bus = nvdimm_bus_register(NULL, &bus_desc); + if (!bus) + return -ENODEV; + + platform_driver_register(&of_nd_region_driver); + + return 0; +} +module_init(of_nvdimm_init); + +static void __init of_nvdimm_exit(void) +{ + nvdimm_bus_unregister(bus); + platform_driver_unregister(&of_nd_region_driver); +} +module_exit(of_nvdimm_exit); + +MODULE_DEVICE_TABLE(of, of_nd_region_match); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("IBM Corporation");