source: mainline/uspace/srv/devman/devman.c@ 0358da0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0358da0 was 0358da0, checked in by Lenka Trochtova <trochtova.lenka@…>, 15 years ago

device manager - parts of code

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @defgroup devman Device manager.
31 * @brief HelenOS device manager.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <ipc/services.h>
39#include <ipc/ns.h>
40#include <async.h>
41#include <stdio.h>
42#include <errno.h>
43#include <bool.h>
44#include <fibril_synch.h>
45#include <stdlib.h>
46#include <string.h>
47//#include <ipc/devman.h>
48
49#define NAME "devman"
50
51#define MAX_ID_LEN 256
52
53
54struct driver;
55struct match_id;
56struct match_id_list;
57struct node;
58struct dev_tree;
59
60
61typedef struct driver driver_t;
62typedef struct match_id match_id_t;
63typedef struct match_id_list match_id_list_t;
64typedef struct node node_t;
65typedef struct dev_tree dev_tree_t;
66
67
68
69LIST_INITIALIZE(drivers_list);
70
71/** Represents device tree.
72 */
73struct dev_tree {
74 node_t *root_node;
75}
76
77
78
79/** Ids of device models used for device-to-driver matching.
80 */
81struct match_id {
82 /** Pointers to next and previous ids.
83 */
84 link_t ids;
85 /** Id of device model.
86 */
87 char id[MAX_ID_LEN];
88 /** Relevancy of device-to-driver match.
89 * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
90 * the more suitable is the leaf driver for handling the device.
91 */
92 unsigned int score;
93};
94
95/** List of ids for matching devices to drivers sorted
96 * according to match scores in descending order.
97 */
98struct match_id_list {
99 link_t ids;
100};
101
102/** Representation of device driver.
103 */
104struct driver {
105 /** Pointers to previous and next drivers in a linked list */
106 link_t drivers;
107 /** Specifies whether the driver has been started.*/
108 bool running;
109 /** Phone asociated with this driver */
110 ipcarg_t phone;
111 /** Name of the device driver */
112 char *name;
113 /** Path to the driver's binary */
114 const char *path;
115 /** Fibril mutex for list of devices owned by this driver */
116 fibril_mutex_t devices_mutex;
117 /** List of device ids for device-to-driver matching.*/
118 match_id_list_t match_ids;
119};
120
121/** Representation of a node in the device tree.*/
122struct node {
123 /** The node of the parent device. */
124 node_t *parent;
125 /** Pointers to previous and next child devices in the linked list of parent device's node.*/
126 link_t sibling;
127
128
129 /** List of device ids for device-to-driver matching.*/
130 match_id_list_t match_ids;
131};
132
133/** Initialize device manager internal structures.
134 */
135static bool devman_init()
136{
137 // TODO:
138 // initialize list of available drivers
139
140 return true;
141}
142
143/**
144 *
145 */
146int main(int argc, char *argv[])
147{
148 printf(NAME ": HelenOS Device Manager\n");
149
150 if (!devman_init()) {
151 printf(NAME ": Error while initializing service\n");
152 return -1;
153 }
154
155 /*// Set a handler of incomming connections
156 async_set_client_connection(devman_connection);
157
158 // Register device manager at naming service
159 ipcarg_t phonead;
160 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
161 return -1;
162
163 printf(NAME ": Accepting connections\n");
164 async_manager();*/
165
166 // Never reached
167 return 0;
168}
Note: See TracBrowser for help on using the repository browser.