Changeset 9a66bc2 in mainline for uspace/lib/libdrv/generic/driver.c
- Timestamp:
- 2010-04-04T21:52:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c06905
- Parents:
- 5cd136ab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/generic/driver.c
r5cd136ab r9a66bc2 57 57 static driver_t *driver; 58 58 LIST_INITIALIZE(devices); 59 FIBRIL_MUTEX_INITIALIZE(devices_mutex); 59 60 60 61 static device_t * driver_create_device() … … 67 68 } 68 69 70 static void add_to_devices_list(device_t *dev) 71 { 72 fibril_mutex_lock(&devices_mutex); 73 list_append(&dev->link, &devices); 74 fibril_mutex_unlock(&devices_mutex); 75 } 76 77 static void remove_from_devices_list(device_t *dev) 78 { 79 fibril_mutex_lock(&devices_mutex); 80 list_append(&dev->link, &devices); 81 fibril_mutex_unlock(&devices_mutex); 82 } 83 69 84 static device_t * driver_get_device(link_t *devices, device_handle_t handle) 70 85 { 71 86 device_t *dev = NULL; 87 88 fibril_mutex_lock(&devices_mutex); 72 89 link_t *link = devices->next; 73 74 90 while (link != devices) { 75 91 dev = list_get_instance(link, device_t, link); 76 92 if (handle == dev->handle) { 93 fibril_mutex_unlock(&devices_mutex); 77 94 return dev; 78 95 } 79 } 96 link = link->next; 97 } 98 fibril_mutex_unlock(&devices_mutex); 80 99 81 100 return NULL; … … 86 105 printf("%s: driver_add_device\n", driver->name); 87 106 88 // result of the operation - device was added, device is not present etc. 89 ipcarg_t ret = 0; 107 // TODO device state - the driver may detect the device is not actually present 108 // (old non PnP devices) or is not working properly. 109 // We should send such information to device manager. 110 111 ipcarg_t ret; 90 112 device_handle_t dev_handle = IPC_GET_ARG1(*icall); 91 113 device_t *dev = driver_create_device(); 92 114 dev->handle = dev_handle; 93 if (driver->driver_ops->add_device(dev)) { 94 list_append(&dev->link, &devices); 95 // TODO set return value 96 } 97 printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle); 98 115 add_to_devices_list(dev); 116 if (driver->driver_ops->add_device(dev)) { 117 printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle); 118 ret = 1; 119 } else { 120 printf("%s: failed to add a new device with handle = %x.\n", driver->name, dev_handle); 121 remove_from_devices_list(dev); 122 // TODO delete device 123 ret = 0; 124 } 99 125 ipc_answer_1(iid, EOK, ret); 100 126 } … … 129 155 * Generic client connection handler both for applications and drivers. 130 156 * 131 * @param dr ivertrue for driver client, false for other clients (applications, services etc.).132 */ 133 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool dr iver)157 * @param drv true for driver client, false for other clients (applications, services etc.). 158 */ 159 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv) 134 160 { 135 161 // Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of the device to which the client connected. 136 device_handle_t handle = IPC_GET_ARG 1(*icall);162 device_handle_t handle = IPC_GET_ARG2(*icall); 137 163 device_t *dev = driver_get_device(&devices, handle); 138 164 139 165 if (dev == NULL) { 166 printf("%s: driver_connection_gen error - no device with handle %x was found.\n", driver->name, handle); 140 167 ipc_answer_0(iid, ENOENT); 141 168 return; … … 147 174 // TODO open the device (introduce some callbacks for opening and closing devices registered by the driver) 148 175 149 ipc_answer_0(iid, EOK); 176 printf("%s: driver_connection_gen: accepting connection.\n", driver->name); 177 ipc_answer_0(iid, EOK); 150 178 151 179 while (1) { … … 153 181 ipc_call_t call; 154 182 183 printf("%s: driver_connection_gen: waiting for call.\n", driver->name); 155 184 callid = async_get_call(&call); 156 185 ipcarg_t method = IPC_GET_METHOD(call); … … 166 195 if (!is_valid_iface_id(method)) { 167 196 // this is not device's interface 197 printf("%s: driver_connection_gen error - invalid interface id %x.", driver->name, method); 168 198 ipc_answer_0(callid, ENOTSUP); 169 199 break; … … 175 205 void *iface = device_get_iface(dev, method); 176 206 if (NULL == iface) { 207 printf("%s: driver_connection_gen error - ", driver->name); 208 printf("device with handle %x has no interface with id %x.\n", handle, method); 177 209 ipc_answer_0(callid, ENOTSUP); 178 210 break; … … 188 220 if (NULL == iface_method_ptr) { 189 221 // the interface has not such method 222 printf("%s: driver_connection_gen error - invalid interface method.", driver->name); 190 223 ipc_answer_0(callid, ENOTSUP); 191 224 break; … … 203 236 static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 204 237 { 238 printf("%s: driver_connection_driver\n", driver->name); 205 239 driver_connection_gen(iid, icall, true); 206 240 } … … 208 242 static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall) 209 243 { 244 printf("%s: driver_connection_client\n", driver->name); 210 245 driver_connection_gen(iid, icall, false); 211 246 } … … 244 279 assert(NULL != child->name); 245 280 281 add_to_devices_list(child); 246 282 if (EOK == devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) { 247 283 return true; 248 284 } 285 remove_from_devices_list(child); 249 286 return false; 250 287 }
Note:
See TracChangeset
for help on using the changeset viewer.