Changeset cfb79747 in mainline for uspace/lib/drv


Ignore:
Timestamp:
2012-02-14T22:06:15Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a31aad1
Parents:
199112e4 (diff), e10d41a (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.
Message:

Merge mainline changes.

Location:
uspace/lib/drv
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/Makefile

    r199112e4 rcfb79747  
    3535        generic/driver.c \
    3636        generic/dev_iface.c \
     37        generic/interrupt.c \
    3738        generic/log.c \
    3839        generic/logbuf.c \
  • uspace/lib/drv/generic/driver.c

    r199112e4 rcfb79747  
    7070FIBRIL_MUTEX_INITIALIZE(functions_mutex);
    7171
    72 /** Interrupts */
    73 static interrupt_context_list_t interrupt_contexts;
    74 
    75 static irq_cmd_t default_cmds[] = {
    76         {
    77                 .cmd = CMD_ACCEPT
    78         }
    79 };
    80 
    81 static irq_code_t default_pseudocode = {
    82         0,
    83         NULL,
    84         sizeof(default_cmds) / sizeof(irq_cmd_t),
    85         default_cmds
    86 };
    87 
    8872static ddf_dev_t *create_device(void);
    8973static void delete_device(ddf_dev_t *);
     
    9579static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
    9680
    97 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
    98 {
    99         int id = (int)IPC_GET_IMETHOD(*icall);
    100         interrupt_context_t *ctx;
    101        
    102         ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    103         if (ctx != NULL && ctx->handler != NULL)
    104                 (*ctx->handler)(ctx->dev, iid, icall);
    105 }
    106 
    107 interrupt_context_t *create_interrupt_context(void)
    108 {
    109         interrupt_context_t *ctx;
    110        
    111         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    112         if (ctx != NULL)
    113                 memset(ctx, 0, sizeof(interrupt_context_t));
    114        
    115         return ctx;
    116 }
    117 
    118 void delete_interrupt_context(interrupt_context_t *ctx)
    119 {
    120         if (ctx != NULL)
    121                 free(ctx);
    122 }
    123 
    124 void init_interrupt_context_list(interrupt_context_list_t *list)
    125 {
    126         memset(list, 0, sizeof(interrupt_context_list_t));
    127         fibril_mutex_initialize(&list->mutex);
    128         list_initialize(&list->contexts);
    129 }
    130 
    131 void
    132 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    133 {
    134         fibril_mutex_lock(&list->mutex);
    135         ctx->id = list->curr_id++;
    136         list_append(&ctx->link, &list->contexts);
    137         fibril_mutex_unlock(&list->mutex);
    138 }
    139 
    140 void remove_interrupt_context(interrupt_context_list_t *list,
    141     interrupt_context_t *ctx)
    142 {
    143         fibril_mutex_lock(&list->mutex);
    144         list_remove(&ctx->link);
    145         fibril_mutex_unlock(&list->mutex);
    146 }
    147 
    148 interrupt_context_t *
    149 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    150 {
    151         interrupt_context_t *ctx;
    152        
    153         fibril_mutex_lock(&list->mutex);
    154        
    155         list_foreach(list->contexts, link) {
    156                 ctx = list_get_instance(link, interrupt_context_t, link);
    157                 if (ctx->id == id) {
    158                         fibril_mutex_unlock(&list->mutex);
    159                         return ctx;
    160                 }
    161         }
    162        
    163         fibril_mutex_unlock(&list->mutex);
    164         return NULL;
    165 }
    166 
    167 interrupt_context_t *
    168 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    169 {
    170         interrupt_context_t *ctx;
    171        
    172         fibril_mutex_lock(&list->mutex);
    173        
    174         list_foreach(list->contexts, link) {
    175                 ctx = list_get_instance(link, interrupt_context_t, link);
    176                 if (ctx->irq == irq && ctx->dev == dev) {
    177                         fibril_mutex_unlock(&list->mutex);
    178                         return ctx;
    179                 }
    180         }
    181        
    182         fibril_mutex_unlock(&list->mutex);
    183         return NULL;
    184 }
    185 
    186 
    187 int
    188 register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
    189     irq_code_t *pseudocode)
    190 {
    191         interrupt_context_t *ctx = create_interrupt_context();
    192        
    193         ctx->dev = dev;
    194         ctx->irq = irq;
    195         ctx->handler = handler;
    196        
    197         add_interrupt_context(&interrupt_contexts, ctx);
    198        
    199         if (pseudocode == NULL)
    200                 pseudocode = &default_pseudocode;
    201        
    202         int res = irq_register(irq, dev->handle, ctx->id, pseudocode);
    203         if (res != EOK) {
    204                 remove_interrupt_context(&interrupt_contexts, ctx);
    205                 delete_interrupt_context(ctx);
    206         }
    207 
    208         return res;
    209 }
    210 
    211 int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
    212 {
    213         interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
    214             dev, irq);
    215         int res = irq_unregister(irq, dev->handle);
    216        
    217         if (ctx != NULL) {
    218                 remove_interrupt_context(&interrupt_contexts, ctx);
    219                 delete_interrupt_context(ctx);
    220         }
    221        
    222         return res;
    223 }
    224 
    22581static void add_to_functions_list(ddf_fun_t *fun)
    22682{
     
    303159       
    304160        async_answer_0(iid, res);
    305 }
    306 
    307 static void driver_dev_added(ipc_callid_t iid, ipc_call_t *icall)
    308 {
    309         fibril_mutex_lock(&devices_mutex);
    310         ddf_dev_t *dev = driver_get_device(IPC_GET_ARG1(*icall));
    311         fibril_mutex_unlock(&devices_mutex);
    312        
    313         if (dev != NULL && driver->driver_ops->device_added != NULL)
    314                 driver->driver_ops->device_added(dev);
    315161}
    316162
     
    462308                case DRIVER_DEV_ADD:
    463309                        driver_dev_add(callid, &call);
    464                         break;
    465                 case DRIVER_DEV_ADDED:
    466                         async_answer_0(callid, EOK);
    467                         driver_dev_added(callid, &call);
    468310                        break;
    469311                case DRIVER_DEV_REMOVE:
     
    753595
    754596/** Allocate driver-specific device data. */
    755 extern void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
     597void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
    756598{
    757599        void *data;
     
    815657
    816658/** Allocate driver-specific function data. */
    817 extern void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
     659void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
    818660{
    819661        void *data;
     
    1008850        driver = drv;
    1009851       
    1010         /* Initialize the list of interrupt contexts. */
    1011         init_interrupt_context_list(&interrupt_contexts);
    1012        
    1013         /* Set generic interrupt handler. */
    1014         async_set_interrupt_received(driver_irq_handler);
     852        /* Initialize interrupt module */
     853        interrupt_init();
    1015854       
    1016855        /*
  • uspace/lib/drv/generic/remote_nic.c

    r199112e4 rcfb79747  
    6363}
    6464
    65 static void remote_nic_connect_to_nil(ddf_fun_t *dev, void *iface,
    66     ipc_callid_t callid, ipc_call_t *call)
    67 {
    68         nic_iface_t *nic_iface = (nic_iface_t *) iface;
    69         assert(nic_iface->connect_to_nil);
    70        
    71         services_t nil_service = (services_t) IPC_GET_ARG2(*call);
    72         nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG3(*call);
    73        
    74         int rc = nic_iface->connect_to_nil(dev, nil_service, device_id);
     65static void remote_nic_callback_create(ddf_fun_t *dev, void *iface,
     66    ipc_callid_t callid, ipc_call_t *call)
     67{
     68        nic_iface_t *nic_iface = (nic_iface_t *) iface;
     69        assert(nic_iface->callback_create);
     70       
     71        int rc = nic_iface->callback_create(dev);
    7572        async_answer_0(callid, rc);
    7673}
     
    12031200static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    12041201        &remote_nic_send_frame,
    1205         &remote_nic_connect_to_nil,
     1202        &remote_nic_callback_create,
    12061203        &remote_nic_get_state,
    12071204        &remote_nic_set_state,
  • uspace/lib/drv/include/ddf/driver.h

    r199112e4 rcfb79747  
    145145        /** Ask driver to offline a specific function */
    146146        int (*fun_offline)(ddf_fun_t *);
    147 
    148         /**
    149          * Notification that the device was succesfully added.
    150          * The driver can do any blocking operation without
    151          * blocking the device manager.
    152          *
    153          * XXX REMOVE THIS
    154          */
    155         void (*device_added)(ddf_dev_t *dev);
    156147} driver_ops_t;
    157148
  • uspace/lib/drv/include/ddf/interrupt.h

    r199112e4 rcfb79747  
    6464} interrupt_context_list_t;
    6565
    66 extern interrupt_context_t *create_interrupt_context(void);
    67 extern void delete_interrupt_context(interrupt_context_t *);
    68 extern void init_interrupt_context_list(interrupt_context_list_t *);
    69 extern void add_interrupt_context(interrupt_context_list_t *,
    70     interrupt_context_t *);
    71 extern void remove_interrupt_context(interrupt_context_list_t *,
    72     interrupt_context_t *);
    73 extern interrupt_context_t *find_interrupt_context_by_id(
    74     interrupt_context_list_t *, int);
    75 extern interrupt_context_t *find_interrupt_context(
    76     interrupt_context_list_t *, ddf_dev_t *, int);
    77 
     66extern void interrupt_init(void);
    7867extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *,
    7968    irq_code_t *);
  • uspace/lib/drv/include/ops/nic.h

    r199112e4 rcfb79747  
    3838
    3939#include <ipc/services.h>
    40 #include <net/device.h>
     40#include <nic/nic.h>
    4141#include <sys/time.h>
    4242
     
    4646        /** Mandatory methods */
    4747        int (*send_frame)(ddf_fun_t *, void *, size_t);
    48         int (*connect_to_nil)(ddf_fun_t *, services_t, nic_device_id_t);
     48        int (*callback_create)(ddf_fun_t *);
    4949        int (*get_state)(ddf_fun_t *, nic_device_state_t *);
    5050        int (*set_state)(ddf_fun_t *, nic_device_state_t);
  • uspace/lib/drv/include/usbhc_iface.h

    r199112e4 rcfb79747  
    2727 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828 */
     29
    2930/** @addtogroup libdrv
    3031 * @addtogroup usb
    3132 * @{
    3233 */
     34
    3335/** @file
    3436 * @brief USB host controller interface definition.
Note: See TracChangeset for help on using the changeset viewer.