pass: hal: Add a function for putting resource 88/121688/3
authorWook Song <wook16.song@samsung.com>
Tue, 28 Mar 2017 08:08:36 +0000 (17:08 +0900)
committerWook Song <wook16.song@samsung.com>
Wed, 26 Apr 2017 05:50:21 +0000 (14:50 +0900)
This patch adds the pass_put_resource function, which is paired up with
pass_get_resource(). When the main daemon is terminated, every hardware
resources resources (which are opened by pass_get_resource()) are closed
via HAL by this function.

Change-Id: I454d931979c5753ad070c44e58e9256429e6f7f7
Signed-off-by: Wook Song <wook16.song@samsung.com>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-hal.c
src/pass/pass-hal.h
src/pass/pass.c

index 129d025e2fb3f9d3d6af266a2fd953f7e192aa53..8b1f3b14d5dbc4779ee32447da94687f88f4a83d 100644 (file)
@@ -533,6 +533,47 @@ int pass_get_resource(struct pass *pass)
        return 0;
 }
 
+int pass_put_resource(struct pass *pass)
+{
+       struct pass_resource_common *common;
+       struct pass_resource_info *info;
+       int i, ret;
+
+       for (i = 0; i < pass->num_resources; i++) {
+               struct pass_resource *pass_res = &pass->res[i];
+               struct pass_conf_data *cdata = &pass_res->cdata;
+               int res_type = cdata->res_type;
+
+               switch (res_type) {
+               case PASS_RESOURCE_CPU_ID:
+                       common = (struct pass_resource_common*)pass_res->hal.cpu;
+                       info = pass_res->hal.cpu->common.info;
+                       ret = info->close(common);
+                       break;
+               case PASS_RESOURCE_BUS_ID:
+                       common = (struct pass_resource_common*)pass_res->hal.bus;
+                       info = pass_res->hal.bus->common.info;
+                       ret = info->close(common);
+                       break;
+               case PASS_RESOURCE_GPU_ID:
+                       common = (struct pass_resource_common*)pass_res->hal.gpu;
+                       info = pass_res->hal.gpu->common.info;
+                       ret = info->close(common);
+                       break;
+               default:
+                       return -EINVAL;
+               };
+
+               if (ret < 0) {
+                       _E("Failed to close %s h/w resource\n", info->name);
+                       return -EINVAL;
+               }
+
+               _D("Complete the closing for %s h/w resource\n", info->name);
+       }
+
+       return 0;
+}
 /*
  * FXIME: Following function is not standard interface.
  * Following functions will be altered by the standard interface on later.
index 09eb879d2175d4d332fdc3d699944b1165a935fb..6700eeaa48c613759414a8ae454de5b79e8713ce 100644 (file)
@@ -55,8 +55,9 @@ int pass_set_online_max_num(struct pass_resource *res, int num);
 int pass_get_temp(struct pass_resource *res);
 int pass_get_policy(struct pass_resource *res, char *policy);
 
-/* Load the h/w resource. */
+/* Get and put the h/w resource. */
 int pass_get_resource(struct pass *pass);
+int pass_put_resource(struct pass *pass);
 
 /*
  * FXIME: Following function is not standard interface.
index 40ae21582fd36937f3d001f776025c7d515a8ae4..33e08f38b6b7cd831aa27296ed5f0812e14b44ae 100644 (file)
@@ -268,7 +268,6 @@ static int pass_exit_done(void)
 {
        int i, ret;
 
-       ret = 0;
        for (i = 0; i < g_pass.num_resources; i++) {
                struct pass_resource *pass_res = &g_pass.res[i];
                struct pass_policy *policy = &pass_res->policy;
@@ -276,10 +275,15 @@ static int pass_exit_done(void)
                ret = pass_resource_exit(policy);
                if (ret < 0) {
                        _E("failed to clean up the pass resource #%d\n", i);
-                       break;
+                       goto exit;
                }
        }
 
+       ret = pass_put_resource(&g_pass);
+       if (ret < 0)
+               _E("cannot put the pass resource\n");
+
+exit:
        return ret;
 }