mirror of https://gitee.com/openkylin/linux.git
libnvdimm, e820: make CONFIG_X86_PMEM_LEGACY a tristate option
We currently register a platform device for e820 type-12 memory and register a nvdimm bus beneath it. Registering the platform device triggers the device-core machinery to probe for a driver, but that search currently comes up empty. Building the nvdimm-bus registration into the e820_pmem platform device registration in this way forces libnvdimm to be built-in. Instead, convert the built-in portion of CONFIG_X86_PMEM_LEGACY to simply register a platform device and move the rest of the logic to the driver for e820_pmem, for the following reasons: 1/ Letting e820_pmem support be a module allows building and testing libnvdimm.ko changes without rebooting 2/ All the normal policy around modules can be applied to e820_pmem (unbind to disable and/or blacklisting the module from loading by default) 3/ Moving the driver to a generic location and converting it to scan "iomem_resource" rather than "e820.map" means any other architecture can take advantage of this simple nvdimm resource discovery mechanism by registering a resource named "Persistent Memory (legacy)" Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
parent
6ec689542b
commit
7a67832c7e
|
@ -1426,10 +1426,14 @@ config ILLEGAL_POINTER_VALUE
|
|||
|
||||
source "mm/Kconfig"
|
||||
|
||||
config X86_PMEM_LEGACY_DEVICE
|
||||
bool
|
||||
|
||||
config X86_PMEM_LEGACY
|
||||
bool "Support non-standard NVDIMMs and ADR protected memory"
|
||||
tristate "Support non-standard NVDIMMs and ADR protected memory"
|
||||
depends on PHYS_ADDR_T_64BIT
|
||||
depends on BLK_DEV
|
||||
select X86_PMEM_LEGACY_DEVICE
|
||||
select LIBNVDIMM
|
||||
help
|
||||
Treat memory marked using the non-standard e820 type of 12 as used
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
/*
|
||||
* This is a non-standardized way to represent ADR or NVDIMM regions that
|
||||
* persist over a reboot. The kernel will ignore their special capabilities
|
||||
* unless the CONFIG_X86_PMEM_LEGACY=y option is set.
|
||||
* unless the CONFIG_X86_PMEM_LEGACY option is set.
|
||||
*
|
||||
* ( Note that older platforms also used 6 for the same type of memory,
|
||||
* but newer versions switched to 12 as 6 was assigned differently. Some
|
||||
|
|
|
@ -92,7 +92,7 @@ obj-$(CONFIG_KVM_GUEST) += kvm.o kvmclock.o
|
|||
obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o
|
||||
obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= paravirt-spinlocks.o
|
||||
obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o
|
||||
obj-$(CONFIG_X86_PMEM_LEGACY) += pmem.o
|
||||
obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o
|
||||
|
||||
obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o
|
||||
|
||||
|
|
|
@ -3,80 +3,17 @@
|
|||
* Copyright (c) 2015, Intel Corporation.
|
||||
*/
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/libnvdimm.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/e820.h>
|
||||
|
||||
static void e820_pmem_release(struct device *dev)
|
||||
{
|
||||
struct nvdimm_bus *nvdimm_bus = dev->platform_data;
|
||||
|
||||
if (nvdimm_bus)
|
||||
nvdimm_bus_unregister(nvdimm_bus);
|
||||
}
|
||||
|
||||
static struct platform_device e820_pmem = {
|
||||
.name = "e820_pmem",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.release = e820_pmem_release,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct attribute_group *e820_pmem_attribute_groups[] = {
|
||||
&nvdimm_bus_attribute_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group *e820_pmem_region_attribute_groups[] = {
|
||||
&nd_region_attribute_group,
|
||||
&nd_device_attribute_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static __init int register_e820_pmem(void)
|
||||
{
|
||||
static struct nvdimm_bus_descriptor nd_desc;
|
||||
struct device *dev = &e820_pmem.dev;
|
||||
struct nvdimm_bus *nvdimm_bus;
|
||||
int rc, i;
|
||||
struct platform_device *pdev;
|
||||
|
||||
rc = platform_device_register(&e820_pmem);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
nd_desc.attr_groups = e820_pmem_attribute_groups;
|
||||
nd_desc.provider_name = "e820";
|
||||
nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
|
||||
if (!nvdimm_bus)
|
||||
goto err;
|
||||
dev->platform_data = nvdimm_bus;
|
||||
|
||||
for (i = 0; i < e820.nr_map; i++) {
|
||||
struct e820entry *ei = &e820.map[i];
|
||||
struct resource res = {
|
||||
.flags = IORESOURCE_MEM,
|
||||
.start = ei->addr,
|
||||
.end = ei->addr + ei->size - 1,
|
||||
};
|
||||
struct nd_region_desc ndr_desc;
|
||||
|
||||
if (ei->type != E820_PRAM)
|
||||
continue;
|
||||
|
||||
memset(&ndr_desc, 0, sizeof(ndr_desc));
|
||||
ndr_desc.res = &res;
|
||||
ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
|
||||
ndr_desc.numa_node = NUMA_NO_NODE;
|
||||
if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
dev_err(dev, "failed to register legacy persistent memory ranges\n");
|
||||
platform_device_unregister(&e820_pmem);
|
||||
return -ENXIO;
|
||||
/*
|
||||
* See drivers/nvdimm/e820.c for the implementation, this is
|
||||
* simply here to trigger the module to load on demand.
|
||||
*/
|
||||
pdev = platform_device_alloc("e820_pmem", -1);
|
||||
return platform_device_add(pdev);
|
||||
}
|
||||
device_initcall(register_e820_pmem);
|
||||
|
|
|
@ -2,6 +2,7 @@ obj-$(CONFIG_LIBNVDIMM) += libnvdimm.o
|
|||
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
|
||||
|
||||
nd_pmem-y := pmem.o
|
||||
|
||||
|
@ -9,6 +10,8 @@ nd_btt-y := btt.o
|
|||
|
||||
nd_blk-y := blk.o
|
||||
|
||||
nd_e820-y := e820.o
|
||||
|
||||
libnvdimm-y := core.o
|
||||
libnvdimm-y += bus.o
|
||||
libnvdimm-y += dimm_devs.o
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Christoph Hellwig.
|
||||
* Copyright (c) 2015, Intel Corporation.
|
||||
*/
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/libnvdimm.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
static const struct attribute_group *e820_pmem_attribute_groups[] = {
|
||||
&nvdimm_bus_attribute_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group *e820_pmem_region_attribute_groups[] = {
|
||||
&nd_region_attribute_group,
|
||||
&nd_device_attribute_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int e820_pmem_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct nvdimm_bus *nvdimm_bus = platform_get_drvdata(pdev);
|
||||
|
||||
nvdimm_bus_unregister(nvdimm_bus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int e820_pmem_probe(struct platform_device *pdev)
|
||||
{
|
||||
static struct nvdimm_bus_descriptor nd_desc;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct nvdimm_bus *nvdimm_bus;
|
||||
struct resource *p;
|
||||
|
||||
nd_desc.attr_groups = e820_pmem_attribute_groups;
|
||||
nd_desc.provider_name = "e820";
|
||||
nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
|
||||
if (!nvdimm_bus)
|
||||
goto err;
|
||||
platform_set_drvdata(pdev, nvdimm_bus);
|
||||
|
||||
for (p = iomem_resource.child; p ; p = p->sibling) {
|
||||
struct nd_region_desc ndr_desc;
|
||||
|
||||
if (strncmp(p->name, "Persistent Memory (legacy)", 26) != 0)
|
||||
continue;
|
||||
|
||||
memset(&ndr_desc, 0, sizeof(ndr_desc));
|
||||
ndr_desc.res = p;
|
||||
ndr_desc.attr_groups = e820_pmem_region_attribute_groups;
|
||||
ndr_desc.numa_node = NUMA_NO_NODE;
|
||||
if (!nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc))
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
nvdimm_bus_unregister(nvdimm_bus);
|
||||
dev_err(dev, "failed to register legacy persistent memory ranges\n");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
static struct platform_driver e820_pmem_driver = {
|
||||
.probe = e820_pmem_probe,
|
||||
.remove = e820_pmem_remove,
|
||||
.driver = {
|
||||
.name = "e820_pmem",
|
||||
},
|
||||
};
|
||||
|
||||
static __init int e820_pmem_init(void)
|
||||
{
|
||||
return platform_driver_register(&e820_pmem_driver);
|
||||
}
|
||||
|
||||
static __exit void e820_pmem_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&e820_pmem_driver);
|
||||
}
|
||||
|
||||
MODULE_ALIAS("platform:e820_pmem*");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_AUTHOR("Intel Corporation");
|
||||
module_init(e820_pmem_init);
|
||||
module_exit(e820_pmem_exit);
|
|
@ -15,6 +15,7 @@ obj-$(CONFIG_LIBNVDIMM) += libnvdimm.o
|
|||
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_ACPI_NFIT) += nfit.o
|
||||
|
||||
nfit-y := $(ACPI_SRC)/nfit.o
|
||||
|
@ -29,6 +30,9 @@ nd_btt-y += config_check.o
|
|||
nd_blk-y := $(NVDIMM_SRC)/blk.o
|
||||
nd_blk-y += config_check.o
|
||||
|
||||
nd_e820-y := $(NVDIMM_SRC)/e820.o
|
||||
nd_e820-y += config_check.o
|
||||
|
||||
libnvdimm-y := $(NVDIMM_SRC)/core.o
|
||||
libnvdimm-y += $(NVDIMM_SRC)/bus.o
|
||||
libnvdimm-y += $(NVDIMM_SRC)/dimm_devs.o
|
||||
|
|
Loading…
Reference in New Issue