Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65e5166a authored by Patrick Daly's avatar Patrick Daly
Browse files

ion: Add pm_ops for msm_ion driver



Extend ion by allowing heaps to register the freeze and restore notifiers.

Change-Id: Ie9014013a14ce053a7fb8fa25134b339491cb609
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 33eaa278
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -159,6 +159,12 @@ struct ion_device {
	int heap_cnt;
};

/* refer to include/linux/pm.h */
struct ion_pm_ops {
	int (*freeze)(struct ion_heap *heap);
	int (*restore)(struct ion_heap *heap);
};

/**
 * struct ion_heap_ops - ops to operate on a given heap
 * @allocate:		allocate memory
@@ -184,6 +190,7 @@ struct ion_heap_ops {
	int (*map_user)(struct ion_heap *mapper, struct ion_buffer *buffer,
			struct vm_area_struct *vma);
	int (*shrink)(struct ion_heap *heap, gfp_t gfp_mask, int nr_to_scan);
	struct ion_pm_ops pm;
};

/**
+57 −0
Original line number Diff line number Diff line
@@ -344,6 +344,62 @@ static int msm_ion_probe(struct platform_device *pdev)
	return err;
}

static int msm_ion_pm_freeze(struct device *dev)
{
	struct ion_device *ion_dev = dev_get_drvdata(dev);
	struct ion_heap *heap;
	int ret;

	plist_for_each_entry(heap, &ion_dev->heaps, node) {
		if (heap->ops->pm.freeze) {
			ret = heap->ops->pm.freeze(heap);
			if (ret) {
				dev_err(dev, "%s freeze callback failed\n",
					heap->name);
				goto undo;
			}
		}
	}

	return 0;

undo:
	list_for_each_entry_continue_reverse(heap, &ion_dev->heaps.node_list,
					     node.node_list)
		if (heap->ops->pm.restore)
			heap->ops->pm.restore(heap);

	return ret;
}

static int msm_ion_pm_restore(struct device *dev)
{
	struct ion_device *ion_dev = dev_get_drvdata(dev);
	struct ion_heap *heap;
	int ret = 0;

	plist_for_each_entry(heap, &ion_dev->heaps, node) {
		int rc;

		if (heap->ops->pm.restore) {
			rc = heap->ops->pm.restore(heap);
			if (rc) {
				dev_err(dev, "%s restore callback failed.\n",
					heap->name);
				if (!ret)
					ret = rc;
			}
		}
	}

	return ret;
}

static const struct dev_pm_ops msm_ion_pm_ops = {
	.freeze = msm_ion_pm_freeze,
	.restore = msm_ion_pm_restore,
};

static const struct of_device_id msm_ion_match_table[] = {
	{.compatible = ION_COMPAT_STR},
	{},
@@ -354,6 +410,7 @@ static struct platform_driver msm_ion_driver = {
	.driver = {
		.name = "ion-msm",
		.of_match_table = msm_ion_match_table,
		.pm = &msm_ion_pm_ops,
	},
};