From: Dongwoo Lee Date: Thu, 13 Oct 2022 03:23:24 +0000 (+0900) Subject: resource: Resolve dependency of HAL devices X-Git-Tag: accepted/tizen/unified/20221206.170546~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F283208%2F5;p=platform%2Fcore%2Fsystem%2Fpass.git 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 --- 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 #include +#include #include #include #include @@ -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 #include +#include #include #include 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 #include +#include #include #include 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 #include +#include #include #include 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 #include +#include #include #include #include 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 #include +#include #include #include 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 #include +#include #include #include 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 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)