pass: hal: Modify the definition of pass_get/put_resource() 86/137486/5
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 6 Jul 2017 04:45:42 +0000 (13:45 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 7 Jul 2017 05:34:02 +0000 (14:34 +0900)
The existing pass_get/put_resource() handles the all of resources
with 'struct pass *pass' argument which includes the information
of all h/w resources.

So, this patch modifies the definition of pass_get/put_resrouce()
in order to handle the each h/w resource with 'struct pass_resource *'
argument. And this patch changes the log message in the pass_init/exit_done()
in order to keep the same log format.

And this patch removes the unnecessary log of pass_get/put_resource().

[Before]
- pass_get_resource(struct pass *pass)
- pass_put_resource(struct pass *pass)

[After]
- pass_get_resource(struct pass_resource *pass_res)
- pass_put_resource(struct pass_resource *pass_res)

Change-Id: I704d1b1d9bc2cfe84fd3af05fe12ab8364b21df7
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-hal.c
src/pass/pass-hal.h
src/pass/pass.c

index 62505b24d487904abf25dad6f3cd9db28224bc27..d1d3c935de306600c9316a6e52b472501800714a 100644 (file)
@@ -489,131 +489,119 @@ int pass_set_pmqos_data(struct pass_resource *res, void *data)
        return nonstandard->set_pmqos_data(res_name, data);
 }
 
