• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  */
5 
6 #include <linux/module.h>
7 #include <linux/rwsem.h>
8 #include <linux/gunyah_rsc_mgr.h>
9 
10 #include "rsc_mgr.h"
11 
12 static const struct gh_rm_platform_ops *rm_platform_ops;
13 static DECLARE_RWSEM(rm_platform_ops_lock);
14 
gh_rm_platform_pre_mem_share(struct gh_rm * rm,struct gh_rm_mem_parcel * mem_parcel)15 int gh_rm_platform_pre_mem_share(struct gh_rm *rm, struct gh_rm_mem_parcel *mem_parcel)
16 {
17 	int ret = 0;
18 
19 	down_read(&rm_platform_ops_lock);
20 	if (rm_platform_ops && rm_platform_ops->pre_mem_share)
21 		ret = rm_platform_ops->pre_mem_share(rm, mem_parcel);
22 	up_read(&rm_platform_ops_lock);
23 	return ret;
24 }
25 EXPORT_SYMBOL_GPL(gh_rm_platform_pre_mem_share);
26 
gh_rm_platform_post_mem_reclaim(struct gh_rm * rm,struct gh_rm_mem_parcel * mem_parcel)27 int gh_rm_platform_post_mem_reclaim(struct gh_rm *rm, struct gh_rm_mem_parcel *mem_parcel)
28 {
29 	int ret = 0;
30 
31 	down_read(&rm_platform_ops_lock);
32 	if (rm_platform_ops && rm_platform_ops->post_mem_reclaim)
33 		ret = rm_platform_ops->post_mem_reclaim(rm, mem_parcel);
34 	up_read(&rm_platform_ops_lock);
35 	return ret;
36 }
37 EXPORT_SYMBOL_GPL(gh_rm_platform_post_mem_reclaim);
38 
gh_rm_register_platform_ops(const struct gh_rm_platform_ops * platform_ops)39 int gh_rm_register_platform_ops(const struct gh_rm_platform_ops *platform_ops)
40 {
41 	int ret = 0;
42 
43 	down_write(&rm_platform_ops_lock);
44 	if (!rm_platform_ops)
45 		rm_platform_ops = platform_ops;
46 	else
47 		ret = -EEXIST;
48 	up_write(&rm_platform_ops_lock);
49 	return ret;
50 }
51 EXPORT_SYMBOL_GPL(gh_rm_register_platform_ops);
52 
gh_rm_unregister_platform_ops(const struct gh_rm_platform_ops * platform_ops)53 void gh_rm_unregister_platform_ops(const struct gh_rm_platform_ops *platform_ops)
54 {
55 	down_write(&rm_platform_ops_lock);
56 	if (rm_platform_ops == platform_ops)
57 		rm_platform_ops = NULL;
58 	up_write(&rm_platform_ops_lock);
59 }
60 EXPORT_SYMBOL_GPL(gh_rm_unregister_platform_ops);
61 
_devm_gh_rm_unregister_platform_ops(void * data)62 static void _devm_gh_rm_unregister_platform_ops(void *data)
63 {
64 	gh_rm_unregister_platform_ops((const struct gh_rm_platform_ops *)data);
65 }
66 
devm_gh_rm_register_platform_ops(struct device * dev,const struct gh_rm_platform_ops * ops)67 int devm_gh_rm_register_platform_ops(struct device *dev, const struct gh_rm_platform_ops *ops)
68 {
69 	int ret;
70 
71 	ret = gh_rm_register_platform_ops(ops);
72 	if (ret)
73 		return ret;
74 
75 	return devm_add_action(dev, _devm_gh_rm_unregister_platform_ops, (void *)ops);
76 }
77 EXPORT_SYMBOL_GPL(devm_gh_rm_register_platform_ops);
78 
79 MODULE_LICENSE("GPL");
80 MODULE_DESCRIPTION("Gunyah Platform Hooks");
81