forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libnvdimm, nfit: dimm/memory-devices
Enable nvdimm devices to be registered on a nvdimm_bus. The kernel assigned device id for nvdimm devicesis dynamic. If userspace needs a more static identifier it should consult a provider-specific attribute. In the case where NFIT is the provider, the 'nmemX/nfit/handle' or 'nmemX/nfit/serial' attributes may be used for this purpose. Cc: Neil Brown <neilb@suse.de> Cc: <linux-acpi@vger.kernel.org> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Robert Moore <robert.moore@intel.com> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Christoph Hellwig <hch@lst.de> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Toshi Kani <toshi.kani@hp.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
- Loading branch information
Showing
8 changed files
with
321 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ obj-$(CONFIG_LIBNVDIMM) += libnvdimm.o | |
|
||
libnvdimm-y := core.o | ||
libnvdimm-y += bus.o | ||
libnvdimm-y += dimm_devs.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
*/ | ||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
#include <linux/device.h> | ||
#include <linux/slab.h> | ||
#include <linux/io.h> | ||
#include <linux/fs.h> | ||
#include <linux/mm.h> | ||
#include "nd-core.h" | ||
|
||
static DEFINE_IDA(dimm_ida); | ||
|
||
static void nvdimm_release(struct device *dev) | ||
{ | ||
struct nvdimm *nvdimm = to_nvdimm(dev); | ||
|
||
ida_simple_remove(&dimm_ida, nvdimm->id); | ||
kfree(nvdimm); | ||
} | ||
|
||
static struct device_type nvdimm_device_type = { | ||
.name = "nvdimm", | ||
.release = nvdimm_release, | ||
}; | ||
|
||
static bool is_nvdimm(struct device *dev) | ||
{ | ||
return dev->type == &nvdimm_device_type; | ||
} | ||
|
||
struct nvdimm *to_nvdimm(struct device *dev) | ||
{ | ||
struct nvdimm *nvdimm = container_of(dev, struct nvdimm, dev); | ||
|
||
WARN_ON(!is_nvdimm(dev)); | ||
return nvdimm; | ||
} | ||
EXPORT_SYMBOL_GPL(to_nvdimm); | ||
|
||
const char *nvdimm_name(struct nvdimm *nvdimm) | ||
{ | ||
return dev_name(&nvdimm->dev); | ||
} | ||
EXPORT_SYMBOL_GPL(nvdimm_name); | ||
|
||
void *nvdimm_provider_data(struct nvdimm *nvdimm) | ||
{ | ||
return nvdimm->provider_data; | ||
} | ||
EXPORT_SYMBOL_GPL(nvdimm_provider_data); | ||
|
||
struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus, void *provider_data, | ||
const struct attribute_group **groups, unsigned long flags) | ||
{ | ||
struct nvdimm *nvdimm = kzalloc(sizeof(*nvdimm), GFP_KERNEL); | ||
struct device *dev; | ||
|
||
if (!nvdimm) | ||
return NULL; | ||
|
||
nvdimm->id = ida_simple_get(&dimm_ida, 0, 0, GFP_KERNEL); | ||
if (nvdimm->id < 0) { | ||
kfree(nvdimm); | ||
return NULL; | ||
} | ||
nvdimm->provider_data = provider_data; | ||
nvdimm->flags = flags; | ||
|
||
dev = &nvdimm->dev; | ||
dev_set_name(dev, "nmem%d", nvdimm->id); | ||
dev->parent = &nvdimm_bus->dev; | ||
dev->type = &nvdimm_device_type; | ||
dev->bus = &nvdimm_bus_type; | ||
dev->groups = groups; | ||
if (device_register(dev) != 0) { | ||
put_device(dev); | ||
return NULL; | ||
} | ||
|
||
return nvdimm; | ||
} | ||
EXPORT_SYMBOL_GPL(nvdimm_create); |
Oops, something went wrong.