-int pass_get_resource(struct pass *pass)
+int pass_get_resource(struct pass_resource *pass_res)
 {
+       struct pass_conf_data *cdata = &pass_res->cdata;
        struct pass_resource_info *info;
-       int i, ret;
+       char *res_name = cdata->res_name;
+       char name[BUFF_MAX];
+       int res_type = cdata->res_type;
+       int ret;
        int len;
 
-       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;
-               char *res_name = cdata->res_name;
-               char name[BUFF_MAX];
-
-               switch (res_type) {
-               case PASS_RESOURCE_CPU_ID:
-                       len = strlen(PASS_RESOURCE_CPU_NAME);
-                       strncpy(name, PASS_RESOURCE_CPU_NAME, len);
-                       break;
-               case PASS_RESOURCE_BUS_ID:
-                       len = strlen(PASS_RESOURCE_BUS_NAME);
-                       strncpy(name, PASS_RESOURCE_BUS_NAME, len);
-                       break;
-               case PASS_RESOURCE_GPU_ID:
-                       len = strlen(PASS_RESOURCE_GPU_NAME);
-                       strncpy(name, PASS_RESOURCE_GPU_NAME, len);
-                       break;
-               case PASS_RESOURCE_NONSTANDARD_ID:
-                       len = strlen(PASS_RESOURCE_NONSTANDARD_NAME);
-                       strncpy(name, PASS_RESOURCE_NONSTANDARD_NAME, len);
-                       break;
-               default:
-                       _E("Unsupported resource type (type: %d)\n", res_type);
-                       return -EINVAL;
-               };
-
-               name[len] = '\0';
-
-               ret = pass_get_hal_info(name,
-                               (const struct pass_resource_info **)&info);
-               if (ret < 0) {
-                       _E("Failed to get hal info\n");
-                       return -EINVAL;
-               }
+       switch (res_type) {
+       case PASS_RESOURCE_CPU_ID:
+               len = strlen(PASS_RESOURCE_CPU_NAME);
+               strncpy(name, PASS_RESOURCE_CPU_NAME, len);
+               break;
+       case PASS_RESOURCE_BUS_ID:
+               len = strlen(PASS_RESOURCE_BUS_NAME);
+               strncpy(name, PASS_RESOURCE_BUS_NAME, len);
+               break;
+       case PASS_RESOURCE_GPU_ID:
+               len = strlen(PASS_RESOURCE_GPU_NAME);
+               strncpy(name, PASS_RESOURCE_GPU_NAME, len);
+               break;
+       case PASS_RESOURCE_NONSTANDARD_ID:
+               len = strlen(PASS_RESOURCE_NONSTANDARD_NAME);
+               strncpy(name, PASS_RESOURCE_NONSTANDARD_NAME, len);
+               break;
+       default:
+               _E("Unsupported resource type (type: %d)\n", res_type);
+               return -EINVAL;
+       };
 
-               if (!info->open || !info->close) {
-                       _E("Failed to open %s h/w device\n", name);
-                       return -EPERM;
-               }
+       name[len] = '\0';
+
+       ret = pass_get_hal_info(name,
+                       (const struct pass_resource_info **)&info);
+       if (ret < 0) {
+               _D("Failed to get %s.so for '%s' resource\n",
+                               name, res_name);
+               return -EINVAL;
+       }
 
-               switch (res_type) {
-               case PASS_RESOURCE_CPU_ID:
-                       ret = info->open(res_name, info,
-                               (struct pass_resource_common**)&pass_res->hal.cpu);
-                       break;
-               case PASS_RESOURCE_BUS_ID:
-                       ret = info->open(res_name, info,
-                               (struct pass_resource_common**)&pass_res->hal.bus);
-                       break;
-               case PASS_RESOURCE_GPU_ID:
-                       ret = info->open(res_name, info,
-                               (struct pass_resource_common**)&pass_res->hal.gpu);
-                       break;
-               case PASS_RESOURCE_NONSTANDARD_ID:
-                       ret = info->open(res_name, info,
-                               (struct pass_resource_common**)&pass_res->hal.nonstandard);
-                       break;
-               };
+       if (!info->open || !info->close) {
+               _D("Failed to get functions of %s.so for '%s' resource\n",
+                               name, res_name);
+               return -EPERM;
+       }
 
-               if (ret < 0) {
-                       _E("Failed to open %s h/w resource (%s)\n",
-                                               name, res_name);
-                       return -EINVAL;
-               }
+       switch (res_type) {
+       case PASS_RESOURCE_CPU_ID:
+               ret = info->open(res_name, info,
+                       (struct pass_resource_common**)&pass_res->hal.cpu);
+               break;
+       case PASS_RESOURCE_BUS_ID:
+               ret = info->open(res_name, info,
+                       (struct pass_resource_common**)&pass_res->hal.bus);
+               break;
+       case PASS_RESOURCE_GPU_ID:
+               ret = info->open(res_name, info,
+                       (struct pass_resource_common**)&pass_res->hal.gpu);
+               break;
+       case PASS_RESOURCE_NONSTANDARD_ID:
+               ret = info->open(res_name, info,
+                       (struct pass_resource_common**)&pass_res->hal.nonstandard);
+               break;
+       };
 
-               _D("Complete the loading for %s h/w resource (%s)\n",
-                                               name, res_name);
+       if (ret < 0) {
+               _D("Failed to open %s.so for '%s' resource\n",
+                                       name, res_name);
+               return -EINVAL;
        }
 
        return 0;
 }
 
