Changeset 70922c2 in mainline for uspace/lib


Ignore:
Timestamp:
2012-02-01T00:09:22Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ffcc5776
Parents:
cb3dbb63 (diff), 3d4750f (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:

Mainline changes.

Location:
uspace/lib
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/nic.c

    rcb3dbb63 r70922c2  
    8181 *
    8282 */
    83 int nic_callback_create(async_sess_t *dev_sess, nic_device_id_t device_id,
    84     async_client_conn_t cfun, void *carg)
     83int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun,
     84    void *carg)
    8585{
    8686        ipc_call_t answer;
     
    8989       
    9090        async_exch_t *exch = async_exchange_begin(dev_sess);
    91         aid_t req = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    92             NIC_CALLBACK_CREATE, device_id, &answer);
     91        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     92            NIC_CALLBACK_CREATE, &answer);
    9393       
    9494        rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg);
  • uspace/lib/c/include/device/nic.h

    rcb3dbb63 r70922c2  
    9191
    9292extern int nic_send_frame(async_sess_t *, void *, size_t);
    93 extern int nic_callback_create(async_sess_t *, nic_device_id_t,
    94     async_client_conn_t, void *);
     93extern int nic_callback_create(async_sess_t *, async_client_conn_t, void *);
    9594extern int nic_get_state(async_sess_t *, nic_device_state_t *);
    9695extern int nic_set_state(async_sess_t *, nic_device_state_t);
  • uspace/lib/c/include/net/device.h

    rcb3dbb63 r70922c2  
    4747#define DEVICE_MAP_IMPLEMENT  INT_MAP_IMPLEMENT
    4848
     49/** Device identifier type. */
     50typedef int nic_device_id_t;
     51
     52/** Invalid device identifier. */
     53#define NIC_DEVICE_INVALID_ID  (-1)
     54
    4955#endif
    5056
  • uspace/lib/c/include/nic/nic.h

    rcb3dbb63 r70922c2  
    6363#define NIC_MAX_ADDRESS_LENGTH  16
    6464
    65 /** Invalid device identifier. */
    66 #define NIC_DEVICE_INVALID_ID  (-1)
    67 
    6865#define NIC_VENDOR_MAX_LENGTH         64
    6966#define NIC_MODEL_MAX_LENGTH          64
     
    8683
    8784#define NIC_DEVICE_PRINT_FMT  "%x"
    88 
    89 /** Device identifier type. */
    90 typedef int nic_device_id_t;
    9185
    9286/**
  • uspace/lib/drv/Makefile

    rcb3dbb63 r70922c2  
    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

    rcb3dbb63 r70922c2  
    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         sizeof(default_cmds) / sizeof(irq_cmd_t),
    83         default_cmds
    84 };
    85 
    8672static ddf_dev_t *create_device(void);
    8773static void delete_device(ddf_dev_t *);
     
    9278static remote_handler_t *function_get_default_handler(ddf_fun_t *);
    9379static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
    94 
    95 static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
    96 {
    97         int id = (int)IPC_GET_IMETHOD(*icall);
    98         interrupt_context_t *ctx;
    99        
    100         ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    101         if (ctx != NULL && ctx->handler != NULL)
    102                 (*ctx->handler)(ctx->dev, iid, icall);
    103 }
    104 
    105 interrupt_context_t *create_interrupt_context(void)
    106 {
    107         interrupt_context_t *ctx;
    108        
    109         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    110         if (ctx != NULL)
    111                 memset(ctx, 0, sizeof(interrupt_context_t));
    112        
    113         return ctx;
    114 }
    115 
    116 void delete_interrupt_context(interrupt_context_t *ctx)
    117 {
    118         if (ctx != NULL)
    119                 free(ctx);
    120 }
    121 
    122 void init_interrupt_context_list(interrupt_context_list_t *list)
    123 {
    124         memset(list, 0, sizeof(interrupt_context_list_t));
    125         fibril_mutex_initialize(&list->mutex);
    126         list_initialize(&list->contexts);
    127 }
    128 
    129 void
    130 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    131 {
    132         fibril_mutex_lock(&list->mutex);
    133         ctx->id = list->curr_id++;
    134         list_append(&ctx->link, &list->contexts);
    135         fibril_mutex_unlock(&list->mutex);
    136 }
    137 
    138 void remove_interrupt_context(interrupt_context_list_t *list,
    139     interrupt_context_t *ctx)
    140 {
    141         fibril_mutex_lock(&list->mutex);
    142         list_remove(&ctx->link);
    143         fibril_mutex_unlock(&list->mutex);
    144 }
    145 
    146 interrupt_context_t *
    147 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    148 {
    149         interrupt_context_t *ctx;
    150        
    151         fibril_mutex_lock(&list->mutex);
    152        
    153         list_foreach(list->contexts, link) {
    154                 ctx = list_get_instance(link, interrupt_context_t, link);
    155                 if (ctx->id == id) {
    156                         fibril_mutex_unlock(&list->mutex);
    157                         return ctx;
    158                 }
    159         }
    160        
    161         fibril_mutex_unlock(&list->mutex);
    162         return NULL;
    163 }
    164 
    165 interrupt_context_t *
    166 find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    167 {
    168         interrupt_context_t *ctx;
    169        
    170         fibril_mutex_lock(&list->mutex);
    171        
    172         list_foreach(list->contexts, link) {
    173                 ctx = list_get_instance(link, interrupt_context_t, link);
    174                 if (ctx->irq == irq && ctx->dev == dev) {
    175                         fibril_mutex_unlock(&list->mutex);
    176                         return ctx;
    177                 }
    178         }
    179        
    180         fibril_mutex_unlock(&list->mutex);
    181         return NULL;
    182 }
    183 
    184 
    185 int
    186 register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
    187     irq_code_t *pseudocode)
    188 {
    189         interrupt_context_t *ctx = create_interrupt_context();
    190        
    191         ctx->dev = dev;
    192         ctx->irq = irq;
    193         ctx->handler = handler;
    194        
    195         add_interrupt_context(&interrupt_contexts, ctx);
    196        
    197         if (pseudocode == NULL)
    198                 pseudocode = &default_pseudocode;
    199        
    200         int res = irq_register(irq, dev->handle, ctx->id, pseudocode);
    201         if (res != EOK) {
    202                 remove_interrupt_context(&interrupt_contexts, ctx);
    203                 delete_interrupt_context(ctx);
    204         }
    205 
    206         return res;
    207 }
    208 
    209 int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
    210 {
    211         interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
    212             dev, irq);
    213         int res = irq_unregister(irq, dev->handle);
    214        
    215         if (ctx != NULL) {
    216                 remove_interrupt_context(&interrupt_contexts, ctx);
    217                 delete_interrupt_context(ctx);
    218         }
    219        
    220         return res;
    221 }
    22280
    22381static void add_to_functions_list(ddf_fun_t *fun)
     
    737595
    738596/** Allocate driver-specific device data. */
    739 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)
    740598{
    741599        void *data;
     
    799657
    800658/** Allocate driver-specific function data. */
    801 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)
    802660{
    803661        void *data;
     
    992850        driver = drv;
    993851       
    994         /* Initialize the list of interrupt contexts. */
    995         init_interrupt_context_list(&interrupt_contexts);
    996        
    997         /* Set generic interrupt handler. */
    998         async_set_interrupt_received(driver_irq_handler);
     852        /* Initialize interrupt module */
     853        interrupt_init();
    999854       
    1000855        /*
  • uspace/lib/drv/generic/remote_nic.c

    rcb3dbb63 r70922c2  
    6969        assert(nic_iface->callback_create);
    7070       
    71         nic_device_id_t device_id = (nic_device_id_t) IPC_GET_ARG2(*call);
    72        
    73         int rc = nic_iface->callback_create(dev, device_id);
     71        int rc = nic_iface->callback_create(dev);
    7472        async_answer_0(callid, rc);
    7573}
  • uspace/lib/drv/include/ddf/interrupt.h

    rcb3dbb63 r70922c2  
    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

    rcb3dbb63 r70922c2  
    4646        /** Mandatory methods */
    4747        int (*send_frame)(ddf_fun_t *, void *, size_t);
    48         int (*callback_create)(ddf_fun_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

    rcb3dbb63 r70922c2  
    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.
  • uspace/lib/nic/include/nic_driver.h

    rcb3dbb63 r70922c2  
    7070         */
    7171        ddf_fun_t *fun;
    72         /** Identifier for higher network stack layers */
    73         nic_device_id_t device_id;
    7472        /** Current state of the device */
    7573        nic_device_state_t state;
  • uspace/lib/nic/include/nic_ev.h

    rcb3dbb63 r70922c2  
    4343#include <sys/types.h>
    4444
    45 extern int nic_ev_addr_changed(async_sess_t *, nic_device_id_t,
    46     const nic_address_t *);
    47 extern int nic_ev_device_state(async_sess_t *, nic_device_id_t, sysarg_t);
    48 extern int nic_ev_received(async_sess_t *, nic_device_id_t, void *, size_t);
     45extern int nic_ev_addr_changed(async_sess_t *, const nic_address_t *);
     46extern int nic_ev_device_state(async_sess_t *, sysarg_t);
     47extern int nic_ev_received(async_sess_t *, void *, size_t);
    4948
    5049#endif
  • uspace/lib/nic/include/nic_impl.h

    rcb3dbb63 r70922c2  
    4848extern int nic_get_address_impl(ddf_fun_t *dev_fun, nic_address_t *address);
    4949extern int nic_send_frame_impl(ddf_fun_t *dev_fun, void *data, size_t size);
    50 extern int nic_callback_create_impl(ddf_fun_t *dev_fun, int device_id);
     50extern int nic_callback_create_impl(ddf_fun_t *dev_fun);
    5151extern int nic_get_state_impl(ddf_fun_t *dev_fun, nic_device_state_t *state);
    5252extern int nic_set_state_impl(ddf_fun_t *dev_fun, nic_device_state_t state);
  • uspace/lib/nic/src/nic_driver.c

    rcb3dbb63 r70922c2  
    497497        if (nic_data->client_session != NULL) {
    498498                int rc = nic_ev_addr_changed(nic_data->client_session,
    499                     nic_data->device_id, address);
     499                    address);
    500500                if (rc != EOK) {
    501501                        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    604604                }
    605605                fibril_rwlock_write_unlock(&nic_data->stats_lock);
    606                 nic_ev_received(nic_data->client_session, nic_data->device_id,
    607                     frame->data, frame->size);
     606                nic_ev_received(nic_data->client_session, frame->data,
     607                    frame->size);
    608608        } else {
    609609                switch (frame_type) {
     
    639639        fibril_rwlock_write_unlock(&nic_data->stats_lock);
    640640       
    641         nic_ev_received(nic_data->client_session, nic_data->device_id,
    642             data, size);
     641        nic_ev_received(nic_data->client_session, data, size);
    643642}
    644643
     
    691690        nic_data->dev = NULL;
    692691        nic_data->fun = NULL;
    693         nic_data->device_id = NIC_DEVICE_INVALID_ID;
    694692        nic_data->state = NIC_STATE_STOPPED;
    695693        nic_data->client_session = NULL;
  • uspace/lib/nic/src/nic_ev.c

    rcb3dbb63 r70922c2  
    4242
    4343/** Device address changed. */
    44 int nic_ev_addr_changed(async_sess_t *sess, nic_device_id_t dev_id,
    45     const nic_address_t *addr)
     44int nic_ev_addr_changed(async_sess_t *sess, const nic_address_t *addr)
    4645{
    4746        async_exch_t *exch = async_exchange_begin(sess);
    4847
    4948        ipc_call_t answer;
    50         aid_t req = async_send_1(exch, NIC_EV_ADDR_CHANGED, (sysarg_t) dev_id,
    51             &answer);
     49        aid_t req = async_send_0(exch, NIC_EV_ADDR_CHANGED, &answer);
    5250        sysarg_t retval = async_data_write_start(exch, addr,
    5351            sizeof(nic_address_t));
     
    6563
    6664/** Device state changed. */
    67 extern int nic_ev_device_state(async_sess_t *sess, nic_device_id_t dev_id,
    68     sysarg_t state)
     65int nic_ev_device_state(async_sess_t *sess, sysarg_t state)
    6966{
    7067        int rc;
    7168
    7269        async_exch_t *exch = async_exchange_begin(sess);
    73         rc = async_req_2_0(exch, NIC_EV_DEVICE_STATE, dev_id, state);
     70        rc = async_req_1_0(exch, NIC_EV_DEVICE_STATE, state);
    7471        async_exchange_end(exch);
    7572
     
    7875
    7976/** Frame received. */
    80 int nic_ev_received(async_sess_t *sess, nic_device_id_t dev_id, void *data,
    81     size_t size)
     77int nic_ev_received(async_sess_t *sess, void *data, size_t size)
    8278{
    8379        async_exch_t *exch = async_exchange_begin(sess);
    8480
    8581        ipc_call_t answer;
    86         aid_t req = async_send_1(exch, NIC_EV_RECEIVED, (sysarg_t) dev_id,
    87             &answer);
     82        aid_t req = async_send_0(exch, NIC_EV_RECEIVED, &answer);
    8883        sysarg_t retval = async_data_write_start(exch, data, size);
    8984
  • uspace/lib/nic/src/nic_impl.c

    rcb3dbb63 r70922c2  
    8787        }
    8888        if (state == NIC_STATE_ACTIVE) {
    89                 if (nic_data->client_session == NULL || nic_data->device_id < 0) {
     89                if (nic_data->client_session == NULL) {
    9090                        fibril_rwlock_write_unlock(&nic_data->main_lock);
    9191                        return EINVAL;
     
    118118                /* Notify upper layers that we are reseting the MAC */
    119119                int rc = nic_ev_addr_changed(nic_data->client_session,
    120                         nic_data->device_id, &nic_data->default_mac);
     120                        &nic_data->default_mac);
    121121                nic_data->poll_mode = nic_data->default_poll_mode;
    122122                memcpy(&nic_data->poll_period, &nic_data->default_poll_period,
     
    150150        nic_data->state = state;
    151151
    152         nic_ev_device_state(nic_data->client_session, nic_data->device_id, state);
     152        nic_ev_device_state(nic_data->client_session, state);
    153153
    154154        fibril_rwlock_write_unlock(&nic_data->main_lock);
     
    187187 *
    188188 * @param       fun
    189  * @param       device_id       ID of the device as used in higher layers
    190189 *
    191190 * @return EOK          On success, or negative error code.
    192191 */
    193 int nic_callback_create_impl(ddf_fun_t *fun, nic_device_id_t device_id)
     192int nic_callback_create_impl(ddf_fun_t *fun)
    194193{
    195194        nic_t *nic = (nic_t *) fun->driver_data;
    196195        fibril_rwlock_write_lock(&nic->main_lock);
    197        
    198         nic->device_id = device_id;
    199196       
    200197        nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE);
  • uspace/lib/posix/ctype.c

    rcb3dbb63 r70922c2  
    112112 * @return Non-zero if character match the definition, zero otherwise.
    113113 */
    114 extern int posix_isascii(int c)
     114int posix_isascii(int c)
    115115{
    116116        return c >= 0 && c < 128;
     
    123123 * @return Coverted character.
    124124 */
    125 extern int posix_toascii(int c)
     125int posix_toascii(int c)
    126126{
    127127        return c & 0x7F;
Note: See TracChangeset for help on using the changeset viewer.