2 * Remote processor resource manager
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Copyright (C) 2011 Google, Inc.
7 * Fernando Guzman Lugo <fernando.lugo@ti.com>
8 * Miguel Vadillo <vadillo@ti.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/virtio.h>
19 #include <linux/slab.h>
20 #include <linux/rpmsg.h>
21 #include <linux/delay.h>
22 #include <linux/idr.h>
23 #include <linux/remoteproc.h>
24 #include <linux/clk.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/regulator/driver.h>
27 #include <linux/regulator/machine.h>
28 #include <linux/gpio.h>
29 #include <linux/err.h>
30 #include <linux/list.h>
31 #include <linux/debugfs.h>
32 #include <linux/rpmsg_resmgr.h>
33 #include <linux/pm_runtime.h>
34 #include <plat/dmtimer.h>
35 #include <plat/rpres.h>
36 #include <plat/clock.h>
39 #include <plat/omap_hwmod.h>
42 #define REGULATOR_MAX 1
46 #define GPTIMERS_MAX 11
48 #define MAX_MSG (sizeof(struct rprm_ack) + sizeof(struct rprm_sdma))
50 static struct dentry
*rprm_dbg
;
52 static char *regulator_name
[] = {
56 static char *clk_src_name
[] = {
62 static const char const *rnames
[] = {
63 [RPRM_GPTIMER
] = "GP Timer",
64 [RPRM_L3BUS
] = "L3 bus",
65 [RPRM_IVAHD
] = "IVA HD",
66 [RPRM_IVASEQ0
] = "IVA SEQ0",
67 [RPRM_IVASEQ1
] = "IVA SEQ1",
69 [RPRM_SL2IF
] = "SL2IF",
71 [RPRM_AUXCLK
] = "AUXCLK",
72 [RPRM_REGULATOR
] = "REGULATOR",
80 static const char *rname(u32 type
) {
87 struct list_head next
;
93 struct rprm_constraints_data
*constraints
;
98 struct list_head res_list
;
102 struct dentry
*dbg_dir
;
105 struct rprm_auxclk_depot
{
110 struct rprm_regulator_depot
{
111 struct regulator
*reg_p
;
115 static struct rprm_constraints_data def_data
= {
121 static int _get_rprm_size(u32 type
)
125 return sizeof(struct rprm_gpt
);
127 return sizeof(struct rprm_auxclk
);
129 return sizeof(struct rprm_regulator
);
131 return sizeof(struct rprm_gpio
);
133 return sizeof(struct rprm_sdma
);
135 return sizeof(struct rprm_i2c
);
140 static int rprm_gptimer_request(struct rprm_elem
*e
, struct rprm_gpt
*obj
)
143 struct omap_dm_timer
*gpt
;
145 if (obj
->id
> GPTIMERS_MAX
) {
146 pr_err("Invalid gptimer %u\n", obj
->id
);
150 gpt
= omap_dm_timer_request_specific(obj
->id
);
154 ret
= omap_dm_timer_set_source(gpt
, obj
->src_clk
);
158 omap_dm_timer_free(gpt
);
163 static void rprm_gptimer_release(struct omap_dm_timer
*obj
)
165 omap_dm_timer_free(obj
);
168 static int rprm_auxclk_request(struct rprm_elem
*e
, struct rprm_auxclk
*obj
)
171 char clk_name
[NAME_SIZE
];
172 char src_clk_name
[NAME_SIZE
];
173 struct rprm_auxclk_depot
*acd
;
174 struct clk
*src_parent
;
176 if ((obj
->id
< AUX_CLK_MIN
) || (obj
->id
> AUX_CLK_MAX
)) {
177 pr_err("Invalid aux_clk %d\n", obj
->id
);
181 /* Create auxclks depot */
182 acd
= kmalloc(sizeof(*acd
), GFP_KERNEL
);
186 sprintf(clk_name
, "auxclk%d_ck", obj
->id
);
187 acd
->aux_clk
= clk_get(NULL
, clk_name
);
189 pr_err("%s: unable to get clock %s\n", __func__
, clk_name
);
194 if (unlikely(acd
->aux_clk
->usecount
))
195 pr_warn("There are other users of %d clk\n", obj
->id
);
197 sprintf(src_clk_name
, "auxclk%d_src_ck", obj
->id
);
198 acd
->src
= clk_get(NULL
, src_clk_name
);
200 pr_err("%s: unable to get clock %s\n", __func__
, src_clk_name
);
205 src_parent
= clk_get(NULL
, clk_src_name
[obj
->parent_src_clk
]);
207 pr_err("%s: unable to get parent clock %s\n", __func__
,
208 clk_src_name
[obj
->parent_src_clk
]);
213 ret
= clk_set_rate(src_parent
, (obj
->parent_src_clk_rate
* MHZ
));
215 pr_err("%s: rate not supported by %s\n", __func__
,
216 clk_src_name
[obj
->parent_src_clk
]);
218 goto error_aux_src_parent
;
221 ret
= clk_set_parent(acd
->src
, src_parent
);
223 pr_err("%s: unable to set clk %s as parent of aux_clk %s\n",
225 clk_src_name
[obj
->parent_src_clk
],
227 goto error_aux_src_parent
;
230 ret
= clk_enable(acd
->src
);
232 pr_err("%s: error enabling %s\n", __func__
, src_clk_name
);
233 goto error_aux_src_parent
;
236 ret
= clk_set_rate(acd
->aux_clk
, (obj
->clk_rate
* MHZ
));
238 pr_err("%s: rate not supported by %s\n", __func__
, clk_name
);
239 goto error_aux_src_parent
;
242 ret
= clk_enable(acd
->aux_clk
);
244 pr_err("%s: error enabling %s\n", __func__
, clk_name
);
245 goto error_aux_enable
;
253 clk_disable(acd
->src
);
254 error_aux_src_parent
:
259 clk_put(acd
->aux_clk
);
266 static void rprm_auxclk_release(struct rprm_auxclk_depot
*obj
)
268 clk_disable((struct clk
*)obj
->aux_clk
);
269 clk_put((struct clk
*)obj
->aux_clk
);
270 clk_disable((struct clk
*)obj
->src
);
271 clk_put((struct clk
*)obj
->src
);
277 int rprm_regulator_request(struct rprm_elem
*e
, struct rprm_regulator
*obj
)
280 struct rprm_regulator_depot
*rd
;
283 if (obj
->id
> REGULATOR_MAX
) {
284 pr_err("Invalid regulator %d\n", obj
->id
);
288 /* Create regulator depot */
289 rd
= kmalloc(sizeof(*rd
), GFP_KERNEL
);
293 reg_name
= regulator_name
[obj
->id
- 1];
294 rd
->reg_p
= regulator_get_exclusive(NULL
, reg_name
);
295 if (IS_ERR_OR_NULL(rd
->reg_p
)) {
296 pr_err("%s: error providing regulator %s\n", __func__
, reg_name
);
301 rd
->orig_uv
= regulator_get_voltage(rd
->reg_p
);
303 ret
= regulator_set_voltage(rd
->reg_p
, obj
->min_uv
, obj
->max_uv
);
305 pr_err("%s: error setting %s voltage\n", __func__
, reg_name
);
309 ret
= regulator_enable(rd
->reg_p
);
311 pr_err("%s: error enabling %s ldo\n", __func__
, reg_name
);
320 regulator_put(rd
->reg_p
);
327 static void rprm_regulator_release(struct rprm_regulator_depot
*obj
)
331 ret
= regulator_disable(obj
->reg_p
);
333 pr_err("%s: error disabling ldo\n", __func__
);
337 /* Restore orginal voltage */
338 ret
= regulator_set_voltage(obj
->reg_p
, obj
->orig_uv
, obj
->orig_uv
);
340 pr_err("%s: error restoring voltage\n", __func__
);
344 regulator_put(obj
->reg_p
);
348 static int rprm_gpio_request(struct rprm_elem
*e
, struct rprm_gpio
*obj
)
351 struct rprm_gpio
*gd
;
353 /* Create gpio depot */
354 gd
= kmalloc(sizeof(*gd
), GFP_KERNEL
);
358 ret
= gpio_request(obj
->id
, "rpmsg_resmgr");
360 pr_err("%s: error providing gpio %d\n", __func__
, obj
->id
);
364 e
->handle
= memcpy(gd
, obj
, sizeof(*obj
));
369 static void rprm_gpio_release(struct rprm_gpio
*obj
)
375 static int rprm_sdma_request(struct rprm_elem
*e
, struct rprm_sdma
*obj
)
380 struct rprm_sdma
*sd
;
382 /* Create sdma depot */
383 sd
= kmalloc(sizeof(*sd
), GFP_KERNEL
);
387 if (obj
->num_chs
> MAX_NUM_SDMA_CHANNELS
) {
388 pr_err("Not able to provide %u channels\n", obj
->num_chs
);
392 for (i
= 0; i
< obj
->num_chs
; i
++) {
393 ret
= omap_request_dma(0, "rpmsg_resmgr", NULL
, NULL
, &sdma
);
395 pr_err("Error providing sdma channel %d\n", ret
);
398 obj
->channels
[i
] = sdma
;
399 pr_debug("Providing sdma ch %d\n", sdma
);
402 e
->handle
= memcpy(sd
, obj
, sizeof(*obj
));
407 omap_free_dma(obj
->channels
[i
]);
412 static void rprm_sdma_release(struct rprm_sdma
*obj
)
414 int i
= obj
->num_chs
;
417 omap_free_dma(obj
->channels
[i
]);
418 pr_debug("Releasing sdma ch %d\n", obj
->channels
[i
]);
423 static int rprm_i2c_request(struct rprm_elem
*e
, struct rprm_i2c
*obj
)
425 struct device
*i2c_dev
;
426 struct i2c_adapter
*adapter
;
427 char i2c_name
[NAME_SIZE
];
430 sprintf(i2c_name
, "i2c%d", obj
->id
);
431 i2c_dev
= omap_hwmod_name_get_dev(i2c_name
);
432 if (IS_ERR_OR_NULL(i2c_dev
)) {
433 pr_err("%s: unable to lookup %s\n", __func__
, i2c_name
);
437 adapter
= i2c_get_adapter(obj
->id
);
439 pr_err("%s: could not get i2c%d adapter\n", __func__
, obj
->id
);
442 i2c_detect_ext_master(adapter
);
443 i2c_put_adapter(adapter
);
445 ret
= pm_runtime_get_sync(i2c_dev
);
447 * pm_runtime_get_sync can return 1 in case it is already active,
448 * change it to 0 to indicate success.
454 dev_warn(i2c_dev
, "%s: failed get sync %d\n", __func__
, ret
);
459 static int rprm_i2c_release(struct device
*i2c_dev
)
463 if (IS_ERR_OR_NULL(i2c_dev
)) {
464 pr_err("%s: invalid device passed\n", __func__
);
468 ret
= pm_runtime_put_sync(i2c_dev
);
470 dev_warn(i2c_dev
, "%s: failed put sync %d\n", __func__
, ret
);
476 static const char *_get_rpres_name(int type
)
482 return "rpres_iva_seq0";
484 return "rpres_iva_seq1";
490 return "rpres_sl2if";
495 static int _rpres_set_constraints(struct rprm_elem
*e
, u32 type
, long val
)
499 return rpres_set_constraints(e
->handle
,
500 RPRES_CONSTRAINT_SCALE
,
503 return rpres_set_constraints(e
->handle
,
504 RPRES_CONSTRAINT_LATENCY
,
507 return rpres_set_constraints(e
->handle
,
508 RPRES_CONSTRAINT_BANDWIDTH
,
511 pr_err("Invalid constraint\n");
515 static int _rproc_set_constraints(struct rprm_elem
*e
, u32 type
, long val
)
519 return rproc_set_constraints(e
->handle
,
520 RPROC_CONSTRAINT_SCALE
,
523 return rproc_set_constraints(e
->handle
,
524 RPROC_CONSTRAINT_LATENCY
,
527 return rproc_set_constraints(e
->handle
,
528 RPROC_CONSTRAINT_BANDWIDTH
,
531 pr_err("Invalid constraint\n");
536 int _set_constraints(struct rprm_elem
*e
, struct rprm_constraints_data
*c
)
540 int (*_set_constraints_func
)(struct rprm_elem
*, u32 type
, long val
);
546 _set_constraints_func
= _rpres_set_constraints
;
549 _set_constraints_func
= _rproc_set_constraints
;
555 if (c
->mask
& RPRM_SCALE
) {
556 ret
= _set_constraints_func(e
, RPRM_SCALE
, c
->frequency
);
560 e
->constraints
->frequency
= c
->frequency
;
563 if (c
->mask
& RPRM_LATENCY
) {
564 ret
= _set_constraints_func(e
, RPRM_LATENCY
, c
->latency
);
567 mask
|= RPRM_LATENCY
;
568 e
->constraints
->latency
= c
->latency
;
571 if (c
->mask
& RPRM_BANDWIDTH
) {
572 ret
= _set_constraints_func(e
, RPRM_BANDWIDTH
, c
->bandwidth
);
575 mask
|= RPRM_BANDWIDTH
;
576 e
->constraints
->bandwidth
= c
->bandwidth
;
583 static int rprm_set_constraints(struct rprm
*rprm
, u32 addr
, int res_id
,
584 void *data
, bool set
)
589 mutex_lock(&rprm
->lock
);
590 if (!idr_find(&rprm
->conn_list
, addr
)) {
595 e
= idr_find(&rprm
->id_list
, res_id
);
596 if (!e
|| e
->src
!= addr
) {
601 if (!e
->constraints
) {
602 pr_warn("No constraints\n");
608 ret
= _set_constraints(e
, data
);
610 e
->constraints
->mask
|=
611 ((struct rprm_constraints_data
*)data
)->mask
;
615 def_data
.mask
= ((struct rprm_constraints_data
*)data
)->mask
;
617 _set_constraints(e
, &def_data
);
618 e
->constraints
->mask
&=
619 ~((struct rprm_constraints_data
*)data
)->mask
;
622 mutex_unlock(&rprm
->lock
);
627 static int rprm_rpres_request(struct rprm_elem
*e
, int type
)
629 const char *res_name
= _get_rpres_name(type
);
632 e
->constraints
= kzalloc(sizeof(*(e
->constraints
)), GFP_KERNEL
);
633 if (!(e
->constraints
))
636 res
= rpres_get(res_name
);
639 pr_err("%s: error requesting %s\n", __func__
, res_name
);
640 kfree(e
->constraints
);
648 static void rprm_rpres_release(struct rpres
*res
)
653 static int rprm_rproc_request(struct rprm_elem
*e
, char *name
)
657 e
->constraints
= kzalloc(sizeof(*(e
->constraints
)), GFP_KERNEL
);
658 if (!(e
->constraints
))
661 rp
= rproc_get(name
);
663 pr_debug("Error requesting %s\n", name
);
664 kfree(e
->constraints
);
672 static void rprm_rproc_release(struct rproc
*rp
)
677 static int _resource_free(struct rprm_elem
*e
)
680 if (e
->constraints
&& e
->constraints
->mask
) {
681 def_data
.mask
= e
->constraints
->mask
;
682 _set_constraints(e
, &def_data
);
684 kfree(e
->constraints
);
688 rprm_gptimer_release(e
->handle
);
696 rprm_rpres_release(e
->handle
);
700 rprm_rproc_release(e
->handle
);
703 rprm_auxclk_release(e
->handle
);
706 ret
= rprm_i2c_release(e
->handle
);
709 rprm_regulator_release(e
->handle
);
712 rprm_gpio_release(e
->handle
);
715 rprm_sdma_release(e
->handle
);
718 /* ignore silently */
727 static int rprm_resource_free(struct rprm
*rprm
, u32 addr
, int res_id
)
732 mutex_lock(&rprm
->lock
);
733 if (!idr_find(&rprm
->conn_list
, addr
)) {
738 e
= idr_find(&rprm
->id_list
, res_id
);
739 if (!e
|| e
->src
!= addr
) {
743 idr_remove(&rprm
->id_list
, res_id
);
746 mutex_unlock(&rprm
->lock
);
749 ret
= _resource_free(e
);
756 static int _resource_alloc(struct rprm_elem
*e
, int type
, void *data
)
762 ret
= rprm_gptimer_request(e
, data
);
770 ret
= rprm_rpres_request(e
, type
);
773 ret
= rprm_rproc_request(e
, "ipu");
776 ret
= rprm_rproc_request(e
, "dsp");
779 ret
= rprm_auxclk_request(e
, data
);
782 ret
= rprm_i2c_request(e
, data
);
785 ret
= rprm_regulator_request(e
, data
);
788 ret
= rprm_gpio_request(e
, data
);
791 ret
= rprm_sdma_request(e
, data
);
794 /* ignore silently; */
797 pr_err("%s: invalid source %d!\n", __func__
, type
);
804 static int rprm_resource_alloc(struct rprm
*rprm
, u32 addr
, int *res_id
,
805 int type
, void *data
)
809 int rlen
= _get_rprm_size(type
);
811 e
= kzalloc(sizeof(*e
) + rlen
, GFP_KERNEL
);
815 ret
= _resource_alloc(e
, type
, data
);
817 pr_err("%s: request for %d (%s) failed: %d\n", __func__
,
818 type
, rname(type
), ret
);
822 mutex_lock(&rprm
->lock
);
823 if (!idr_find(&rprm
->conn_list
, addr
)) {
824 pr_err("%s: addr %d not connected!\n", __func__
, addr
);
829 * Create a resource id to avoid sending kernel address to the
832 if (!idr_pre_get(&rprm
->id_list
, GFP_KERNEL
)) {
836 ret
= idr_get_new(&rprm
->id_list
, e
, res_id
);
843 memcpy(e
->res
, data
, rlen
);
844 list_add(&e
->next
, &rprm
->res_list
);
845 mutex_unlock(&rprm
->lock
);
849 mutex_unlock(&rprm
->lock
);
857 static int rprm_disconnect_client(struct rprm
*rprm
, u32 addr
)
859 struct rprm_elem
*e
, *tmp
;
862 mutex_lock(&rprm
->lock
);
863 if (!idr_find(&rprm
->conn_list
, addr
)) {
867 list_for_each_entry_safe(e
, tmp
, &rprm
->res_list
, next
) {
868 if (e
->src
== addr
) {
870 idr_remove(&rprm
->id_list
, e
->id
);
876 idr_remove(&rprm
->conn_list
, addr
);
878 mutex_unlock(&rprm
->lock
);
883 static int rpmsg_connect_client(struct rprm
*rprm
, u32 addr
)
888 mutex_lock(&rprm
->lock
);
889 if (idr_find(&rprm
->conn_list
, addr
)) {
890 pr_err("Connection already opened\n");
894 if (!idr_pre_get(&rprm
->conn_list
, GFP_KERNEL
)) {
898 ret
= idr_get_new_above(&rprm
->conn_list
, &rprm
->res_list
, addr
, &tid
);
901 mutex_unlock(&rprm
->lock
);
906 static void rprm_cb(struct rpmsg_channel
*rpdev
, void *data
, int len
,
910 struct device
*dev
= &rpdev
->dev
;
911 struct rprm
*rprm
= dev_get_drvdata(dev
);
912 struct rprm_request
*req
= data
;
913 char ack_msg
[MAX_MSG
];
914 struct rprm_ack
*ack
= (void *)ack_msg
;
917 if (len
< sizeof(*req
)) {
918 dev_err(dev
, "Bad message\n");
922 dev_dbg(dev
, "resource type %d\n"
925 req
->res_type
, req
->acquire
, req
->res_id
);
927 switch (req
->acquire
) {
929 ret
= rpmsg_connect_client(rprm
, src
);
931 dev_err(dev
, "connection failed! ret %d\n", ret
);
934 r_sz
= len
- sizeof(*req
);
935 if (r_sz
!= _get_rprm_size(req
->res_type
)) {
940 ret
= rprm_resource_alloc(rprm
, src
, &req
->res_id
,
941 req
->res_type
, req
->data
);
943 dev_err(dev
, "resource allocation failed! ret %d\n",
947 ret
= rprm_resource_free(rprm
, src
, req
->res_id
);
949 dev_err(dev
, "resource release failed! ret %d\n", ret
);
951 case RPRM_DISCONNECT
:
952 ret
= rprm_disconnect_client(rprm
, src
);
954 dev_err(dev
, "disconnection failed ret %d\n", ret
);
956 case RPRM_REQ_CONSTRAINTS
:
957 r_sz
= len
- sizeof(*req
);
958 if (r_sz
!= sizeof(struct rprm_constraints_data
)) {
963 ret
= rprm_set_constraints(rprm
, src
, req
->res_id
,
966 dev_err(dev
, "set constraints failed! ret %d\n", ret
);
968 case RPRM_REL_CONSTRAINTS
:
969 ret
= rprm_set_constraints(rprm
, src
, req
->res_id
,
972 dev_err(dev
, "rel constraints failed! ret %d\n", ret
);
975 dev_err(dev
, "Unknow request\n");
980 ack
->res_type
= req
->res_type
;
981 ack
->res_id
= req
->res_id
;
982 memcpy(ack
->data
, req
->data
, r_sz
);
984 ret
= rpmsg_sendto(rpdev
, ack
, sizeof(*ack
) + r_sz
, src
);
986 dev_err(dev
, "rprm ack failed: %d\n", ret
);
989 static int _printf_gptimer_args(char *buf
, struct rprm_gpt
*obj
)
994 obj
->id
, obj
->src_clk
);
997 static int _printf_auxclk_args(char *buf
, struct rprm_auxclk
*obj
)
1003 "ParentSrcRate:%d\n",
1004 obj
->id
, obj
->clk_rate
, obj
->parent_src_clk
,
1005 obj
->parent_src_clk_rate
);
1008 static int _printf_regulator_args(char *buf
, struct rprm_regulator
*obj
)
1014 obj
->id
, obj
->min_uv
, obj
->max_uv
);
1017 static int _printf_gpio_args(char *buf
, struct rprm_gpio
*obj
)
1019 return sprintf(buf
, "Id:%d\n", obj
->id
);
1022 static int _printf_i2c_args(char *buf
, struct rprm_i2c
*obj
)
1024 return sprintf(buf
, "Id:%d\n", obj
->id
);
1027 static int _printf_sdma_args(char *buf
, struct rprm_sdma
*obj
)
1030 ret
+= sprintf(buf
, "NumChannels:%d\n", obj
->num_chs
);
1031 for (i
= 0 ; i
< obj
->num_chs
; i
++)
1032 ret
+= sprintf(buf
+ ret
, "Channel[%d]:%d\n", i
,
1037 static int _print_res_args(char *buf
, struct rprm_elem
*e
)
1039 void *res
= (void *)e
->res
;
1043 return _printf_gptimer_args(buf
, res
);
1045 return _printf_auxclk_args(buf
, res
);
1047 return _printf_i2c_args(buf
, res
);
1048 case RPRM_REGULATOR
:
1049 return _printf_regulator_args(buf
, res
);
1051 return _printf_gpio_args(buf
, res
);
1053 return _printf_sdma_args(buf
, res
);
1058 static int _printf_constraints_args(char *buf
, struct rprm_elem
*e
)
1065 e
->constraints
->mask
, e
->constraints
->frequency
,
1066 e
->constraints
->latency
, e
->constraints
->bandwidth
);
1069 static ssize_t
rprm_dbg_read(struct file
*filp
, char __user
*userbuf
,
1070 size_t count
, loff_t
*ppos
)
1072 struct rprm
*rprm
= filp
->private_data
;
1073 struct rprm_elem
*e
;
1075 int total
= 0, c
, tmp
;
1078 list_for_each_entry(e
, &rprm
->res_list
, next
) {
1080 "\nResource Name:%s\n"
1081 "Source address:%d\n",
1082 rnames
[e
->type
], e
->src
);
1084 if (_get_rprm_size(e
->type
))
1085 c
+= _print_res_args(res
+ c
, e
);
1087 if (e
->constraints
&& e
->constraints
->mask
)
1088 c
+= _printf_constraints_args(res
+ c
, e
);
1094 tmp
= simple_read_from_buffer(userbuf
+ total
, count
, &pt
,
1105 static int rprm_dbg_open(struct inode
*inode
, struct file
*file
)
1107 file
->private_data
= inode
->i_private
;
1111 static const struct file_operations rprm_dbg_ops
= {
1112 .read
= rprm_dbg_read
,
1113 .open
= rprm_dbg_open
,
1114 .llseek
= generic_file_llseek
,
1117 static int rprm_probe(struct rpmsg_channel
*rpdev
)
1121 rprm
= kmalloc(sizeof(*rprm
), GFP_KERNEL
);
1125 mutex_init(&rprm
->lock
);
1126 INIT_LIST_HEAD(&rprm
->res_list
);
1127 idr_init(&rprm
->conn_list
);
1128 idr_init(&rprm
->id_list
);
1129 dev_set_drvdata(&rpdev
->dev
, rprm
);
1131 rprm
->dbg_dir
= debugfs_create_dir(dev_name(&rpdev
->dev
), rprm_dbg
);
1133 dev_err(&rpdev
->dev
, "can't create debugfs dir\n");
1135 debugfs_create_file("resources", 0400, rprm
->dbg_dir
, rprm
,
1141 static void __devexit
rprm_remove(struct rpmsg_channel
*rpdev
)
1143 struct rprm
*rprm
= dev_get_drvdata(&rpdev
->dev
);
1144 struct rprm_elem
*e
, *tmp
;
1146 dev_info(&rpdev
->dev
, "Enter %s\n", __func__
);
1149 debugfs_remove_recursive(rprm
->dbg_dir
);
1151 mutex_lock(&rprm
->lock
);
1153 /* clean up remaining resources */
1154 list_for_each_entry_safe(e
, tmp
, &rprm
->res_list
, next
) {
1159 idr_remove_all(&rprm
->id_list
);
1160 idr_destroy(&rprm
->id_list
);
1161 idr_remove_all(&rprm
->conn_list
);
1162 idr_destroy(&rprm
->conn_list
);
1164 mutex_unlock(&rprm
->lock
);
1169 static struct rpmsg_device_id rprm_id_table
[] = {
1171 .name
= "rpmsg-resmgr",
1175 MODULE_DEVICE_TABLE(platform
, rprm_id_table
);
1177 static struct rpmsg_driver rprm_driver
= {
1178 .drv
.name
= KBUILD_MODNAME
,
1179 .drv
.owner
= THIS_MODULE
,
1180 .id_table
= rprm_id_table
,
1181 .probe
= rprm_probe
,
1182 .callback
= rprm_cb
,
1183 .remove
= __devexit_p(rprm_remove
),
1186 static int __init
init(void)
1190 if (debugfs_initialized()) {
1191 rprm_dbg
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
1193 pr_err("Error creating rprm debug directory\n");
1195 r
= register_rpmsg_driver(&rprm_driver
);
1197 debugfs_remove_recursive(rprm_dbg
);
1202 static void __exit
fini(void)
1205 debugfs_remove_recursive(rprm_dbg
);
1206 unregister_rpmsg_driver(&rprm_driver
);
1211 MODULE_DESCRIPTION("Remote Processor Resource Manager");
1212 MODULE_LICENSE("GPL v2");