-int pass_put_resource(struct pass *pass)
+int pass_put_resource(struct pass_resource *pass_res)
 {
+       struct pass_conf_data *cdata = &pass_res->cdata;
        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;
-               char *res_name = cdata->res_name;
-               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(res_name, 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(res_name, 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(res_name, common);
-                       break;
-               case PASS_RESOURCE_NONSTANDARD_ID:
-                       common = (struct pass_resource_common*)pass_res->hal.nonstandard;
-                       info = pass_res->hal.nonstandard->common.info;
-                       ret = info->close(res_name, common);
-               default:
-                       return -EINVAL;
-               };
+       char *res_name = cdata->res_name;
+       int res_type = cdata->res_type;
+       int ret;
 
-               if (ret < 0) {
-                       _E("Failed to close %s h/w resource (%s)\n",
-                                               info->name, res_name);
-                       return -EINVAL;
-               }
+       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(res_name, 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(res_name, 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(res_name, common);
+               break;
+       case PASS_RESOURCE_NONSTANDARD_ID:
+               common = (struct pass_resource_common*)pass_res->hal.nonstandard;
+               info = pass_res->hal.nonstandard->common.info;
+               ret = info->close(res_name, common);
+       default:
+               return -EINVAL;
+       };
 
-               _D("Complete the closing for %s h/w resource (%s)\n",
-                                               info->name, res_name);
+       if (ret < 0) {
+               _D("Failed to close %s.so for '%s' resource\n",
+                                       info->name, res_name);
+               return -EINVAL;
        }
 
        return 0;
index 1afa8c1fafca029016c63cab742785a5dbe307c7..a8f7b312d65b0541aee342f20bb21f5008aea7f5 100644 (file)
@@ -26,8 +26,8 @@
  * Functions for all H/W resources
  */
 /* Get and put the h/w resource. */
-int pass_get_resource(struct pass *pass);
-int pass_put_resource(struct pass *pass);
+int pass_get_resource(struct pass_resource *pass_res);
+int pass_put_resource(struct pass_resource *pass_res);
 
 /***
  * Functions for CPU/BUS/GPU H/W resources
index 1c52750f0014a93f7c7ca55ba2b3a34e055080c1..00c4e57fbe875d2206fa3b348323ad80e0fb11b7 100644 (file)
@@ -227,20 +227,10 @@ static int pass_init_done(void *data, void *user_data)
                return ret;
        }
 
-       /* Initialize pass resources data based on parsed configuration */
-       ret = pass_get_resource(&g_pass);
-       if (ret < 0) {
-               _E("cannot get the pass resource\n");
-               return ret;
-       }
-
+       /* Print the information for all h/w resources */
        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;
                struct pass_conf_data *cdata = &g_pass.res[i].cdata;
 
-               policy->governor = NULL;
-
                _I("Resource%d type           : %d\n", i, cdata->res_type);
                _I("Resource%d name           : %s\n", i, cdata->res_name);
                _I("Resource%d path_conf_file : %s\n", i, cdata->path_conf_file);
@@ -249,15 +239,25 @@ static int pass_init_done(void *data, void *user_data)
                _I("Resource%d first cpu      : %d\n\n", i, cdata->cpu);
        }
 
+       /* Initialize pass resources data based on parsed configuration */
        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;
+               struct pass_conf_data *cdata = &g_pass.res[i].cdata;
+
+               policy->governor = NULL;
+               ret = pass_get_resource(pass_res);
+               if (ret < -1) {
+                       _E("Cannot get the pass '%s' resource (%d)\n",
+                                       cdata->res_name, ret);
+                       return ret;
+               }
 
                ret = pass_resource_init(policy);
                if (ret < 0) {
-                       _E("cannot initialize the pass resource\n");
-                       pass_exit(NULL);
-                       return -EINVAL;
+                       _E("Cannot initialize the pass '%s' resource (%d)\n",
+                                       cdata->res_name, ret);
+                       return ret;
                }
        }
 
@@ -266,22 +266,27 @@ static int pass_init_done(void *data, void *user_data)
 
 static int pass_exit_done(void)
 {
-       int i, ret;
+       int i, 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;
+               struct pass_conf_data *cdata = &g_pass.res[i].cdata;
 
                ret = pass_resource_exit(policy);
                if (ret < 0) {
-                       _E("failed to clean up the pass resource #%d\n", i);
+                       _E("Cannot exit the pass '%s' resource (%d)\n",
+                                       cdata->res_name, ret);
                        goto exit;
                }
-       }
 
-       ret = pass_put_resource(&g_pass);
-       if (ret < 0)
-               _E("cannot put the pass resource\n");
+               ret = pass_put_resource(pass_res);
+               if (ret < 0) {
+                       _E("Cannot put the pass '%s' resource (%d)\n",
+                                       cdata->res_name, ret);
+                       goto exit;
+               }
+       }
 
 exit:
        return ret;