[tyndur-devel] [PATCH 1/4] init: devmgr
Kevin Wolf ·
+ init: Systemweit zentrale Verwaltung von Geraeten, damit sich unterschiedliche Treiber koordinieren koennen Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- src/modules/include/init.h | 10 ++++ src/modules/init/devmgr.c | 98 ++++++++++++++++++++++++++++++++++++++++++++ src/modules/init/init.c | 6 +++ src/modules/lib/init.c | 20 +++++++++ 4 files changed, 134 insertions(+), 0 deletions(-) create mode 100644 src/modules/init/devmgr.c diff --git a/src/modules/include/init.h b/src/modules/include/init.h index 325a7b4..aa18fd5 100644 --- a/src/modules/include/init.h +++ b/src/modules/include/init.h @@ -63,5 +63,15 @@ pid_t init_execute(const char* cmd); #endif +struct init_dev_desc { + char name[64]; + int type; + size_t bus_data_size; + uint8_t bus_data[]; +}; + +int init_dev_register(struct init_dev_desc* dev, size_t size); +int init_dev_list(struct init_dev_desc** devs); + #endif diff --git a/src/modules/init/devmgr.c b/src/modules/init/devmgr.c new file mode 100644 index 0000000..42adc92 --- /dev/null +++ b/src/modules/init/devmgr.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include <rpc.h> +#include <init.h> +#include <collections.h> +#include <stdlib.h> +#include <string.h> + +struct device { + struct init_dev_desc* public; +}; + +list_t* devices = NULL; + +void rpc_dev_register(pid_t pid, dword cid, size_t size, void* data) +{ + struct init_dev_desc* desc; + struct device* dev; + + if (size < sizeof(struct init_dev_desc)) { + rpc_send_int_response(pid, cid, -1); + return; + } + + desc = data; + if (size != desc->bus_data_size + sizeof(struct init_dev_desc)) { + rpc_send_int_response(pid, cid, -1); + return; + } + + desc = malloc(size); + memcpy(desc, data, size); + desc->name[sizeof(desc->name) - 1] = '\0'; + + dev = malloc(sizeof(*dev)); + dev->public = desc; + + if (devices == NULL) { + devices = list_create(); + } + + list_push(devices, dev); + rpc_send_int_response(pid, cid, 0); +} + +void rpc_dev_list(pid_t pid, dword cid, size_t size, void* data) +{ + size_t bytes = 0; + int i; + struct device* dev; + + for (i = 0; (dev = list_get_element_at(devices, i)); i++) { + bytes += dev->public->bus_data_size + sizeof(struct init_dev_desc); + } + + uint8_t buf[bytes]; + size_t pos = 0; + + for (i = 0; (dev = list_get_element_at(devices, i)); i++) { + size_t s = dev->public->bus_data_size + sizeof(struct init_dev_desc); + memcpy(&buf[pos], dev->public, s); + pos += s; + } + + rpc_send_response(pid, cid, bytes, (char*) buf); +} diff --git a/src/modules/init/init.c b/src/modules/init/init.c index 475d602..e5fbbdb 100644 --- a/src/modules/init/init.c +++ b/src/modules/init/init.c @@ -75,6 +75,9 @@ void rpc_loadelf(pid_t pid, dword correlation_id, size_t data_size, void* data); void rpc_reopen_stdio(pid_t pid, dword cid, size_t size, void* data); +void rpc_dev_register(pid_t pid, dword cid, size_t size, void* data); +void rpc_dev_list(pid_t pid, dword cid, size_t size, void* data); + void load_modules(init_module_list_t* modules); bool load_single_module(Elf32_Ehdr* elf_header, char* args, pid_t parent_pid); bool start_program(char* path, char* args, pid_t parent_pid); @@ -168,6 +171,9 @@ void _start(dword modules) register_message_handler("UP_STDIO", &rpc_reopen_stdio); + register_message_handler("DEV_REG ", &rpc_dev_register); + register_message_handler("DEV_LIST", &rpc_dev_list); + io_init(); diff --git a/src/modules/lib/init.c b/src/modules/lib/init.c index 3759114..1451e80 100644 --- a/src/modules/lib/init.c +++ b/src/modules/lib/init.c @@ -175,3 +175,23 @@ pid_t init_execute(const char* cmd) return pid; } +int init_dev_register(struct init_dev_desc* dev, size_t size) +{ + return rpc_get_int(1, "DEV_REG ", size, (char*) dev); +} + +int init_dev_list(struct init_dev_desc** devs) +{ + int res; + response_t* response = rpc_get_response(1, "DEV_LIST", 0, NULL); + + if (response == 0) { + return -1; + } + + *devs = response->data; + res = response->data_length; + free(response); + + return res; +} -- 1.6.0.2
Antworten
- [tyndur-devel] [PATCH 1/4] init: devmgr · Antoine Kaufmann