Changeset 8e7c9fe in mainline for uspace/lib/drv
- Timestamp:
- 2014-09-12T03:45:25Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c53b58e
- Parents:
- 3eb0c85 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/drv
- Files:
-
- 10 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/Makefile
r3eb0c85 r8e7c9fe 47 47 generic/remote_pio_window.c \ 48 48 generic/remote_char_dev.c \ 49 generic/remote_graph_dev.c \50 49 generic/remote_nic.c \ 51 50 generic/remote_usb.c \ … … 54 53 generic/remote_usbhid.c \ 55 54 generic/remote_clock_dev.c \ 55 generic/remote_led_dev.c \ 56 56 generic/remote_battery_dev.c \ 57 57 generic/remote_ahci.c -
uspace/lib/drv/generic/dev_iface.c
r3eb0c85 r8e7c9fe 43 43 #include "remote_char_dev.h" 44 44 #include "remote_clock_dev.h" 45 #include "remote_led_dev.h" 45 46 #include "remote_battery_dev.h" 46 #include "remote_graph_dev.h"47 47 #include "remote_nic.h" 48 48 #include "remote_usb.h" … … 61 61 [PIO_WINDOW_DEV_IFACE] = &remote_pio_window_iface, 62 62 [CHAR_DEV_IFACE] = &remote_char_dev_iface, 63 [GRAPH_DEV_IFACE] = &remote_graph_dev_iface,64 63 [NIC_DEV_IFACE] = &remote_nic_iface, 65 64 [PCI_DEV_IFACE] = &remote_pci_iface, … … 68 67 [USBHID_DEV_IFACE] = &remote_usbhid_iface, 69 68 [CLOCK_DEV_IFACE] = &remote_clock_dev_iface, 69 [LED_DEV_IFACE] = &remote_led_dev_iface, 70 70 [BATTERY_DEV_IFACE] = &remote_battery_dev_iface, 71 71 [AHCI_DEV_IFACE] = &remote_ahci_iface, -
uspace/lib/drv/generic/driver.c
r3eb0c85 r8e7c9fe 36 36 /** @file 37 37 */ 38 39 #define _DDF_DATA_IMPLANT40 38 41 39 #include <assert.h> … … 596 594 } 597 595 598 /** Implant foreign driver-specific device data.599 *600 * XXX This is used to transition USB to new interface. Do not use601 * in new code. Use of this function must be removed.602 */603 void ddf_fun_data_implant(ddf_fun_t *fun, void *data)604 {605 assert(fun->driver_data == NULL);606 fun->driver_data = data;607 }608 609 596 /** Return driver-specific device data. */ 610 597 void *ddf_dev_data_get(ddf_dev_t *dev) … … 964 951 */ 965 952 driver = drv; 966 967 /* Initialize interrupt module */968 interrupt_init();969 953 970 954 /* -
uspace/lib/drv/generic/interrupt.c
r3eb0c85 r8e7c9fe 44 44 #include "private/driver.h" 45 45 46 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall);47 static interrupt_context_t *create_interrupt_context(void);48 static void delete_interrupt_context(interrupt_context_t *ctx);49 static void init_interrupt_context_list(interrupt_context_list_t *list);50 static void add_interrupt_context(interrupt_context_list_t *list,51 interrupt_context_t *ctx);52 static void remove_interrupt_context(interrupt_context_list_t *list,53 interrupt_context_t *ctx);54 static interrupt_context_t *find_interrupt_context_by_id(55 interrupt_context_list_t *list, int id);56 static interrupt_context_t *find_interrupt_context(57 interrupt_context_list_t *list, ddf_dev_t *dev, int irq);58 59 /** Interrupts */60 static interrupt_context_list_t interrupt_contexts;61 62 46 static irq_cmd_t default_cmds[] = { 63 47 { … … 73 57 }; 74 58 75 void interrupt_init(void)76 {77 /* Initialize the list of interrupt contexts. */78 init_interrupt_context_list(&interrupt_contexts);79 80 /* Set generic interrupt handler. */81 async_set_interrupt_received(driver_irq_handler);82 }83 84 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)85 {86 int id = (int)IPC_GET_IMETHOD(*icall);87 interrupt_context_t *ctx;88 89 ctx = find_interrupt_context_by_id(&interrupt_contexts, id);90 if (ctx != NULL && ctx->handler != NULL)91 (*ctx->handler)(ctx->dev, iid, icall);92 }93 94 static interrupt_context_t *create_interrupt_context(void)95 {96 interrupt_context_t *ctx;97 98 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));99 if (ctx != NULL)100 memset(ctx, 0, sizeof(interrupt_context_t));101 102 return ctx;103 }104 105 static void delete_interrupt_context(interrupt_context_t *ctx)106 {107 if (ctx != NULL)108 free(ctx);109 }110 111 static void init_interrupt_context_list(interrupt_context_list_t *list)112 {113 memset(list, 0, sizeof(interrupt_context_list_t));114 fibril_mutex_initialize(&list->mutex);115 list_initialize(&list->contexts);116 }117 118 static void add_interrupt_context(interrupt_context_list_t *list,119 interrupt_context_t *ctx)120 {121 fibril_mutex_lock(&list->mutex);122 ctx->id = list->curr_id++;123 list_append(&ctx->link, &list->contexts);124 fibril_mutex_unlock(&list->mutex);125 }126 127 static void remove_interrupt_context(interrupt_context_list_t *list,128 interrupt_context_t *ctx)129 {130 fibril_mutex_lock(&list->mutex);131 list_remove(&ctx->link);132 fibril_mutex_unlock(&list->mutex);133 }134 135 static interrupt_context_t *find_interrupt_context_by_id(136 interrupt_context_list_t *list, int id)137 {138 fibril_mutex_lock(&list->mutex);139 140 list_foreach(list->contexts, link, interrupt_context_t, ctx) {141 if (ctx->id == id) {142 fibril_mutex_unlock(&list->mutex);143 return ctx;144 }145 }146 147 fibril_mutex_unlock(&list->mutex);148 return NULL;149 }150 151 static interrupt_context_t *find_interrupt_context(152 interrupt_context_list_t *list, ddf_dev_t *dev, int irq)153 {154 fibril_mutex_lock(&list->mutex);155 156 list_foreach(list->contexts, link, interrupt_context_t, ctx) {157 if (ctx->irq == irq && ctx->dev == dev) {158 fibril_mutex_unlock(&list->mutex);159 return ctx;160 }161 }162 163 fibril_mutex_unlock(&list->mutex);164 return NULL;165 }166 167 168 59 int register_interrupt_handler(ddf_dev_t *dev, int irq, 169 60 interrupt_handler_t *handler, const irq_code_t *pseudocode) 170 61 { 171 interrupt_context_t *ctx = create_interrupt_context(); 172 173 ctx->dev = dev; 174 ctx->irq = irq; 175 ctx->handler = handler; 176 177 add_interrupt_context(&interrupt_contexts, ctx); 178 179 if (pseudocode == NULL) 180 pseudocode = &default_pseudocode; 181 182 int res = irq_register(irq, dev->handle, ctx->id, pseudocode); 183 if (res != EOK) { 184 remove_interrupt_context(&interrupt_contexts, ctx); 185 delete_interrupt_context(ctx); 186 } 187 188 return res; 62 return async_irq_subscribe(irq, dev->handle, 63 (async_notification_handler_t) handler, dev, pseudocode); 189 64 } 190 65 191 66 int unregister_interrupt_handler(ddf_dev_t *dev, int irq) 192 67 { 193 interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts, 194 dev, irq); 195 int res = irq_unregister(irq, dev->handle); 196 197 if (ctx != NULL) { 198 remove_interrupt_context(&interrupt_contexts, ctx); 199 delete_interrupt_context(ctx); 200 } 201 202 return res; 68 return async_irq_unsubscribe(irq, dev->handle); 203 69 } 204 70 -
uspace/lib/drv/generic/private/remote_led_dev.h
r3eb0c85 r8e7c9fe 1 1 /* 2 * Copyright (c) 201 1 Petr Koupy2 * Copyright (c) 2014 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef LIBDRV_REMOTE_ GRAPH_DEV_H_36 #define LIBDRV_REMOTE_ GRAPH_DEV_H_35 #ifndef LIBDRV_REMOTE_LED_DEV_H_ 36 #define LIBDRV_REMOTE_LED_DEV_H_ 37 37 38 extern remote_iface_t remote_ graph_dev_iface;38 extern remote_iface_t remote_led_dev_iface; 39 39 40 40 #endif … … 43 43 * @} 44 44 */ 45 -
uspace/lib/drv/generic/remote_audio_pcm.c
r3eb0c85 r8e7c9fe 38 38 #include <macros.h> 39 39 #include <str.h> 40 #include < sys/mman.h>40 #include <as.h> 41 41 42 42 #include "audio_pcm_iface.h" -
uspace/lib/drv/generic/remote_led_dev.c
r3eb0c85 r8e7c9fe 1 1 /* 2 * Copyright (c) 201 1 Petr Koupy2 * Copyright (c) 2014 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #include <async.h> 35 36 #include <errno.h> 36 #include < async.h>37 #include <io/pixel.h> 37 38 #include <macros.h> 39 #include <device/led_dev.h> 40 #include <ops/led_dev.h> 41 #include <ddf/driver.h> 38 42 39 #include "ops/graph_dev.h" 40 #include "graph_iface.h" 41 #include "ddf/driver.h" 43 static void remote_led_color_set(ddf_fun_t *, void *, ipc_callid_t, 44 ipc_call_t *); 42 45 43 typedef enum { 44 GRAPH_DEV_CONNECT = 0 45 } graph_dev_method_t; 46 47 int graph_dev_connect(async_sess_t *sess) 48 { 49 async_exch_t *exch = async_exchange_begin(sess); 50 int ret = async_req_1_0(exch, DEV_IFACE_ID(GRAPH_DEV_IFACE), GRAPH_DEV_CONNECT); 51 async_exchange_end(exch); 52 53 return ret; 54 } 55 56 static void remote_graph_connect(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 57 58 static const remote_iface_func_ptr_t remote_graph_dev_iface_ops[] = { 59 [GRAPH_DEV_CONNECT] = remote_graph_connect 46 /** Remote LED interface operations */ 47 static const remote_iface_func_ptr_t remote_led_dev_iface_ops[] = { 48 [LED_DEV_COLOR_SET] = remote_led_color_set 60 49 }; 61 50 62 const remote_iface_t remote_graph_dev_iface = { 63 .method_count = ARRAY_SIZE(remote_graph_dev_iface_ops), 64 .methods = remote_graph_dev_iface_ops 51 /** Remote LED interface structure 52 * 53 * Interface for processing requests from remote clients 54 * addressed by the LED interface. 55 * 56 */ 57 const remote_iface_t remote_led_dev_iface = { 58 .method_count = ARRAY_SIZE(remote_led_dev_iface_ops), 59 .methods = remote_led_dev_iface_ops 65 60 }; 66 61 67 static void remote_graph_connect(ddf_fun_t *fun, void *ops, ipc_callid_t callid, 62 /** Process the color_set() request from the remote client 63 * 64 * @param fun The function to which the data are written 65 * @param ops The local ops structure 66 * 67 */ 68 static void remote_led_color_set(ddf_fun_t *fun, void *ops, ipc_callid_t callid, 68 69 ipc_call_t *call) 69 70 { 70 graph_dev_ops_t *graph_dev_ops = (graph_dev_ops_t *) ops; 71 72 if (!graph_dev_ops->connect || !ddf_fun_data_get(fun)) { 71 led_dev_ops_t *led_dev_ops = (led_dev_ops_t *) ops; 72 pixel_t color = DEV_IPC_GET_ARG1(*call); 73 74 if (!led_dev_ops->color_set) { 73 75 async_answer_0(callid, ENOTSUP); 74 76 return; 75 77 } 76 77 (*graph_dev_ops->connect)(ddf_fun_data_get(fun), callid, call, NULL); 78 79 int rc = (*led_dev_ops->color_set)(fun, color); 80 async_answer_0(callid, rc); 78 81 } 79 82 -
uspace/lib/drv/generic/remote_nic.c
r3eb0c85 r8e7c9fe 288 288 async_exch_t *exch = async_exchange_begin(dev_sess); 289 289 290 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 291 NIC_GET_DEVICE_INFO); 292 if (rc != EOK) { 293 async_exchange_end(exch); 290 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 291 NIC_GET_DEVICE_INFO, NULL); 292 int rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t)); 293 async_exchange_end(exch); 294 295 sysarg_t res; 296 async_wait_for(aid, &res); 297 298 if (rc != EOK) 294 299 return rc; 295 } 296 297 rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t)); 298 299 async_exchange_end(exch); 300 301 return rc; 300 301 return (int) res; 302 302 } 303 303 -
uspace/lib/drv/generic/remote_usbhc.c
r3eb0c85 r8e7c9fe 212 212 static void async_transaction_destroy(async_transaction_t *trans) 213 213 { 214 if (trans == NULL) {215 return; 216 }217 if (trans->buffer != NULL) {214 if (trans == NULL) 215 return; 216 217 if (trans->buffer != NULL) 218 218 free(trans->buffer); 219 } 220 219 221 220 free(trans); 222 221 } … … 304 303 async_answer_0(callid, ENOMEM); 305 304 async_transaction_destroy(trans); 305 return; 306 306 } 307 307 -
uspace/lib/drv/include/ddf/driver.h
r3eb0c85 r8e7c9fe 111 111 } driver_t; 112 112 113 /** XXX Only to transition network drivers */114 #ifdef _DDF_DATA_IMPLANT115 extern void ddf_fun_data_implant(ddf_fun_t *, void *);116 #endif117 118 113 extern int ddf_driver_main(const driver_t *); 119 114 -
uspace/lib/drv/include/ddf/interrupt.h
r3eb0c85 r8e7c9fe 49 49 */ 50 50 51 typedef void interrupt_handler_t( ddf_dev_t *, ipc_callid_t, ipc_call_t *);51 typedef void interrupt_handler_t(ipc_callid_t, ipc_call_t *, ddf_dev_t *); 52 52 53 typedef struct interrupt_context {54 int id;55 ddf_dev_t *dev;56 int irq;57 interrupt_handler_t *handler;58 link_t link;59 } interrupt_context_t;60 61 typedef struct interrupt_context_list {62 int curr_id;63 list_t contexts;64 fibril_mutex_t mutex;65 } interrupt_context_list_t;66 67 extern void interrupt_init(void);68 53 extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *, 69 54 const irq_code_t *); -
uspace/lib/drv/include/ops/led_dev.h
r3eb0c85 r8e7c9fe 1 1 /* 2 * Copyright (c) 201 1 Petr Koupy2 * Copyright (c) 2014 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef LIBDRV_OPS_ GRAPH_DEV_H_36 #define LIBDRV_OPS_ GRAPH_DEV_H_35 #ifndef LIBDRV_OPS_LED_DEV_H_ 36 #define LIBDRV_OPS_LED_DEV_H_ 37 37 38 #include < async.h>38 #include <io/pixel.h> 39 39 #include "../ddf/driver.h" 40 40 41 typedef void (*connect_func)(void *, ipc_callid_t , ipc_call_t *, void *);42 43 41 typedef struct { 44 connect_func connect;45 } graph_dev_ops_t;42 int (*color_set)(ddf_fun_t *, pixel_t); 43 } led_dev_ops_t; 46 44 47 45 #endif -
uspace/lib/drv/include/pci_dev_iface.h
r3eb0c85 r8e7c9fe 40 40 #include "ddf/driver.h" 41 41 42 #define PCI_VENDOR_ID 0x00 42 43 #define PCI_DEVICE_ID 0x02 43 44
Note:
See TracChangeset
for help on using the changeset viewer.