Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/platform_device.h>
0003 #include <linux/memregion.h>
0004 #include <linux/module.h>
0005 #include <linux/pfn_t.h>
0006 #include "../bus.h"
0007 
0008 static bool region_idle;
0009 module_param_named(region_idle, region_idle, bool, 0644);
0010 
0011 static int dax_hmem_probe(struct platform_device *pdev)
0012 {
0013     struct device *dev = &pdev->dev;
0014     struct dax_region *dax_region;
0015     struct memregion_info *mri;
0016     struct dev_dax_data data;
0017     struct dev_dax *dev_dax;
0018     struct resource *res;
0019     struct range range;
0020 
0021     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0022     if (!res)
0023         return -ENOMEM;
0024 
0025     mri = dev->platform_data;
0026     range.start = res->start;
0027     range.end = res->end;
0028     dax_region = alloc_dax_region(dev, pdev->id, &range, mri->target_node,
0029             PMD_SIZE, 0);
0030     if (!dax_region)
0031         return -ENOMEM;
0032 
0033     data = (struct dev_dax_data) {
0034         .dax_region = dax_region,
0035         .id = -1,
0036         .size = region_idle ? 0 : resource_size(res),
0037     };
0038     dev_dax = devm_create_dev_dax(&data);
0039     if (IS_ERR(dev_dax))
0040         return PTR_ERR(dev_dax);
0041 
0042     /* child dev_dax instances now own the lifetime of the dax_region */
0043     dax_region_put(dax_region);
0044     return 0;
0045 }
0046 
0047 static int dax_hmem_remove(struct platform_device *pdev)
0048 {
0049     /* devm handles teardown */
0050     return 0;
0051 }
0052 
0053 static struct platform_driver dax_hmem_driver = {
0054     .probe = dax_hmem_probe,
0055     .remove = dax_hmem_remove,
0056     .driver = {
0057         .name = "hmem",
0058     },
0059 };
0060 
0061 module_platform_driver(dax_hmem_driver);
0062 
0063 MODULE_ALIAS("platform:hmem*");
0064 MODULE_LICENSE("GPL v2");
0065 MODULE_AUTHOR("Intel Corporation");