Changeset 948911d in mainline for uspace/srv


Ignore:
Timestamp:
2012-01-24T02:27:43Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
230385c
Parents:
8afeb04 (diff), 2df6f6fe (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/srv
Files:
6 added
3 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    r8afeb04 r948911d  
    245245        void *vaddr;
    246246        int rc;
    247 
    248         rc = loc_server_register(NAME, ata_bd_connection);
     247       
     248        async_set_client_connection(ata_bd_connection);
     249        rc = loc_server_register(NAME);
    249250        if (rc < 0) {
    250251                printf(NAME ": Unable to register driver.\n");
  • uspace/srv/bd/file_bd/file_bd.c

    r8afeb04 r948911d  
    141141        int rc;
    142142        long img_size;
    143 
    144         rc = loc_server_register(NAME, file_bd_connection);
     143       
     144        async_set_client_connection(file_bd_connection);
     145        rc = loc_server_register(NAME);
    145146        if (rc < 0) {
    146147                printf(NAME ": Unable to register driver.\n");
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    r8afeb04 r948911d  
    125125        int rc, i;
    126126        char name[16];
    127 
    128         rc = loc_server_register(NAME, gxe_bd_connection);
     127       
     128        async_set_client_connection(gxe_bd_connection);
     129        rc = loc_server_register(NAME);
    129130        if (rc < 0) {
    130131                printf(NAME ": Unable to register driver.\n");
  • uspace/srv/bd/part/guid_part/guid_part.c

    r8afeb04 r948911d  
    164164
    165165        /* Register server with location service. */
    166         rc = loc_server_register(NAME, gpt_connection);
     166        async_set_client_connection(gpt_connection);
     167        rc = loc_server_register(NAME);
    167168        if (rc != EOK) {
    168169                printf(NAME ": Unable to register server.\n");
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    r8afeb04 r948911d  
    214214
    215215        /* Register server with location service. */
    216         rc = loc_server_register(NAME, mbr_connection);
     216        async_set_client_connection(mbr_connection);
     217        rc = loc_server_register(NAME);
    217218        if (rc != EOK) {
    218219                printf(NAME ": Unable to register server.\n");
  • uspace/srv/bd/rd/rd.c

    r8afeb04 r948911d  
    235235            (void *) addr_phys, size);
    236236       
    237         ret = loc_server_register(NAME, rd_connection);
     237        async_set_client_connection(rd_connection);
     238        ret = loc_server_register(NAME);
    238239        if (ret < 0) {
    239240                printf("%s: Unable to register driver (%d)\n", NAME, ret);
  • uspace/srv/devman/devman.c

    r8afeb04 r948911d  
    794794        case EOK:
    795795                dev->state = DEVICE_USABLE;
    796                 exch = async_exchange_begin(drv->sess);
    797                 async_msg_1(exch, DRIVER_DEV_ADDED, dev->handle);
    798                 async_exchange_end(exch);
    799796                break;
    800797        case ENOENT:
     
    803800        default:
    804801                dev->state = DEVICE_INVALID;
     802                break;
    805803        }
    806804       
  • uspace/srv/devman/main.c

    r8afeb04 r948911d  
    13091309
    13101310        /*
    1311          * !!! devman_connection ... as the device manager is not a real loc
    1312          * driver (it uses a completely different ipc protocol than an ordinary
    1313          * loc driver) forwarding a connection from client to the devman by
    1314          * location service would not work.
     1311         * Caution: As the device manager is not a real loc
     1312         * driver (it uses a completely different IPC protocol
     1313         * than an ordinary loc driver), forwarding a connection
     1314         * from client to the devman by location service will
     1315         * not work.
    13151316         */
    1316         loc_server_register(NAME, devman_connection);
     1317        loc_server_register(NAME);
    13171318       
    13181319        return true;
     
    13251326        if (log_init(NAME, LVL_WARN) != EOK) {
    13261327                printf(NAME ": Error initializing logging subsystem.\n");
    1327                 return -1;
    1328         }
    1329 
    1330         if (!devman_init()) {
    1331                 log_msg(LVL_ERROR, "Error while initializing service.");
    13321328                return -1;
    13331329        }
     
    13381334        async_set_client_connection(devman_connection);
    13391335
     1336        if (!devman_init()) {
     1337                log_msg(LVL_ERROR, "Error while initializing service.");
     1338                return -1;
     1339        }
     1340
    13401341        /* Register device manager at naming service. */
    13411342        if (service_register(SERVICE_DEVMAN) != EOK) {
  • uspace/srv/hid/console/console.c

    r8afeb04 r948911d  
    825825       
    826826        /* Register server */
    827         int rc = loc_server_register(NAME, client_connection);
     827        async_set_client_connection(client_connection);
     828        int rc = loc_server_register(NAME);
    828829        if (rc < 0) {
    829830                printf("%s: Unable to register server (%s)\n", NAME,
  • uspace/srv/hid/fb/fb.c

    r8afeb04 r948911d  
    987987       
    988988        /* Register server */
    989         int rc = loc_server_register(NAME, client_connection);
     989        async_set_client_connection(client_connection);
     990        int rc = loc_server_register(NAME);
    990991        if (rc != EOK) {
    991992                printf("%s: Unable to register driver (%d)\n", NAME, rc);
  • uspace/srv/hid/input/Makefile

    r8afeb04 r948911d  
    4343        port/adb_mouse.c \
    4444        port/chardev.c \
    45         port/chardev_mouse.c \
    4645        port/gxemul.c \
    4746        port/msim.c \
     
    5251        proto/adb.c \
    5352        proto/mousedev.c \
    54         proto/ps2.c \
    5553        ctl/apple.c \
    5654        ctl/gxe_fb.c \
  • uspace/srv/hid/input/generic/input.c

    r8afeb04 r948911d  
    3939#include <adt/list.h>
    4040#include <bool.h>
     41#include <fibril_synch.h>
    4142#include <ipc/services.h>
    4243#include <ipc/input.h>
     
    8384async_sess_t *irc_sess = NULL;
    8485
     86static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
     87
    8588void kbd_push_data(kbd_dev_t *kdev, sysarg_t data)
    8689{
     
    172175
    173176/** Mouse pointer has moved. */
    174 void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy)
     177void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy, int dz)
    175178{
    176179        async_exch_t *exch = async_exchange_begin(client_sess);
    177         async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
     180        if (dx || dy)
     181                async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
     182        if (dz) {
     183                // TODO: Implement proper wheel support
     184                keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
     185                for (int i = 0; i < 3; ++i) {
     186                        async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
     187                }
     188                async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
     189        }
    178190        async_exchange_end(exch);
    179191}
     
    397409         * them automatically.
    398410         */
    399 #if defined(UARCH_amd64)
    400         kbd_add_dev(&chardev_port, &pc_ctl);
    401 #endif
    402411#if defined(UARCH_arm32) && defined(MACHINE_gta02)
    403412        kbd_add_dev(&chardev_port, &stty_ctl);
     
    411420#if defined(UARCH_arm32) && defined(MACHINE_integratorcp)
    412421        kbd_add_dev(&pl050_port, &pc_ctl);
    413 #endif
    414 #if defined(UARCH_ia32)
    415         kbd_add_dev(&chardev_port, &pc_ctl);
    416 #endif
    417 #if defined(MACHINE_i460GX)
    418         kbd_add_dev(&chardev_port, &pc_ctl);
    419422#endif
    420423#if defined(MACHINE_ski)
     
    450453         * them automatically.
    451454         */
    452 #if defined(UARCH_amd64)
    453         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    454 #endif
    455 #if defined(UARCH_ia32)
    456         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    457 #endif
    458 #if defined(MACHINE_i460GX)
    459         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    460 #endif
    461455#if defined(UARCH_ppc32)
    462456        mouse_add_dev(&adb_mouse_port, &adb_proto);
     
    602596        int rc;
    603597       
     598        fibril_mutex_lock(&discovery_lock);
     599       
    604600        rc = dev_check_new_kbdevs();
    605         if (rc != EOK)
     601        if (rc != EOK) {
     602                fibril_mutex_unlock(&discovery_lock);
    606603                return rc;
     604        }
    607605       
    608606        rc = dev_check_new_mousedevs();
    609         if (rc != EOK)
     607        if (rc != EOK) {
     608                fibril_mutex_unlock(&discovery_lock);
    610609                return rc;
    611 
     610        }
     611       
     612        fibril_mutex_unlock(&discovery_lock);
     613       
    612614        return EOK;
    613615}
     
    658660       
    659661        /* Register driver */
    660         int rc = loc_server_register(NAME, client_connection);
     662        async_set_client_connection(client_connection);
     663        int rc = loc_server_register(NAME);
    661664        if (rc < 0) {
    662665                printf("%s: Unable to register server (%d)\n", NAME, rc);
  • uspace/srv/hid/input/include/mouse.h

    r8afeb04 r948911d  
    6262
    6363extern void mouse_push_data(mouse_dev_t *, sysarg_t);
    64 extern void mouse_push_event_move(mouse_dev_t *, int, int);
     64extern void mouse_push_event_move(mouse_dev_t *, int, int, int);
    6565extern void mouse_push_event_button(mouse_dev_t *, int, int);
    6666
  • uspace/srv/hid/input/include/mouse_proto.h

    r8afeb04 r948911d  
    4848
    4949extern mouse_proto_ops_t adb_proto;
    50 extern mouse_proto_ops_t ps2_proto;
    5150extern mouse_proto_ops_t mousedev_proto;
    5251
  • uspace/srv/hid/input/port/chardev.c

    r8afeb04 r948911d  
    6363/** List of devices to try connecting to. */
    6464static const char *in_devs[] = {
    65         "char/ps2a",
    6665        "char/s3c24ser"
    6766};
  • uspace/srv/hid/input/proto/adb.c

    r8afeb04 r948911d  
    8282       
    8383        if (dx != 0 || dy != 0)
    84                 mouse_push_event_move(mouse_dev, dx, dy);
     84                mouse_push_event_move(mouse_dev, dx, dy, 0);
    8585}
    8686
  • uspace/srv/hid/input/proto/mousedev.c

    r8afeb04 r948911d  
    9191                switch (IPC_GET_IMETHOD(call)) {
    9292                case MOUSEEV_MOVE_EVENT:
    93                         mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call),
    94                             IPC_GET_ARG2(call));
     93                        mouse_push_event_move(mousedev->mouse_dev,
     94                            IPC_GET_ARG1(call), IPC_GET_ARG2(call),
     95                            IPC_GET_ARG3(call));
    9596                        retval = EOK;
    9697                        break;
    9798                case MOUSEEV_BUTTON_EVENT:
    98                         mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),
    99                             IPC_GET_ARG2(call));
     99                        mouse_push_event_button(mousedev->mouse_dev,
     100                            IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    100101                        retval = EOK;
    101102                        break;
  • uspace/srv/hid/s3c24xx_ts/s3c24xx_ts.c

    r8afeb04 r948911d  
    8585
    8686        printf(NAME ": S3C24xx touchscreen driver\n");
    87 
    88         rc = loc_server_register(NAME, s3c24xx_ts_connection);
     87       
     88        async_set_client_connection(s3c24xx_ts_connection);
     89        rc = loc_server_register(NAME);
    8990        if (rc < 0) {
    9091                printf(NAME ": Unable to register driver.\n");
  • uspace/srv/hw/bus/cuda_adb/cuda_adb.c

    r8afeb04 r948911d  
    154154        }
    155155
    156         rc = loc_server_register(NAME, cuda_connection);
     156        async_set_client_connection(cuda_connection);
     157        rc = loc_server_register(NAME);
    157158        if (rc < 0) {
    158159                printf(NAME ": Unable to register server.\n");
  • uspace/srv/hw/char/s3c24xx_uart/s3c24xx_uart.c

    r8afeb04 r948911d  
    7979        printf(NAME ": S3C24xx on-chip UART driver\n");
    8080
    81         rc = loc_server_register(NAME, s3c24xx_uart_connection);
     81        async_set_client_connection(s3c24xx_uart_connection);
     82        rc = loc_server_register(NAME);
    8283        if (rc < 0) {
    8384                printf(NAME ": Unable to register server.\n");
  • uspace/srv/loc/loc.c

    r8afeb04 r948911d  
    5656#define NULL_SERVICES  256
    5757
     58/** Callback session */
     59typedef struct {
     60        link_t cb_sess_list;
     61        async_sess_t *sess;
     62} cb_sess_t;
     63
    5864LIST_INITIALIZE(services_list);
    5965LIST_INITIALIZE(namespaces_list);
     
    8692
    8793static FIBRIL_MUTEX_INITIALIZE(callback_sess_mutex);
    88 static async_sess_t *callback_sess = NULL;
     94static LIST_INITIALIZE(callback_sess_list);
    8995
    9096service_id_t loc_create_id(void)
     
    608614        size_t act_size;
    609615        loc_service_t *svc;
     616        char *fqn;
    610617       
    611618        if (!async_data_read_receive(&callid, &size)) {
     
    625632        }
    626633       
    627         act_size = str_size(svc->name);
     634        if (asprintf(&fqn, "%s/%s", svc->namespace->name, svc->name) < 0) {
     635                fibril_mutex_unlock(&services_list_mutex);
     636                async_answer_0(callid, ENOMEM);
     637                async_answer_0(iid, ENOMEM);
     638                return;
     639        }
     640       
     641        act_size = str_size(fqn);
    628642        if (act_size > size) {
     643                free(fqn);
    629644                fibril_mutex_unlock(&services_list_mutex);
    630645                async_answer_0(callid, EOVERFLOW);
     
    633648        }
    634649       
    635         sysarg_t retval = async_data_read_finalize(callid, svc->name,
     650        sysarg_t retval = async_data_read_finalize(callid, fqn,
    636651            min(size, act_size));
     652        free(fqn);
    637653       
    638654        fibril_mutex_unlock(&services_list_mutex);
     
    790806}
    791807
    792 /** Find ID for category specified by name.
    793  *
    794  * On success, answer will contain EOK int retval and service ID in arg1.
     808/** Create callback connection.
     809 *
     810 * Create callback connection which will be used to send category change
     811 * events.
     812 *
     813 * On success, answer will contain EOK int retval.
    795814 * On failure, error code will be sent in retval.
    796  *
    797815 */
    798816static void loc_callback_create(ipc_callid_t iid, ipc_call_t *icall)
    799817{
    800         async_sess_t *cb_sess = async_callback_receive(EXCHANGE_SERIALIZE);
     818        cb_sess_t *cb_sess;
     819       
     820        cb_sess = calloc(1, sizeof(cb_sess_t));
    801821        if (cb_sess == NULL) {
    802822                async_answer_0(iid, ENOMEM);
     
    804824        }
    805825       
     826        async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
     827        if (sess == NULL) {
     828                free(cb_sess);
     829                async_answer_0(iid, ENOMEM);
     830                return;
     831        }
     832       
     833        cb_sess->sess = sess;
     834        link_initialize(&cb_sess->cb_sess_list);
     835       
    806836        fibril_mutex_lock(&callback_sess_mutex);
    807         if (callback_sess != NULL) {
    808                 fibril_mutex_unlock(&callback_sess_mutex);
    809                 async_answer_0(iid, EEXIST);
    810                 return;
    811         }
    812        
    813         callback_sess = cb_sess;
     837        list_append(&cb_sess->cb_sess_list, &callback_sess_list);
    814838        fibril_mutex_unlock(&callback_sess_mutex);
    815839       
     
    820844{
    821845        fibril_mutex_lock(&callback_sess_mutex);
    822 
    823         if (callback_sess != NULL) {
    824                 async_exch_t *exch = async_exchange_begin(callback_sess);
     846       
     847        list_foreach(callback_sess_list, link) {
     848                cb_sess_t *cb_sess;
     849               
     850                cb_sess = list_get_instance(link, cb_sess_t, cb_sess_list);
     851               
     852                async_exch_t *exch = async_exchange_begin(cb_sess->sess);
    825853                async_msg_0(exch, LOC_EVENT_CAT_CHANGE);
    826854                async_exchange_end(exch);
    827855        }
    828 
     856       
    829857        fibril_mutex_unlock(&callback_sess_mutex);
    830858}
  • uspace/srv/net/cfg/e1k.nic

    r8afeb04 r948911d  
    33NAME=e1k
    44
    5 HWPATH=/hw/pci0/00:03.0/port0
     5HWPATH=devices/\hw\pci0\00:03.0\port0
    66NIL=eth
    77IL=ip
  • uspace/srv/net/cfg/lo.nic

    r8afeb04 r948911d  
    33NAME=lo
    44
    5 HWPATH=/virt/lo/port0
     5HWPATH=devices/\virt\lo\port0
    66NIL=nildummy
    77IL=ip
  • uspace/srv/net/cfg/ne2k.nic

    r8afeb04 r948911d  
    33NAME=ne2k
    44
    5 HWPATH=/hw/pci0/00:01.0/ne2k/port0
     5HWPATH=devices/\hw\pci0\00:01.0\ne2k\port0
    66NIL=eth
    77IL=ip
  • uspace/srv/net/net/Makefile

    r8afeb04 r948911d  
    3131ROOT_PATH = $(USPACE_PREFIX)/..
    3232LIBS = $(LIBNET_PREFIX)/libnet.a
    33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
     33EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBNIC_PREFIX)/include \
     34    -I$(LIBDRV_PREFIX)/include
    3435
    3536COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
  • uspace/srv/net/net/net.c

    r8afeb04 r948911d  
    22 * Copyright (c) 2009 Lukas Mejdrech
    33 * Copyright (c) 2011 Radim Vansa
     4 * Copyright (c) 2011 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    4142#include <stdio.h>
    4243#include <str.h>
    43 #include <devman.h>
    4444#include <str_error.h>
    4545#include <ns.h>
     
    5656#include <adt/measured_strings.h>
    5757#include <adt/module_map.h>
     58#include <fibril_synch.h>
     59#include <loc.h>
     60#include <nic.h>
    5861#include <nil_remote.h>
    5962#include <net_interface.h>
     
    7376GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
    7477DEVICE_MAP_IMPLEMENT(netifs, netif_t);
     78LIST_INITIALIZE(netif_list);
     79
     80static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
    7581
    7682/** Add the configured setting to the configuration map.
     
    287293 *
    288294 */
    289 static int init_device(netif_t *netif, devman_handle_t handle)
     295static int init_device(netif_t *netif, service_id_t sid)
    290296{
    291297        printf("%s: Initializing device '%s'\n", NAME, netif->name);
    292298       
    293         netif->handle = handle;
    294         netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,
     299        netif->sid = sid;
     300        netif->sess = loc_service_connect(EXCHANGE_SERIALIZE, netif->sid,
    295301            IPC_FLAG_BLOCKING);
    296302        if (netif->sess == NULL) {
     
    337343                    strtol((const char *) setting->value, NULL, 10) : 0;
    338344                rc = nil_device_req(netif->nil->sess, netif->id,
    339                     netif->handle, mtu);
     345                    netif->sid, mtu);
    340346                if (rc != EOK) {
    341347                        printf("%s: Unable to start network interface layer\n",
     
    359365                break;
    360366        default:
     367                printf("%s: Unknown service\n", NAME);
    361368                return ENOENT;
    362369        }
    363370       
    364371        printf("%s: Activating device '%s'\n", NAME, netif->name);
     372        list_append(&netif->netif_list, &netif_list);
    365373        return nic_set_state(netif->sess, NIC_STATE_ACTIVE);
    366374}
    367375
    368 static int net_port_ready(devman_handle_t handle)
    369 {
    370         char hwpath[MAX_PATH_LENGTH];
    371         int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH);
    372         if (rc != EOK)
     376static int net_nic_ready(service_id_t sid)
     377{
     378        int rc;
     379        char *hwpath;
     380       
     381        rc = loc_service_get_name(sid, &hwpath);
     382        if (rc != EOK) {
     383                printf("%s: Failed getting name of service '%u'\n",
     384                    NAME, (unsigned) sid);
    373385                return EINVAL;
     386        }
    374387       
    375388        int index = char_map_find(&net_globals.netif_hwpaths,
    376389            (uint8_t *) hwpath, 0);
    377         if (index == CHAR_MAP_NULL)
     390       
     391        if (index == CHAR_MAP_NULL) {
     392                printf("%s: Service '%s' not found in map.\n", NAME, hwpath);
     393                free(hwpath);
    378394                return ENOENT;
     395        }
     396       
     397        free(hwpath);
    379398       
    380399        netif_t *netif = netifs_get_index(&net_globals.netifs, index);
     
    382401                return ENOENT;
    383402       
    384         rc = init_device(netif, handle);
     403        rc = init_device(netif, sid);
    385404        if (rc != EOK)
    386405                return rc;
     
    391410       
    392411        netif->il->usage++;
    393        
    394         return EOK;
    395 }
    396 
    397 static int net_driver_ready_local(devman_handle_t handle)
    398 {
    399         devman_handle_t *funs;
    400         size_t count;
    401         int rc = devman_dev_get_functions(handle, &funs, &count);
    402         if (rc != EOK)
    403                 return rc;
    404        
    405         for (size_t i = 0; i < count; i++) {
    406                 rc = net_port_ready(funs[i]);
    407                 if (rc != EOK)
    408                         return rc;
    409         }
    410412       
    411413        return EOK;
     
    479481                net_free_devices(strings, count);
    480482                return rc;
    481         case NET_NET_DRIVER_READY:
    482                 rc = net_driver_ready_local(IPC_GET_ARG1(*call));
    483                 *answer_count = 0;
    484                 return rc;
    485483        default:
    486484                return ENOTSUP;
     
    528526                answer_call(callid, res, &answer, count);
    529527        }
     528}
     529
     530static int nic_check_new(void)
     531{
     532        category_id_t nic_cat;
     533        service_id_t *svcs;
     534        size_t count, i;
     535        bool already_known;
     536        int rc;
     537
     538        fibril_mutex_lock(&discovery_lock);
     539
     540        rc = loc_category_get_id(DEVICE_CATEGORY_NIC, &nic_cat, IPC_FLAG_BLOCKING);
     541        if (rc != EOK) {
     542                printf("%s: Failed resolving category '%s'.\n", NAME,
     543                    DEVICE_CATEGORY_NIC);
     544                return ENOENT;
     545        }
     546
     547        rc = loc_category_get_svcs(nic_cat, &svcs, &count);
     548        if (rc != EOK) {
     549                printf("%s: Failed getting list of NIC devices.\n", NAME);
     550                return EIO;
     551        }
     552
     553        for (i = 0; i < count; i++) {
     554                already_known = false;
     555
     556                list_foreach(netif_list, link) {
     557                        netif_t *netif = list_get_instance(link, netif_t, netif_list);
     558                        if (netif->sid == svcs[i]) {
     559                                already_known = true;
     560                                break;
     561                        }
     562                }
     563
     564                if (!already_known) {
     565                        rc = net_nic_ready(svcs[i]);
     566                        if (rc != EOK) {
     567                                printf("%s: Failed adding NIC device #%u.\n",
     568                                    NAME, (unsigned) svcs[i]);
     569                        }
     570                }
     571        }
     572
     573        free(svcs);
     574        fibril_mutex_unlock(&discovery_lock);
     575        return EOK;
     576}
     577
     578static void cat_change_cb(void)
     579{
     580        (void) nic_check_new();
     581}
     582
     583static int net_start_nic_discovery(void)
     584{
     585        int rc;
     586
     587        rc = loc_register_cat_change_cb(cat_change_cb);
     588        if (rc != EOK) {
     589                printf("%s: Failed registering callback for device discovery (%d).\n",
     590                    NAME, rc);
     591                return rc;
     592        }
     593
     594        return nic_check_new();
    530595}
    531596
     
    573638                                continue;
    574639                       
    575                         netif->handle = -1;
     640                        netif->sid = -1;
    576641                        netif->sess = NULL;
    577642                       
     
    697762        }
    698763       
     764        rc = net_start_nic_discovery();
     765        if (rc != EOK) {
     766                printf("%s: Error starting NIC discovery\n", NAME);
     767                pm_destroy();
     768                return rc;
     769        }
     770       
    699771        task_retval(0);
    700772        async_manager();
  • uspace/srv/net/net/net.h

    r8afeb04 r948911d  
    3535#define NET_NET_H_
    3636
     37#include <ipc/loc.h>
    3738#include <net/device.h>
    3839#include <adt/char_map.h>
     
    4142#include <adt/module_map.h>
    4243#include <net/packet.h>
    43 #include <devman.h>
    4444
    4545#define NAME  "net"
     
    9696       
    9797        /** Serving network interface driver module index. */
    98         devman_handle_t handle;  /**< Handle for devman */
     98        service_id_t sid;  /**< Service ID */
    9999        async_sess_t *sess;      /**< Driver session. */
    100100       
    101101        module_t *nil;  /**< Serving link layer module index. */
    102102        module_t *il;   /**< Serving internet layer module index. */
     103       
     104        link_t netif_list;
    103105} netif_t;
    104106
  • uspace/srv/net/nil/eth/eth.c

    r8afeb04 r948911d  
    4848#include <ipc/net.h>
    4949#include <ipc/services.h>
     50#include <loc.h>
    5051#include <net/modules.h>
    5152#include <net_checksum.h>
     
    169170INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    170171
    171 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
     172static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall,
     173    void *arg);
     174
     175static int eth_device_state(nic_device_id_t device_id, sysarg_t state)
    172176{
    173177        int index;
     
    226230 *
    227231 * @param[in] device_id New device identifier.
    228  * @param[in] handle    Device driver handle.
     232 * @param[in] sid       NIC service ID.
    229233 * @param[in] mtu       Device maximum transmission unit.
    230234 *
     
    234238 *
    235239 */
    236 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,
     240static int eth_device_message(nic_device_id_t device_id, service_id_t sid,
    237241    size_t mtu)
    238242{
     
    259263        device = eth_devices_find(&eth_globals.devices, device_id);
    260264        if (device) {
    261                 if (device->handle != handle) {
     265                if (device->sid != sid) {
    262266                        printf("Device %d already exists\n", device->device_id);
    263267                        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    298302
    299303        device->device_id = device_id;
    300         device->handle = handle;
     304        device->sid = sid;
    301305        device->flags = 0;
    302306        if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
     
    335339       
    336340        /* Bind the device driver */
    337         device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
     341        device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid,
    338342            IPC_FLAG_BLOCKING);
    339343        if (device->sess == NULL) {
     
    343347        }
    344348       
    345         nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id);
     349        rc = nic_callback_create(device->sess, device_id,
     350            eth_nic_cb_connection, NULL);
     351        if (rc != EOK) {
     352                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     353                async_hangup(device->sess);
     354                free(device);
     355                return EIO;
     356        }
    346357       
    347358        /* Get hardware address */
     
    362373        }
    363374       
    364         printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, "
     375        printf("%s: Device registered (id: %d, sid: %zu: mtu: %zu, "
    365376            "mac: " PRIMAC ", flags: 0x%x)\n", NAME,
    366             device->device_id, device->handle, device->mtu,
     377            device->device_id, device->sid, device->mtu,
    367378            ARGSMAC(device->addr.address), device->flags);
    368379
     
    802813                        next = tmp;
    803814                } else {
     815                        nic_send_frame(device->sess, packet_get_data(next),
     816                            packet_get_data_length(next));
    804817                        next = pq_next(next);
    805818                }
    806819        } while (next);
    807820       
    808         /* Send packet queue */
    809         if (packet)
    810                 nic_send_message(device->sess, packet_get_id(packet));
     821        pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
    811822       
    812823        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    813824        return EOK;
     825}
     826
     827static int eth_received(nic_device_id_t device_id)
     828{
     829        void *data;
     830        size_t size;
     831        int rc;
     832       
     833        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     834        if (rc != EOK) {
     835                printf("%s: data_write_accept() failed\n", NAME);
     836                return rc;
     837        }
     838       
     839        packet_t *packet = packet_get_1_remote(eth_globals.net_sess, size);
     840        if (packet == NULL)
     841                return ENOMEM;
     842       
     843        void *pdata = packet_suffix(packet, size);
     844        memcpy(pdata, data, size);
     845        free(data);
     846       
     847        return nil_received_msg_local(device_id, packet);
    814848}
    815849
     
    921955               
    922956                return EOK;
    923         case NET_NIL_DEVICE_STATE:
    924                 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));
    925                 async_answer_0(callid, EOK);
    926                 return EOK;
    927         case NET_NIL_RECEIVED:
    928                 rc = packet_translate_remote(eth_globals.net_sess, &packet,
    929                     IPC_GET_ARG2(*call));
    930                 if (rc == EOK)
    931                         rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
    932                
    933                 async_answer_0(callid, (sysarg_t) rc);
    934                 return rc;
    935         case NET_NIL_ADDR_CHANGED:
    936                 rc = eth_addr_changed(IPC_GET_DEVICE(*call));
    937                 async_answer_0(callid, (sysarg_t) rc);
    938                 return rc;
    939957        }
    940958       
    941959        return ENOTSUP;
     960}
     961
     962static void eth_nic_cb_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     963{
     964        int rc;
     965       
     966        async_answer_0(iid, EOK);
     967       
     968        while (true) {
     969                ipc_call_t call;
     970                ipc_callid_t callid = async_get_call(&call);
     971               
     972                if (!IPC_GET_IMETHOD(call))
     973                        break;
     974               
     975                switch (IPC_GET_IMETHOD(call)) {
     976                case NIC_EV_DEVICE_STATE:
     977                        rc = eth_device_state(IPC_GET_ARG1(call),
     978                            IPC_GET_ARG2(call));
     979                        async_answer_0(callid, (sysarg_t) rc);
     980                        break;
     981                case NIC_EV_RECEIVED:
     982                        rc = eth_received(IPC_GET_ARG1(call));
     983                        async_answer_0(callid, (sysarg_t) rc);
     984                        break;
     985                case NIC_EV_ADDR_CHANGED:
     986                        rc = eth_addr_changed(IPC_GET_ARG1(call));
     987                        async_answer_0(callid, (sysarg_t) rc);
     988                        break;
     989                default:
     990                        async_answer_0(callid, ENOTSUP);
     991                }
     992        }
    942993}
    943994
  • uspace/srv/net/nil/eth/eth.h

    r8afeb04 r948911d  
    4141#include <async.h>
    4242#include <fibril_synch.h>
     43#include <ipc/loc.h>
    4344#include <ipc/services.h>
    4445#include <net/device.h>
    4546#include <adt/measured_strings.h>
    46 #include <devman.h>
    4747
    4848/** Ethernet address length. */
     
    224224        nic_device_id_t device_id;
    225225        /** Device handle */
    226         devman_handle_t handle;
     226        service_id_t sid;
    227227        /** Driver session. */
    228228        async_sess_t *sess;
  • uspace/srv/net/nil/nildummy/nildummy.c

    r8afeb04 r948911d  
    22 * Copyright (c) 2009 Lukas Mejdrech
    33 * Copyright (c) 2011 Radim Vansa
     4 * Copyright (c) 2011 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    5354#include <packet_remote.h>
    5455#include <packet_client.h>
    55 #include <devman.h>
    5656#include <device/nic.h>
     57#include <loc.h>
    5758#include <nil_skel.h>
    5859#include "nildummy.h"
     
    6970DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    7071
    71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
     72static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall,
     73    void *arg);
     74
     75static int nildummy_device_state(nic_device_id_t device_id, sysarg_t state)
    7276{
    7377        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     
    7882       
    7983        return EOK;
     84}
     85
     86static int nildummy_addr_changed(nic_device_id_t device_id)
     87{
     88        return ENOTSUP;
    8089}
    8190
     
    115124 */
    116125static int nildummy_device_message(nic_device_id_t device_id,
    117     devman_handle_t handle, size_t mtu)
     126    service_id_t sid, size_t mtu)
    118127{
    119128        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
     
    123132            nildummy_devices_find(&nildummy_globals.devices, device_id);
    124133        if (device) {
    125                 if (device->handle != handle) {
     134                if (device->sid != sid) {
    126135                        printf("Device %d exists, handles do not match\n",
    127136                            device->device_id);
     
    158167       
    159168        device->device_id = device_id;
    160         device->handle = handle;
     169        device->sid = sid;
    161170        if (mtu > 0)
    162171                device->mtu = mtu;
     
    165174       
    166175        /* Bind the device driver */
    167         device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
     176        device->sess = loc_service_connect(EXCHANGE_SERIALIZE, sid,
    168177            IPC_FLAG_BLOCKING);
    169178        if (device->sess == NULL) {
     
    173182        }
    174183       
    175         nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id);
     184        int rc = nic_callback_create(device->sess, device_id,
     185            nildummy_nic_cb_conn, NULL);
     186        if (rc != EOK) {
     187                async_hangup(device->sess);
     188               
     189                return ENOENT;
     190        }
    176191       
    177192        /* Get hardware address */
    178         int rc = nic_get_address(device->sess, &device->addr);
     193        rc = nic_get_address(device->sess, &device->addr);
    179194        if (rc != EOK) {
    180195                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    345360    services_t sender)
    346361{
     362        packet_t *p;
     363       
    347364        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    348365       
     
    354371        }
    355372       
    356         /* Send packet queue */
    357         if (packet)
    358                 nic_send_message(device->sess, packet_get_id(packet));
     373        p = packet;
     374        do {
     375                nic_send_frame(device->sess, packet_get_data(p),
     376                    packet_get_data_length(p));
     377                p = pq_next(p);
     378        } while (p != NULL);
     379       
     380        pq_release_remote(nildummy_globals.net_sess, packet_get_id(packet));
    359381       
    360382        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    361383       
    362384        return EOK;
     385}
     386
     387static int nildummy_received(nic_device_id_t device_id)
     388{
     389        void *data;
     390        size_t size;
     391        int rc;
     392
     393        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     394        if (rc != EOK)
     395                return rc;
     396
     397        packet_t *packet = packet_get_1_remote(nildummy_globals.net_sess, size);
     398        if (packet == NULL)
     399                return ENOMEM;
     400
     401        void *pdata = packet_suffix(packet, size);
     402        memcpy(pdata, data, size);
     403        free(pdata);
     404
     405        return nil_received_msg_local(device_id, packet);
    363406}
    364407
     
    417460                *answer_count = 1;
    418461                return rc;
    419         case NET_NIL_DEVICE_STATE:
    420                 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),
    421                     IPC_GET_STATE(*call));
    422                 async_answer_0(callid, (sysarg_t) rc);
    423                 return rc;
    424        
    425         case NET_NIL_RECEIVED:
    426                 rc = packet_translate_remote(nildummy_globals.net_sess, &packet,
    427                     IPC_GET_ARG2(*call));
    428                 if (rc == EOK)
    429                         rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
    430                
    431                 async_answer_0(callid, (sysarg_t) rc);
    432                 return rc;
    433462        }
    434463       
    435464        return ENOTSUP;
    436465}
     466
     467static void nildummy_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     468{
     469        int rc;
     470       
     471        async_answer_0(iid, EOK);
     472       
     473        while (true) {
     474                ipc_call_t call;
     475                ipc_callid_t callid = async_get_call(&call);
     476               
     477                if (!IPC_GET_IMETHOD(call))
     478                        break;
     479               
     480                switch (IPC_GET_IMETHOD(call)) {
     481                case NIC_EV_DEVICE_STATE:
     482                        rc = nildummy_device_state(IPC_GET_ARG1(call),
     483                            IPC_GET_ARG2(call));
     484                        async_answer_0(callid, (sysarg_t) rc);
     485                        break;
     486                case NIC_EV_RECEIVED:
     487                        rc = nildummy_received(IPC_GET_ARG1(call));
     488                        async_answer_0(callid, (sysarg_t) rc);
     489                        break;
     490                case NIC_EV_ADDR_CHANGED:
     491                        rc = nildummy_addr_changed(IPC_GET_ARG1(call));
     492                        async_answer_0(callid, (sysarg_t) rc);
     493                        break;
     494                default:
     495                        async_answer_0(callid, ENOTSUP);
     496                }
     497        }
     498}
     499
    437500
    438501int main(int argc, char *argv[])
  • uspace/srv/net/nil/nildummy/nildummy.h

    r8afeb04 r948911d  
    4141#include <async.h>
    4242#include <fibril_synch.h>
     43#include <ipc/loc.h>
    4344#include <ipc/services.h>
    44 #include <ipc/devman.h>
    4545#include <net/device.h>
    4646
     
    7878        /** Device identifier. */
    7979        nic_device_id_t device_id;
    80         /** Device driver handle. */
    81         devman_handle_t handle;
     80        /** Device service ID. */
     81        service_id_t sid;
    8282        /** Driver session. */
    8383        async_sess_t *sess;
Note: See TracChangeset for help on using the changeset viewer.