Linux 4.1.18
[linux/fpc-iii.git] / arch / x86 / kernel / pmem.c
blob3420c874ddc5127a0dad919660958ecb67c8d164
1 /*
2 * Copyright (c) 2015, Christoph Hellwig.
3 */
4 #include <linux/memblock.h>
5 #include <linux/platform_device.h>
6 #include <linux/slab.h>
7 #include <asm/e820.h>
8 #include <asm/page_types.h>
9 #include <asm/setup.h>
11 static __init void register_pmem_device(struct resource *res)
13 struct platform_device *pdev;
14 int error;
16 pdev = platform_device_alloc("pmem", PLATFORM_DEVID_AUTO);
17 if (!pdev)
18 return;
20 error = platform_device_add_resources(pdev, res, 1);
21 if (error)
22 goto out_put_pdev;
24 error = platform_device_add(pdev);
25 if (error)
26 goto out_put_pdev;
27 return;
29 out_put_pdev:
30 dev_warn(&pdev->dev, "failed to add 'pmem' (persistent memory) device!\n");
31 platform_device_put(pdev);
34 static __init int register_pmem_devices(void)
36 int i;
38 for (i = 0; i < e820.nr_map; i++) {
39 struct e820entry *ei = &e820.map[i];
41 if (ei->type == E820_PRAM) {
42 struct resource res = {
43 .flags = IORESOURCE_MEM,
44 .start = ei->addr,
45 .end = ei->addr + ei->size - 1,
47 register_pmem_device(&res);
51 return 0;
53 device_initcall(register_pmem_devices);