Changeset 729fa2d6 in mainline
- Timestamp:
- 2010-02-25T14:29:23Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 92413de
- Parents:
- 924c75e1
- Location:
- uspace
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/Makefile
r924c75e1 r729fa2d6 53 53 generic/clipboard.c \ 54 54 generic/devmap.c \ 55 generic/devman.c \ 55 56 generic/event.c \ 56 57 generic/errno.c \ -
uspace/lib/libc/include/ipc/devman.h
r924c75e1 r729fa2d6 36 36 #include <ipc/ipc.h> 37 37 38 #define DEVMAN_NAME_MAXLEN 256 39 38 40 typedef enum { 39 41 DEVMAN_DRIVER = 1, -
uspace/srv/devman/devman.c
r924c75e1 r729fa2d6 348 348 349 349 fibril_mutex_lock(&drivers_list->drivers_mutex); 350 350 351 link_t *link = drivers_list->drivers.next; 351 352 while (link != &drivers_list->drivers) { … … 358 359 link = link->next; 359 360 } 361 360 362 fibril_mutex_unlock(&drivers_list->drivers_mutex); 361 363 … … 404 406 drv->state = DRIVER_STARTING; 405 407 return true; 408 } 409 410 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name) 411 { 412 driver_t *res = NULL; 413 414 fibril_mutex_lock(&drv_list->drivers_mutex); 415 416 driver_t *drv = NULL; 417 link_t *link = drv_list->drivers.next; 418 while (link != &drv_list->drivers) { 419 drv = list_get_instance(link, driver_t, drivers); 420 if (0 == str_cmp(drv->name, drv_name)) { 421 res = drv; 422 break; 423 } 424 link = link->next; 425 } 426 427 fibril_mutex_unlock(&drv_list->drivers_mutex); 428 429 return res; 406 430 } 407 431 -
uspace/srv/devman/devman.h
r924c75e1 r729fa2d6 168 168 } 169 169 170 // Driver list 170 171 172 173 174 // Drivers 171 175 172 176 static inline void init_driver_list(driver_list_t *drv_list) … … 178 182 } 179 183 180 // Drivers181 182 184 driver_t * create_driver(); 183 185 bool get_driver_info(const char *base_path, const char *name, driver_t *drv); … … 191 193 bool add_device(driver_t *drv, node_t *node); 192 194 bool start_driver(driver_t *drv); 195 196 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name); 193 197 194 198 -
uspace/srv/devman/main.c
r924c75e1 r729fa2d6 59 59 static dev_tree_t device_tree; 60 60 61 /** 62 * 63 * 64 * Driver's mutex must be locked. 65 */ 66 static void pass_devices_to_driver(driver_t *driver) 67 { 68 69 70 71 72 } 73 74 static void init_running_driver(driver_t *driver) 75 { 76 fibril_mutex_lock(&driver->driver_mutex); 77 78 // pass devices which have been already assigned to the driver to the driver 79 pass_devices_to_driver(driver); 80 81 // change driver's state to running 82 driver->state = DRIVER_RUNNING; 83 84 fibril_mutex_unlock(&driver->driver_mutex); 85 } 86 87 /** 88 * Register running driver. 89 */ 90 static driver_t * devman_driver_register(void) 91 { 92 printf(NAME ": devman_driver_register \n"); 93 94 ipc_call_t icall; 95 ipc_callid_t iid = async_get_call(&icall); 96 driver_t *driver = NULL; 97 98 if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) { 99 ipc_answer_0(iid, EREFUSED); 100 return NULL; 101 } 102 103 char drv_name[DEVMAN_NAME_MAXLEN]; 104 105 // Get driver name 106 int rc = async_string_receive(drv_name, DEVMAN_NAME_MAXLEN, NULL); 107 if (rc != EOK) { 108 ipc_answer_0(iid, rc); 109 return NULL; 110 } 111 printf(NAME ": the %s driver is trying to register by the service.\n", drv_name); 112 113 // Find driver structure 114 driver = find_driver(&drivers_list, drv_name); 115 if (NULL == driver) { 116 printf(NAME ": no driver named %s was found.\n", drv_name); 117 ipc_answer_0(iid, ENOENT); 118 return NULL; 119 } 120 printf(NAME ": registering the running instance of the %s driver.\n", driver->name); 121 122 // Create connection to the driver 123 printf(NAME ": creating connection to the %s driver.\n", driver->name); 124 ipc_call_t call; 125 ipc_callid_t callid = async_get_call(&call); 126 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 127 ipc_answer_0(callid, ENOTSUP); 128 ipc_answer_0(iid, ENOTSUP); 129 return NULL; 130 } 131 132 fibril_mutex_lock(&driver->driver_mutex); 133 assert(DRIVER_STARTING == driver->state); 134 driver->phone = IPC_GET_ARG5(call); 135 fibril_mutex_unlock(&driver->driver_mutex); 136 137 printf(NAME ": the %s driver was successfully registered as running.\n", driver->name); 138 139 ipc_answer_0(callid, EOK); 140 141 ipc_answer_0(iid, EOK); 142 143 return driver; 144 } 61 145 62 146 /** Function for handling connections to device manager. … … 64 148 */ 65 149 static void devman_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 66 { 150 { 151 /* Accept the connection */ 152 ipc_answer_0(iid, EOK); 153 154 driver_t *driver = devman_driver_register(); 155 if (driver == NULL) 156 return; 157 158 init_running_driver(driver); 159 67 160 ipc_callid_t callid; 68 161 ipc_call_t call; 69 70 /* Accept the connection */ 71 ipc_answer_0(iid, EOK); 72 73 while (1) { 162 bool cont = true; 163 while (cont) { 74 164 callid = async_get_call(&call); 75 165 76 166 switch (IPC_GET_METHOD(call)) { 77 case DEVMAN_DRIVER_REGISTER:78 // TODO register running driver instance - remember driver's phone and lookup devices to which it has been assigned79 break;167 case IPC_M_PHONE_HUNGUP: 168 cont = false; 169 continue; 80 170 case DEVMAN_ADD_CHILD_DEVICE: 81 171 // TODO add new device node to the device tree -
uspace/srv/devman/util.h
r924c75e1 r729fa2d6 57 57 } 58 58 59 static inline void free_not_null( void *ptr)59 static inline void free_not_null(const void *ptr) 60 60 { 61 61 if (NULL != ptr) { -
uspace/srv/drivers/root/Makefile
r924c75e1 r729fa2d6 28 28 USPACE_PREFIX = ../../.. 29 29 LIBS = $(LIBC_PREFIX)/libc.a 30 EXTRA_CFLAGS = -Iinclude31 30 32 OUTPUT = root 31 OUTPUT = root 33 32 34 33 SOURCES = \ 35 root.c \34 root.c 36 35 37 36 include ../../Makefile.common 38 -
uspace/srv/drivers/root/root.c
r924c75e1 r729fa2d6 48 48 #include <ctype.h> 49 49 50 #include <devman.h> 50 51 #include <ipc/devman.h> 51 52 … … 149 150 150 151 151 // TODO put this to library (like in device mapper) 152 static int devman_phone_driver = -1; 153 static int devman_phone_client = -1; 154 155 int devman_get_phone(devman_interface_t iface, unsigned int flags) 156 { 157 switch (iface) { 158 case DEVMAN_DRIVER: 159 if (devman_phone_driver >= 0) 160 return devman_phone_driver; 161 162 if (flags & IPC_FLAG_BLOCKING) 163 devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS, 164 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 165 else 166 devman_phone_driver = ipc_connect_me_to(PHONE_NS, 167 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 168 169 return devman_phone_driver; 170 case DEVMAN_CLIENT: 171 if (devman_phone_client >= 0) 172 return devman_phone_client; 173 174 if (flags & IPC_FLAG_BLOCKING) 175 devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS, 176 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 177 else 178 devman_phone_client = ipc_connect_me_to(PHONE_NS, 179 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 180 181 return devman_phone_client; 182 default: 152 153 int driver_main(driver_t *drv) 154 { 155 // remember driver structure - driver_ops will be called by generic handler for incoming connections 156 driver = drv; 157 158 // register driver by device manager with generic handler for incoming connections 159 printf("%s: sending registration request to devman.\n", driver->name); 160 devman_driver_register(driver->name, driver_connection); 161 162 async_manager(); 163 164 // Never reached 165 return 0; 166 167 } 168 169 //////////////////////////////////////// 170 // ROOT driver 171 //////////////////////////////////////// 172 173 #define NAME "root" 174 175 176 177 bool root_add_device(device_t *dev) 178 { 179 // TODO add root device and register its children 180 return true; 181 } 182 183 static driver_ops_t root_ops = { 184 .add_device = &root_add_device 185 }; 186 187 static driver_t root_driver = { 188 .name = NAME, 189 .driver_ops = &root_ops 190 }; 191 192 bool root_init() 193 { 194 // TODO driver initialization 195 return true; 196 } 197 198 int main(int argc, char *argv[]) 199 { 200 printf(NAME ": HelenOS root device driver\n"); 201 if (!root_init()) { 202 printf(NAME ": Error while initializing driver.\n"); 183 203 return -1; 184 204 } 185 }186 187 /** Register new driver with device manager. */188 int devman_driver_register(const char *name, async_client_conn_t conn)189 {190 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);191 192 if (phone < 0)193 return phone;194 195 async_serialize_start();196 197 ipc_call_t answer;198 aid_t req = async_send_2(phone, DEVMAN_DRIVER_REGISTER, 0, 0, &answer);199 200 ipcarg_t retval = async_data_write_start(phone, name, str_size(name));201 if (retval != EOK) {202 async_wait_for(req, NULL);203 async_serialize_end();204 return -1;205 }206 207 async_set_client_connection(conn);208 209 ipcarg_t callback_phonehash;210 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);211 async_wait_for(req, &retval);212 213 async_serialize_end();214 215 return retval;216 }217 218 int driver_main(driver_t *drv)219 {220 // remember driver structure - driver_ops will be called by generic handler for incoming connections221 driver = drv;222 223 // register driver by device manager with generic handler for incoming connections224 devman_driver_register(driver->name, driver_connection);225 226 async_manager();227 228 // Never reached229 return 0;230 231 }232 233 ////////////////////////////////////////234 // ROOT driver235 ////////////////////////////////////////236 237 #define NAME "root"238 239 static driver_t root_driver;240 241 bool root_add_device(device_t *dev)242 {243 // TODO244 return true;245 }246 247 bool root_init(driver_t *drv, const char *name)248 {249 // TODO initialize driver structure250 251 return true;252 }253 254 int main(int argc, char *argv[])255 {256 printf(NAME ": HelenOS root device driver\n");257 if (!root_init(&root_driver, argv[0])) {258 printf(NAME ": Error while initializing driver\n");259 return -1;260 }261 205 262 206 return driver_main(&root_driver); 263 264 } 207 }
Note:
See TracChangeset
for help on using the changeset viewer.