linux/drivers/dax/hmem.c
<<
>>
Prefs
   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
   8static int dax_hmem_probe(struct platform_device *pdev)
   9{
  10        struct device *dev = &pdev->dev;
  11        struct dev_pagemap pgmap = { };
  12        struct dax_region *dax_region;
  13        struct memregion_info *mri;
  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        memcpy(&pgmap.res, res, sizeof(*res));
  23
  24        dax_region = alloc_dax_region(dev, pdev->id, res, mri->target_node,
  25                        PMD_SIZE, PFN_DEV|PFN_MAP);
  26        if (!dax_region)
  27                return -ENOMEM;
  28
  29        dev_dax = devm_create_dev_dax(dax_region, 0, &pgmap);
  30        if (IS_ERR(dev_dax))
  31                return PTR_ERR(dev_dax);
  32
  33        /* child dev_dax instances now own the lifetime of the dax_region */
  34        dax_region_put(dax_region);
  35        return 0;
  36}
  37
  38static int dax_hmem_remove(struct platform_device *pdev)
  39{
  40        /* devm handles teardown */
  41        return 0;
  42}
  43
  44static struct platform_driver dax_hmem_driver = {
  45        .probe = dax_hmem_probe,
  46        .remove = dax_hmem_remove,
  47        .driver = {
  48                .name = "hmem",
  49        },
  50};
  51
  52module_platform_driver(dax_hmem_driver);
  53
  54MODULE_ALIAS("platform:hmem*");
  55MODULE_LICENSE("GPL v2");
  56MODULE_AUTHOR("Intel Corporation");
  57