Changeset cfe7716 in mainline for uspace/lib/libdrv/include/driver.h
- Timestamp:
- 2010-04-29T14:13:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f8b581
- Parents:
- 953bc1ef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/include/driver.h
r953bc1ef rcfe7716 41 41 #include <device/hw_res.h> 42 42 #include <assert.h> 43 #include <ddi.h> 44 #include <libarch/ddi.h> 45 #include <fibril_synch.h> 46 #include <malloc.h> 43 47 44 48 struct device; … … 159 163 int child_device_register(device_t *child, device_t *parent); 160 164 165 // interrupts 166 167 static irq_cmd_t default_cmds[] = { 168 { 169 .cmd = CMD_ACCEPT 170 } 171 }; 172 173 static irq_code_t default_pseudocode = { 174 sizeof(default_cmds) / sizeof(irq_cmd_t), 175 default_cmds 176 }; 177 178 typedef void interrupt_handler_t(device_t *dev, ipc_callid_t iid, ipc_call_t *icall); 179 180 typedef struct interrupt_context { 181 int id; 182 device_t *dev; 183 int irq; 184 interrupt_handler_t *handler; 185 link_t link; 186 } interrupt_context_t; 187 188 typedef struct interrupt_context_list { 189 int curr_id; 190 link_t contexts; 191 fibril_mutex_t mutex; 192 } interrupt_context_list_t; 193 194 static inline interrupt_context_t * create_interrupt_context() 195 { 196 interrupt_context_t *ctx = (interrupt_context_t *)malloc(sizeof(interrupt_context_t)); 197 if (NULL != ctx) { 198 memset(ctx, 0, sizeof(interrupt_context_t)); 199 } 200 return ctx; 201 } 202 203 static inline void delete_interrupt_context(interrupt_context_t *ctx) 204 { 205 if (NULL != ctx) { 206 free(ctx); 207 } 208 } 209 210 static inline void init_interrupt_context_list(interrupt_context_list_t *list) 211 { 212 memset(list, 0, sizeof(interrupt_context_list_t)); 213 fibril_mutex_initialize(&list->mutex); 214 list_initialize(&list->contexts); 215 } 216 217 static inline void add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 218 { 219 fibril_mutex_lock(&list->mutex); 220 221 ctx->id = list->curr_id++; 222 list_append(&ctx->link, &list->contexts); 223 224 fibril_mutex_unlock(&list->mutex); 225 } 226 227 static inline void remove_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 228 { 229 fibril_mutex_lock(&list->mutex); 230 231 list_remove(&ctx->link); 232 233 fibril_mutex_unlock(&list->mutex); 234 } 235 236 static inline interrupt_context_t *find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 237 { 238 fibril_mutex_lock(&list->mutex); 239 link_t *link = list->contexts.next; 240 interrupt_context_t *ctx; 241 242 while (link != &list->contexts) { 243 ctx = list_get_instance(link, interrupt_context_t, link); 244 if (id == ctx->id) { 245 fibril_mutex_unlock(&list->mutex); 246 return ctx; 247 } 248 link = link->next; 249 } 250 fibril_mutex_unlock(&list->mutex); 251 return NULL; 252 } 253 254 static inline interrupt_context_t *find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 255 { 256 fibril_mutex_lock(&list->mutex); 257 link_t *link = list->contexts.next; 258 interrupt_context_t *ctx; 259 260 while (link != &list->contexts) { 261 ctx = list_get_instance(link, interrupt_context_t, link); 262 if (irq == ctx->irq && dev == ctx->dev) { 263 fibril_mutex_unlock(&list->mutex); 264 return ctx; 265 } 266 link = link->next; 267 } 268 fibril_mutex_unlock(&list->mutex); 269 return NULL; 270 } 161 271 162 272 #endif
Note:
See TracChangeset
for help on using the changeset viewer.