summaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/pmem.c
blob: 3420c874ddc5127a0dad919660958ecb67c8d164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2015, Christoph Hellwig.
 */
#include <linux/memblock.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <asm/e820.h>
#include <asm/page_types.h>
#include <asm/setup.h>

static __init void register_pmem_device(struct resource *res)
{
	struct platform_device *pdev;
	int error;

	pdev = platform_device_alloc("pmem", PLATFORM_DEVID_AUTO);
	if (!pdev)
		return;

	error = platform_device_add_resources(pdev, res, 1);
	if (error)
		goto out_put_pdev;

	error = platform_device_add(pdev);
	if (error)
		goto out_put_pdev;
	return;

out_put_pdev:
	dev_warn(&pdev->dev, "failed to add 'pmem' (persistent memory) device!\n");
	platform_device_put(pdev);
}

static __init int register_pmem_devices(void)
{
	int i;

	for (i = 0; i < e820.nr_map; i++) {
		struct e820entry *ei = &e820.map[i];

		if (ei->type == E820_PRAM) {
			struct resource res = {
				.flags	= IORESOURCE_MEM,
				.start	= ei->addr,
				.end	= ei->addr + ei->size - 1,
			};
			register_pmem_device(&res);
		}
	}

	return 0;
}
device_initcall(register_pmem_devices);
OpenPOWER on IntegriCloud