Changeset a1769ee in mainline for uspace/lib/libdrv/include/driver.h
- Timestamp:
- 2010-03-31T20:30:54Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 52b7b1bb
- Parents:
- eff1a590
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/include/driver.h
reff1a590 ra1769ee 1 1 /* 2 * Copyright (c) 2010 Lenka Trochtova 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. 4 4 * … … 38 38 #include <adt/list.h> 39 39 #include <ipc/devman.h> 40 #include <ipc/dev_iface.h> 40 41 41 typedef struct device { 42 struct device; 43 typedef struct device device_t; 44 45 // device interface 46 47 // first two parameters: device and interface structure registered by the devices driver 48 typedef void remote_iface_func_t(device_t*, void *, ipc_callid_t, ipc_call_t *); 49 typedef remote_iface_func_t *remote_iface_func_ptr_t; 50 51 typedef struct { 52 int method_count; 53 remote_iface_func_ptr_t *methods; 54 } remote_iface_t; 55 56 typedef struct { 57 remote_iface_t * ifaces[DEV_IFACE_COUNT]; 58 } iface_dipatch_table_t; 59 60 static inline int get_iface_index(dev_inferface_id_t id) 61 { 62 return id - DEV_IFACE_FIRST; 63 } 64 65 static inline bool is_valid_iface_id(dev_inferface_id_t id) 66 { 67 return DEV_IFACE_FIRST <= id && id < DEV_IFACE_MAX; 68 } 69 70 // device 71 72 struct device { 42 73 device_handle_t handle; 43 ipcarg_t parent_phone; 74 ipcarg_t parent_phone; 44 75 const char *name; 45 76 match_id_list_t match_ids; 46 77 void *driver_data; 47 78 void *interfaces[DEV_IFACE_COUNT]; 79 48 80 // TODO add more items 49 81 50 82 link_t link; 51 } device_t;83 }; 52 84 53 typedef struct driver_ops { 85 86 // driver 87 88 typedef struct driver_ops { 54 89 bool (*add_device)(device_t *dev); 55 90 // TODO add other generic driver operations … … 61 96 } driver_t; 62 97 98 99 100 101 63 102 int driver_main(driver_t *drv); 64 103 … … 68 107 if (NULL != dev) { 69 108 memset(dev, 0, sizeof(device_t)); 70 } 109 } 71 110 list_initialize(&dev->match_ids.ids); 72 111 return dev; 73 112 } 74 113 75 static inline void delete_device(device_t *dev) { 114 static inline void delete_device(device_t *dev) 115 { 76 116 clean_match_ids(&dev->match_ids); 77 117 if (NULL != dev->name) { … … 79 119 } 80 120 free(dev); 121 } 122 123 static inline void device_set_iface (device_t *dev, dev_inferface_id_t id, void *iface) 124 { 125 assert(is_valid_iface_id(id)); 126 127 int idx = get_iface_index(id); 128 dev->interfaces[idx] = iface; 81 129 } 82 130
Note:
See TracChangeset
for help on using the changeset viewer.