Changeset 5fdd7c3 in mainline
- Timestamp:
- 2011-01-09T20:41:07Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22027b6e
- Parents:
- 97adec8
- Location:
- uspace/lib/drv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/dev_iface.c
r97adec8 r5fdd7c3 63 63 } 64 64 65 bool is_valid_iface_idx(int idx) 66 { 67 return (0 <= idx) && (idx < DEV_IFACE_MAX); 68 } 69 65 70 /** 66 71 * @} -
uspace/lib/drv/generic/driver.c
r97adec8 r5fdd7c3 52 52 #include <ipc/driver.h> 53 53 54 #include "dev_iface.h" 54 55 #include "driver.h" 55 56 … … 85 86 (*ctx->handler)(ctx->dev, iid, icall); 86 87 } 88 89 interrupt_context_t *create_interrupt_context(void) 90 { 91 interrupt_context_t *ctx; 92 93 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t)); 94 if (ctx != NULL) 95 memset(ctx, 0, sizeof(interrupt_context_t)); 96 97 return ctx; 98 } 99 100 void delete_interrupt_context(interrupt_context_t *ctx) 101 { 102 if (ctx != NULL) 103 free(ctx); 104 } 105 106 void init_interrupt_context_list(interrupt_context_list_t *list) 107 { 108 memset(list, 0, sizeof(interrupt_context_list_t)); 109 fibril_mutex_initialize(&list->mutex); 110 list_initialize(&list->contexts); 111 } 112 113 void 114 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 115 { 116 fibril_mutex_lock(&list->mutex); 117 ctx->id = list->curr_id++; 118 list_append(&ctx->link, &list->contexts); 119 fibril_mutex_unlock(&list->mutex); 120 } 121 122 void remove_interrupt_context(interrupt_context_list_t *list, 123 interrupt_context_t *ctx) 124 { 125 fibril_mutex_lock(&list->mutex); 126 list_remove(&ctx->link); 127 fibril_mutex_unlock(&list->mutex); 128 } 129 130 interrupt_context_t * 131 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 132 { 133 fibril_mutex_lock(&list->mutex); 134 135 link_t *link = list->contexts.next; 136 interrupt_context_t *ctx; 137 138 while (link != &list->contexts) { 139 ctx = list_get_instance(link, interrupt_context_t, link); 140 if (ctx->id == id) { 141 fibril_mutex_unlock(&list->mutex); 142 return ctx; 143 } 144 link = link->next; 145 } 146 147 fibril_mutex_unlock(&list->mutex); 148 return NULL; 149 } 150 151 interrupt_context_t * 152 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 153 { 154 fibril_mutex_lock(&list->mutex); 155 156 link_t *link = list->contexts.next; 157 interrupt_context_t *ctx; 158 159 while (link != &list->contexts) { 160 ctx = list_get_instance(link, interrupt_context_t, link); 161 if (ctx->irq == irq && ctx->dev == dev) { 162 fibril_mutex_unlock(&list->mutex); 163 return ctx; 164 } 165 link = link->next; 166 } 167 168 fibril_mutex_unlock(&list->mutex); 169 return NULL; 170 } 171 87 172 88 173 int … … 365 450 } 366 451 452 /** Create new device structure. 453 * 454 * @return The device structure. 455 */ 456 device_t *create_device(void) 457 { 458 device_t *dev = malloc(sizeof(device_t)); 459 460 if (dev != NULL) { 461 memset(dev, 0, sizeof(device_t)); 462 init_match_ids(&dev->match_ids); 463 } 464 465 return dev; 466 } 467 468 /** Delete device structure. 469 * 470 * @param dev The device structure. 471 */ 472 void delete_device(device_t *dev) 473 { 474 clean_match_ids(&dev->match_ids); 475 if (dev->name != NULL) 476 free(dev->name); 477 free(dev); 478 } 479 480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx) 481 { 482 assert(is_valid_iface_idx(idx)); 483 if (dev->ops == NULL) 484 return NULL; 485 return dev->ops->interfaces[idx]; 486 } 487 367 488 int child_device_register(device_t *child, device_t *parent) 368 489 { … … 435 556 } 436 557 558 /** Get default handler for client requests */ 559 remote_handler_t *device_get_default_handler(device_t *dev) 560 { 561 if (dev->ops == NULL) 562 return NULL; 563 return dev->ops->default_handler; 564 } 565 566 int add_device_to_class(device_t *dev, const char *class_name) 567 { 568 return devman_add_device_to_class(dev->handle, class_name); 569 } 570 437 571 int driver_main(driver_t *drv) 438 572 { -
uspace/lib/drv/include/dev_iface.h
r97adec8 r5fdd7c3 40 40 /* TODO declare device interface structures here */ 41 41 42 extern bool is_valid_iface_idx(int); 43 44 42 45 #endif 43 46 -
uspace/lib/drv/include/driver.h
r97adec8 r5fdd7c3 72 72 } iface_dipatch_table_t; 73 73 74 75 static inline bool is_valid_iface_idx(int idx) 76 { 77 return (0 <= idx) && (idx < DEV_IFACE_MAX); 78 } 79 80 remote_iface_t *get_remote_iface(int); 81 remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t); 82 74 extern remote_iface_t *get_remote_iface(int); 75 extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t); 83 76 84 77 /* … … 171 164 * @return The device structure. 172 165 */ 173 static inline device_t *create_device(void) 174 { 175 device_t *dev = malloc(sizeof(device_t)); 176 177 if (dev != NULL) { 178 memset(dev, 0, sizeof(device_t)); 179 init_match_ids(&dev->match_ids); 180 } 181 182 return dev; 183 } 184 185 /** Delete device structure. 186 * 187 * @param dev The device structure. 188 */ 189 static inline void delete_device(device_t *dev) 190 { 191 clean_match_ids(&dev->match_ids); 192 if (dev->name != NULL) 193 free(dev->name); 194 free(dev); 195 } 196 197 static inline void *device_get_ops(device_t *dev, dev_inferface_idx_t idx) 198 { 199 assert(is_valid_iface_idx(idx)); 200 if (dev->ops == NULL) 201 return NULL; 202 return dev->ops->interfaces[idx]; 203 } 204 205 int child_device_register(device_t *, device_t *); 206 int child_device_register_wrapper(device_t *, const char *, const char *, int); 166 extern device_t *create_device(void); 167 extern void delete_device(device_t *); 168 extern void *device_get_ops(device_t *, dev_inferface_idx_t); 169 170 extern int child_device_register(device_t *, device_t *); 171 extern int child_device_register_wrapper(device_t *, const char *, const char *, 172 int); 207 173 208 174 /* … … 226 192 } interrupt_context_list_t; 227 193 228 static inline interrupt_context_t *create_interrupt_context(void) 229 { 230 interrupt_context_t *ctx; 231 232 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t)); 233 if (ctx != NULL) 234 memset(ctx, 0, sizeof(interrupt_context_t)); 235 236 return ctx; 237 } 238 239 static inline void delete_interrupt_context(interrupt_context_t *ctx) 240 { 241 if (ctx != NULL) 242 free(ctx); 243 } 244 245 static inline void init_interrupt_context_list(interrupt_context_list_t *list) 246 { 247 memset(list, 0, sizeof(interrupt_context_list_t)); 248 fibril_mutex_initialize(&list->mutex); 249 list_initialize(&list->contexts); 250 } 251 252 static inline void 253 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 254 { 255 fibril_mutex_lock(&list->mutex); 256 ctx->id = list->curr_id++; 257 list_append(&ctx->link, &list->contexts); 258 fibril_mutex_unlock(&list->mutex); 259 } 260 261 static inline void 262 remove_interrupt_context(interrupt_context_list_t *list, 263 interrupt_context_t *ctx) 264 { 265 fibril_mutex_lock(&list->mutex); 266 list_remove(&ctx->link); 267 fibril_mutex_unlock(&list->mutex); 268 } 269 270 static inline interrupt_context_t * 271 find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 272 { 273 fibril_mutex_lock(&list->mutex); 274 275 link_t *link = list->contexts.next; 276 interrupt_context_t *ctx; 277 278 while (link != &list->contexts) { 279 ctx = list_get_instance(link, interrupt_context_t, link); 280 if (ctx->id == id) { 281 fibril_mutex_unlock(&list->mutex); 282 return ctx; 283 } 284 link = link->next; 285 } 286 287 fibril_mutex_unlock(&list->mutex); 288 return NULL; 289 } 290 291 static inline interrupt_context_t * 292 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 293 { 294 fibril_mutex_lock(&list->mutex); 295 296 link_t *link = list->contexts.next; 297 interrupt_context_t *ctx; 298 299 while (link != &list->contexts) { 300 ctx = list_get_instance(link, interrupt_context_t, link); 301 if (ctx->irq == irq && ctx->dev == dev) { 302 fibril_mutex_unlock(&list->mutex); 303 return ctx; 304 } 305 link = link->next; 306 } 307 308 fibril_mutex_unlock(&list->mutex); 309 return NULL; 310 } 311 312 int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 194 extern interrupt_context_t *create_interrupt_context(void); 195 extern void delete_interrupt_context(interrupt_context_t *); 196 extern void init_interrupt_context_list(interrupt_context_list_t *); 197 extern void add_interrupt_context(interrupt_context_list_t *, 198 interrupt_context_t *); 199 extern void remove_interrupt_context(interrupt_context_list_t *, 200 interrupt_context_t *); 201 extern interrupt_context_t *find_interrupt_context_by_id( 202 interrupt_context_list_t *, int); 203 extern interrupt_context_t *find_interrupt_context( 204 interrupt_context_list_t *, device_t *, int); 205 206 extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *, 313 207 irq_code_t *); 314 int unregister_interrupt_handler(device_t *, int); 315 316 317 /** Get default handler for client requests */ 318 static inline remote_handler_t *device_get_default_handler(device_t *dev) 319 { 320 if (dev->ops == NULL) 321 return NULL; 322 return dev->ops->default_handler; 323 } 324 325 static inline int add_device_to_class(device_t *dev, const char *class_name) 326 { 327 return devman_add_device_to_class(dev->handle, class_name); 328 } 208 extern int unregister_interrupt_handler(device_t *, int); 209 210 extern remote_handler_t *device_get_default_handler(device_t *); 211 extern int add_device_to_class(device_t *, const char *); 329 212 330 213 #endif
Note:
See TracChangeset
for help on using the changeset viewer.