source: mainline/uspace/lib/libc/generic/devman.c@ 729fa2d6

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

parts of root device driver

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2007 Josef Cejka
3 * Copyright (c) 2009 Jiri Svoboda
4 * Copyright (c) 2010 Lenka Trochtova
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <string.h>
32#include <stdio.h>
33#include <ipc/ipc.h>
34#include <ipc/services.h>
35#include <ipc/devman.h>
36#include <devman.h>
37#include <async.h>
38#include <errno.h>
39#include <malloc.h>
40#include <bool.h>
41
42static int devman_phone_driver = -1;
43static int devman_phone_client = -1;
44
45int devman_get_phone(devman_interface_t iface, unsigned int flags)
46{
47 switch (iface) {
48 case DEVMAN_DRIVER:
49 if (devman_phone_driver >= 0)
50 return devman_phone_driver;
51
52 if (flags & IPC_FLAG_BLOCKING)
53 devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
54 SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
55 else
56 devman_phone_driver = ipc_connect_me_to(PHONE_NS,
57 SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
58
59 return devman_phone_driver;
60 case DEVMAN_CLIENT:
61 if (devman_phone_client >= 0)
62 return devman_phone_client;
63
64 if (flags & IPC_FLAG_BLOCKING)
65 devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
66 SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
67 else
68 devman_phone_client = ipc_connect_me_to(PHONE_NS,
69 SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
70
71 return devman_phone_client;
72 default:
73 return -1;
74 }
75}
76
77/** Register running driver with device manager. */
78int devman_driver_register(const char *name, async_client_conn_t conn)
79{
80 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
81
82 if (phone < 0)
83 return phone;
84
85 async_serialize_start();
86
87 ipc_call_t answer;
88 aid_t req = async_send_2(phone, DEVMAN_DRIVER_REGISTER, 0, 0, &answer);
89
90 printf("devman_driver_register (\"%s\", conn)", name);
91 ipcarg_t retval = async_data_write_start(phone, name, str_size(name));
92 if (retval != EOK) {
93 async_wait_for(req, NULL);
94 async_serialize_end();
95 return -1;
96 }
97
98 async_set_client_connection(conn);
99
100 ipcarg_t callback_phonehash;
101 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
102 async_wait_for(req, &retval);
103
104 async_serialize_end();
105
106 return retval;
107}
108
109void devman_hangup_phone(devman_interface_t iface)
110{
111 switch (iface) {
112 case DEVMAN_DRIVER:
113 if (devman_phone_driver >= 0) {
114 ipc_hangup(devman_phone_driver);
115 devman_phone_driver = -1;
116 }
117 break;
118 case DEVMAN_CLIENT:
119 if (devman_phone_client >= 0) {
120 ipc_hangup(devman_phone_client);
121 devman_phone_client = -1;
122 }
123 break;
124 default:
125 break;
126 }
127}
Note: See TracBrowser for help on using the repository browser.