Christoph Hellwig | ec776ef | 2015-04-01 09:12:18 +0200 | [diff] [blame] | 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> |
| 10 | |
| 11 | static __init void register_pmem_device(struct resource *res) |
| 12 | { |
| 13 | struct platform_device *pdev; |
| 14 | int error; |
| 15 | |
| 16 | pdev = platform_device_alloc("pmem", PLATFORM_DEVID_AUTO); |
| 17 | if (!pdev) |
| 18 | return; |
| 19 | |
| 20 | error = platform_device_add_resources(pdev, res, 1); |
| 21 | if (error) |
| 22 | goto out_put_pdev; |
| 23 | |
| 24 | error = platform_device_add(pdev); |
| 25 | if (error) |
| 26 | goto out_put_pdev; |
| 27 | return; |
| 28 | |
| 29 | out_put_pdev: |
| 30 | dev_warn(&pdev->dev, "failed to add 'pmem' (persistent memory) device!\n"); |
| 31 | platform_device_put(pdev); |
| 32 | } |
| 33 | |
| 34 | static __init int register_pmem_devices(void) |
| 35 | { |
| 36 | int i; |
| 37 | |
| 38 | for (i = 0; i < e820.nr_map; i++) { |
| 39 | struct e820entry *ei = &e820.map[i]; |
| 40 | |
| 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, |
| 46 | }; |
| 47 | register_pmem_device(&res); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | device_initcall(register_pmem_devices); |