pmem.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. static __init void register_pmem_device(struct resource *res)
  11. {
  12. struct platform_device *pdev;
  13. int error;
  14. pdev = platform_device_alloc("pmem", PLATFORM_DEVID_AUTO);
  15. if (!pdev)
  16. return;
  17. error = platform_device_add_resources(pdev, res, 1);
  18. if (error)
  19. goto out_put_pdev;
  20. error = platform_device_add(pdev);
  21. if (error)
  22. goto out_put_pdev;
  23. return;
  24. out_put_pdev:
  25. dev_warn(&pdev->dev, "failed to add 'pmem' (persistent memory) device!\n");
  26. platform_device_put(pdev);
  27. }
  28. static __init int register_pmem_devices(void)
  29. {
  30. int i;
  31. for (i = 0; i < e820.nr_map; i++) {
  32. struct e820entry *ei = &e820.map[i];
  33. if (ei->type == E820_PRAM) {
  34. struct resource res = {
  35. .flags = IORESOURCE_MEM,
  36. .start = ei->addr,
  37. .end = ei->addr + ei->size - 1,
  38. };
  39. register_pmem_device(&res);
  40. }
  41. }
  42. return 0;
  43. }
  44. device_initcall(register_pmem_devices);