Changeset 3843ecb in mainline for uspace/lib
- Timestamp:
- 2010-04-09T13:54:06Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 892e4e1
- Parents:
- 3a5909f
- Location:
- uspace/lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/device/hw_res.c
r3a5909f r3843ecb 37 37 #include <async.h> 38 38 #include <malloc.h> 39 40 39 41 40 bool get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources) 42 41 { 43 42 ipcarg_t count = 0; 44 int rc = async_req_1_1(dev_phone, HW_RES_DEV_IFACE, GET_RESOURCE_LIST, &count);43 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), GET_RESOURCE_LIST, &count); 45 44 hw_resources->count = count; 46 45 if (EOK != rc) { … … 66 65 bool enable_interrupt(int dev_phone) 67 66 { 68 int rc = async_req_1_0(dev_phone, HW_RES_DEV_IFACE, ENABLE_INTERRUPT);67 int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), ENABLE_INTERRUPT); 69 68 return rc == EOK; 70 69 } -
uspace/lib/libc/include/device/hw_res.h
r3a5909f r3843ecb 39 39 #include <bool.h> 40 40 41 /** HW resource (e.g. interrupt, memory register, i/o register etc.). */ 42 typedef struct hw_resource { 43 hw_res_type_t type; 44 union { 45 struct { 46 uint64_t address; 47 endianness_t endianness; 48 size_t size; 49 } mem_range; 50 struct { 51 uint64_t address; 52 endianness_t endianness; 53 size_t size; 54 } io_range; 55 struct { 56 int irq; 57 } interrupt; 58 } res; 59 } hw_resource_t; 60 61 typedef struct hw_resource_list { 62 size_t count; 63 hw_resource_t *resources; 64 } hw_resource_list_t; 65 66 static inline void clean_hw_resource_list(hw_resource_list_t *hw_res) 67 { 68 if(NULL != hw_res->resources) { 69 free(hw_res->resources); 70 hw_res->resources = NULL; 71 } 72 hw_res->count = 0; 73 } 74 41 75 42 76 bool get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources); -
uspace/lib/libc/include/ipc/dev_iface.h
r3a5909f r3843ecb 35 35 #include <libarch/types.h> 36 36 37 #define DEV_IFACE_FIRST IPC_FIRST_USER_METHOD38 39 37 typedef enum { 40 HW_RES_DEV_IFACE = DEV_IFACE_FIRST,38 HW_RES_DEV_IFACE = 0, 41 39 // TODO add more interfaces 42 40 DEV_IFACE_MAX 43 } dev_inferface_id _t;41 } dev_inferface_idx_t; 44 42 43 #define DEV_IFACE_ID(idx) ((idx) + IPC_FIRST_USER_METHOD) 44 #define DEV_IFACE_IDX(id) ((id) - IPC_FIRST_USER_METHOD) 45 45 46 #define DEV_IFACE_COUNT (DEV_IFACE_MAX - DEV_IFACE_FIRST)46 #define DEV_IFACE_COUNT DEV_IFACE_MAX 47 47 48 49 // data types related to some interface - TODO move this to separate header files50 48 51 49 … … 69 67 } endianness_t; 70 68 71 /** HW resource (e.g. interrupt, memory register, i/o register etc.). */72 typedef struct hw_resource {73 hw_res_type_t type;74 union {75 struct {76 uint64_t address;77 endianness_t endianness;78 size_t size;79 } mem_range;80 struct {81 uint64_t address;82 endianness_t endianness;83 size_t size;84 } io_range;85 struct {86 int irq;87 } interrupt;88 } res;89 } hw_resource_t;90 91 typedef struct hw_resource_list {92 size_t count;93 hw_resource_t *resources;94 } hw_resource_list_t;95 96 static inline void clean_hw_resource_list(hw_resource_list_t *hw_res)97 {98 if(NULL != hw_res->resources) {99 free(hw_res->resources);100 hw_res->resources = NULL;101 }102 hw_res->count = 0;103 }104 105 69 #endif -
uspace/lib/libdrv/generic/dev_iface.c
r3a5909f r3843ecb 45 45 }; 46 46 47 remote_iface_t* get_remote_iface(dev_inferface_id_t id) 48 { 49 assert(is_valid_iface_id(id)); 50 51 int idx = get_iface_index(id); 47 remote_iface_t* get_remote_iface(int idx) 48 { 49 assert(is_valid_iface_idx(idx)); 52 50 return remote_ifaces.ifaces[idx]; 53 51 } -
uspace/lib/libdrv/generic/driver.c
r3a5909f r3843ecb 177 177 callid = async_get_call(&call); 178 178 ipcarg_t method = IPC_GET_METHOD(call); 179 int iface_idx; 180 179 181 switch (method) { 180 182 case IPC_M_PHONE_HUNGUP: … … 184 186 ipc_answer_0(callid, EOK); 185 187 return; 186 default: 187 188 if (!is_valid_iface_id(method)) { 188 default: 189 // convert ipc interface id to interface index 190 191 iface_idx = DEV_IFACE_IDX(method); 192 193 if (!is_valid_iface_idx(iface_idx)) { 189 194 // this is not device's interface 190 195 printf("%s: driver_connection_gen error - invalid interface id %x.", driver->name, method); … … 196 201 197 202 // get the device interface structure 198 void *iface = device_get_iface(dev, method);203 void *iface = device_get_iface(dev, iface_idx); 199 204 if (NULL == iface) { 200 205 printf("%s: driver_connection_gen error - ", driver->name); … … 205 210 206 211 // get the corresponding interface for remote request handling ("remote interface") 207 remote_iface_t* rem_iface = get_remote_iface( method);212 remote_iface_t* rem_iface = get_remote_iface(iface_idx); 208 213 assert(NULL != rem_iface); 209 214 -
uspace/lib/libdrv/include/driver.h
r3a5909f r3843ecb 39 39 #include <ipc/devman.h> 40 40 #include <ipc/dev_iface.h> 41 #include <device/hw_res.h> 41 42 #include <assert.h> 42 43 … … 59 60 } iface_dipatch_table_t; 60 61 61 static inline int get_iface_index(dev_inferface_id_t id) 62 63 static inline bool is_valid_iface_idx(int idx) 62 64 { 63 return id - DEV_IFACE_FIRST;65 return 0 <= idx && idx < DEV_IFACE_MAX; 64 66 } 65 67 66 static inline bool is_valid_iface_id(dev_inferface_id_t id) 67 { 68 return DEV_IFACE_FIRST <= id && id < DEV_IFACE_MAX; 69 } 68 remote_iface_t* get_remote_iface(int idx); 69 remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx); 70 70 71 remote_iface_t* get_remote_iface(dev_inferface_id_t id); 72 remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx); 71 72 // device class 73 74 /** Devices belonging to the same class should implement the same set of interfaces.*/ 75 typedef struct device_class { 76 /** Unique identification of the class. */ 77 int id; 78 /** The table of interfaces implemented by the device. */ 79 void *interfaces[DEV_IFACE_COUNT]; 80 } device_class_t; 73 81 74 82 … … 89 97 /** The device driver's data associated with this device.*/ 90 98 void *driver_data; 91 /** The table of interfaces exported by this device.*/92 void *interfaces[DEV_IFACE_COUNT];99 /** Device class consist of class id and table of interfaces supported by the device.*/ 100 device_class_t *class; 93 101 /** Pointer to the previous and next device in the list of devices handled by the driver */ 94 102 link_t link; … … 146 154 } 147 155 148 static inline void device_set_iface (device_t *dev, dev_inferface_id_t id, void *iface)156 static inline void * device_get_iface(device_t *dev, dev_inferface_idx_t idx) 149 157 { 150 assert(is_valid_iface_id (id));158 assert(is_valid_iface_idx(idx)); 151 159 152 int idx = get_iface_index(id); 153 dev->interfaces[idx] = iface; 154 } 155 156 static inline void * device_get_iface(device_t *dev, dev_inferface_id_t id) 157 { 158 assert(is_valid_iface_id(id)); 159 160 int idx = get_iface_index(id); 161 return dev->interfaces[idx]; 160 return dev->class->interfaces[idx]; 162 161 } 163 162
Note:
See TracChangeset
for help on using the changeset viewer.