diff options
author | Dongwoo Lee <dwoo08.lee@samsung.com> | 2022-10-13 12:23:24 +0900 |
---|---|---|
committer | Youngjae Cho <y0.cho@samsung.com> | 2022-10-31 11:21:11 +0900 |
commit | 7cefd01b6ef3af9c7fa482f2048d1719da39fd44 (patch) | |
tree | c5f9e36e0b2b1cb03784a88a0fb0098cdaf98bd2 | |
parent | 1cb4ff9439c7d7d2bf7a16961b24ce0509f1d540 (diff) | |
download | pass-7cefd01b6ef3af9c7fa482f2048d1719da39fd44.tar.gz pass-7cefd01b6ef3af9c7fa482f2048d1719da39fd44.tar.bz2 pass-7cefd01b6ef3af9c7fa482f2048d1719da39fd44.zip |
resource: Resolve dependency of HAL devices
To include resource device related features to the resource library,
this separates it from pass core.
Change-Id: I35327b1932de35f5af2a516f361552160215b088
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
-rw-r--r-- | include/util/devices.h | 16 | ||||
-rw-r--r-- | include/util/resource.h | 18 | ||||
-rw-r--r-- | src/monitor/request-handler.c | 23 | ||||
-rw-r--r-- | src/resource/resource-bus.c | 1 | ||||
-rw-r--r-- | src/resource/resource-cpu.c | 1 | ||||
-rw-r--r-- | src/resource/resource-disk.c | 1 | ||||
-rw-r--r-- | src/resource/resource-display.c | 1 | ||||
-rw-r--r-- | src/resource/resource-gpu.c | 1 | ||||
-rw-r--r-- | src/resource/resource-network.c | 1 | ||||
-rw-r--r-- | src/util/devices.c | 60 | ||||
-rw-r--r-- | src/util/resource.c | 80 |
11 files changed, 106 insertions, 97 deletions
diff --git a/include/util/devices.h b/include/util/devices.h index 1a896ea..ef53f26 100644 --- a/include/util/devices.h +++ b/include/util/devices.h @@ -51,6 +51,17 @@ enum device_ops_status { DEVICE_OPS_STATUS_MAX, }; +struct resource_device { + char *name; + int type; + + /* + * Never initialize it by user of add_resource_device(). + * It will be initialized by add_resource_device function automatically. + */ + int index; +}; + #define DEVICE_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ module_init(void) \ { \ @@ -61,6 +72,11 @@ static void __DESTRUCTOR__ module_exit(void) \ remove_device(dev); \ } +int get_resource_device_count(int resource_type); +const struct resource_device *find_resource_device(int resource_type, int resource_index); +int add_resource_device(struct resource_device *resource_device); +void remove_resource_device(struct resource_device *resource_device); + void init_devices(void *data); void exit_devices(void *data); void add_device(const struct device_ops *dev); diff --git a/include/util/resource.h b/include/util/resource.h index eb46610..f0e55d2 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -138,17 +138,6 @@ struct resource { u_int64_t attr_supported; }; -struct resource_device { - char *name; - int type; - - /* - * Never initialize it by user of add_resource_device(). - * It will be initialized by add_resource_device function automatically. - */ - int index; -}; - #define RESOURCE_DRIVER_REGISTER(resource_driver) \ static void __CONSTRUCTOR__ module_init(void) \ { \ @@ -160,15 +149,10 @@ static void __DESTRUCTOR__ module_exit(void) \ } /* Add/remove resource driver and device */ +const struct resource_driver *find_resource_driver(int resource_type); void add_resource_driver(const struct resource_driver *resource_driver); void remove_resource_driver(const struct resource_driver *resource_driver); -int get_resource_device_count_all(void); -int get_resource_device_count(int resource_type); -const struct resource_device *find_resource_device(int resource_type, int resource_index); -int add_resource_device(struct resource_device *resource_device); -void remove_resource_device(struct resource_device *resource_device); - /* Create/delete resource instance */ int create_resource(struct resource **res, int resource_type); void delete_resource(struct resource *resource); diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index 4059ddc..fe241b2 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -25,6 +25,7 @@ #include <glib.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> #include <util/thread.h> @@ -204,6 +205,26 @@ static int handle_request_update_resource(struct request_client *client, char *a return 0; } +static int get_resource_count(int resource_type) +{ + const struct resource_driver *driver; + int count = get_resource_device_count(resource_type); + + if (count > 0) + return count; + + driver = find_resource_driver(resource_type); + if (!driver) + return -EINVAL; + + if (driver->flag & RESOURCE_FLAG_COUNT_ONLY_ONE) + return 1; + else if (driver->flag & RESOURCE_FLAG_PROCESS) + return -EINVAL; + + return 0; +} + static int handle_request_get_resource_count(struct request_client *client, char *args, int *value) { int resource_type; @@ -220,7 +241,7 @@ static int handle_request_get_resource_count(struct request_client *client, char */ resource_type = atoi(args); - ret = get_resource_device_count(resource_type); + ret = get_resource_count(resource_type); if (ret < 0) { _E("failed to get resource device count, res:type(%d)\n", resource_type); return ret; diff --git a/src/resource/resource-bus.c b/src/resource/resource-bus.c index 2cbba18..22807f6 100644 --- a/src/resource/resource-bus.c +++ b/src/resource/resource-bus.c @@ -27,6 +27,7 @@ #include <hal/hal-power.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> diff --git a/src/resource/resource-cpu.c b/src/resource/resource-cpu.c index 2f316be..aa2d405 100644 --- a/src/resource/resource-cpu.c +++ b/src/resource/resource-cpu.c @@ -27,6 +27,7 @@ #include <hal/hal-power.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> diff --git a/src/resource/resource-disk.c b/src/resource/resource-disk.c index 7c26c9b..02b08eb 100644 --- a/src/resource/resource-disk.c +++ b/src/resource/resource-disk.c @@ -27,6 +27,7 @@ #include <glib.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> diff --git a/src/resource/resource-display.c b/src/resource/resource-display.c index ed0f55e..8c2ccfc 100644 --- a/src/resource/resource-display.c +++ b/src/resource/resource-display.c @@ -26,6 +26,7 @@ #include <unistd.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> #include <util/gdbus-util.h> diff --git a/src/resource/resource-gpu.c b/src/resource/resource-gpu.c index 8e6ac82..f112845 100644 --- a/src/resource/resource-gpu.c +++ b/src/resource/resource-gpu.c @@ -27,6 +27,7 @@ #include <hal/hal-power.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> diff --git a/src/resource/resource-network.c b/src/resource/resource-network.c index 016820a..aabadb4 100644 --- a/src/resource/resource-network.c +++ b/src/resource/resource-network.c @@ -27,6 +27,7 @@ #include <glib.h> #include <util/common.h> +#include <util/devices.h> #include <util/log.h> #include <util/resource.h> diff --git a/src/util/devices.c b/src/util/devices.c index 0ad12dd..565db53 100644 --- a/src/util/devices.c +++ b/src/util/devices.c @@ -24,6 +24,66 @@ #include <util/log.h> static GList *dev_head; +static GList *g_resource_device_head; + +int get_resource_device_count(int resource_type) +{ + GList *node; + struct resource_device *device; + int count = 0; + + for (node = g_resource_device_head; node != NULL; node = node->next) { + device = node->data; + if (device->type == resource_type) + count++; + } + + return count; +} + +const struct resource_device *find_resource_device(int resource_type, + int resource_index) +{ + GList *node; + const struct resource_device *device; + + for (node = g_resource_device_head; node != NULL; node = node->next) { + device = node->data; + if (device->type == resource_type && + device->index == resource_index) + return device; + } + + return NULL; +} + +int add_resource_device(struct resource_device *device) +{ + int count; + + if (!device) + return -EINVAL; + + count = get_resource_device_count(device->type); + if (count < 0) + return count; + + device->index = count; + + g_resource_device_head = + g_list_append(g_resource_device_head, (gpointer)device); + + return 0; +} + +void remove_resource_device(struct resource_device *device) +{ + if (!device) + return; + + g_resource_device_head = + g_list_remove(g_resource_device_head, (gpointer)device); +} void add_device(const struct device_ops *dev) { diff --git a/src/util/resource.c b/src/util/resource.c index 963bb83..75fb89e 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -32,7 +32,6 @@ #define RESOURCE_CTRL_INDEX(id) BIT64_INDEX(id) static GList *g_resource_driver_head; -static GList *g_resource_device_head; static gint __compare_resource_type(gconstpointer data, gconstpointer input) { @@ -44,7 +43,7 @@ static gint __compare_resource_type(gconstpointer data, gconstpointer input) return -1; } -static const struct resource_driver *find_resource_driver(int resource_type) +const struct resource_driver *find_resource_driver(int resource_type) { GList *node; @@ -74,83 +73,6 @@ void remove_resource_driver(const struct resource_driver *driver) g_list_remove(g_resource_driver_head, (gpointer)driver); } -int get_resource_device_count_all(void) -{ - return g_list_length(g_resource_device_head); -} - -int get_resource_device_count(int resource_type) -{ - GList *node; - struct resource_device *device; - const struct resource_driver *driver; - int count = 0; - - for (node = g_resource_device_head; node != NULL; node = node->next) { - device = node->data; - if (device->type == resource_type) - count++; - } - - if (count > 0) - return count; - - driver = find_resource_driver(resource_type); - if (!driver) - return -EINVAL; - - if (driver->flag & RESOURCE_FLAG_COUNT_ONLY_ONE) - return 1; - else if (driver->flag & RESOURCE_FLAG_PROCESS) - return -EINVAL; - - return 0; -} - -const struct resource_device *find_resource_device(int resource_type, - int resource_index) -{ - GList *node; - const struct resource_device *device; - - for (node = g_resource_device_head; node != NULL; node = node->next) { - device = node->data; - if (device->type == resource_type && - device->index == resource_index) - return device; - } - - return NULL; -} - -int add_resource_device(struct resource_device *device) -{ - int count; - - if (!device) - return -EINVAL; - - count = get_resource_device_count(device->type); - if (count < 0) - return count; - - device->index = count; - - g_resource_device_head = - g_list_append(g_resource_device_head, (gpointer)device); - - return 0; -} - -void remove_resource_device(struct resource_device *device) -{ - if (!device) - return; - - g_resource_device_head = - g_list_remove(g_resource_device_head, (gpointer)device); -} - static void do_delete_resource(struct resource *resource) { if (!resource->name) |