1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/platform_device.h> 3 #include <linux/memregion.h> 4 #include <linux/module.h> 5 #include <linux/pfn_t.h> 6 #include "../bus.h" 7 8 static int dax_hmem_probe(struct platform_device *pdev) 9 { 10 struct device *dev = &pdev->dev; 11 struct dax_region *dax_region; 12 struct memregion_info *mri; 13 struct dev_dax_data data; 14 struct dev_dax *dev_dax; 15 struct resource *res; 16 17 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 18 if (!res) 19 return -ENOMEM; 20 21 mri = dev->platform_data; 22 dax_region = alloc_dax_region(dev, pdev->id, res, mri->target_node, 23 PMD_SIZE, 0); 24 if (!dax_region) 25 return -ENOMEM; 26 27 data = (struct dev_dax_data) { 28 .dax_region = dax_region, 29 .id = 0, 30 .size = resource_size(res), 31 }; 32 dev_dax = devm_create_dev_dax(&data); 33 if (IS_ERR(dev_dax)) 34 return PTR_ERR(dev_dax); 35 36 /* child dev_dax instances now own the lifetime of the dax_region */ 37 dax_region_put(dax_region); 38 return 0; 39 } 40 41 static int dax_hmem_remove(struct platform_device *pdev) 42 { 43 /* devm handles teardown */ 44 return 0; 45 } 46 47 static struct platform_driver dax_hmem_driver = { 48 .probe = dax_hmem_probe, 49 .remove = dax_hmem_remove, 50 .driver = { 51 .name = "hmem", 52 }, 53 }; 54 55 module_platform_driver(dax_hmem_driver); 56 57 MODULE_ALIAS("platform:hmem*"); 58 MODULE_LICENSE("GPL v2"); 59 MODULE_AUTHOR("Intel Corporation"); 60