Changeset 1affcdf3 in mainline for kernel/generic/src/ipc


Ignore:
Timestamp:
2011-06-10T19:33:41Z (15 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1878386
Parents:
13ecdac9 (diff), 79a141a (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:
kernel/generic/src/ipc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/event.c

    r13ecdac9 r1affcdf3  
    4848static event_t events[EVENT_END];
    4949
    50 /** Initialize kernel events. */
     50/** Initialize kernel events.
     51 *
     52 */
    5153void event_init(void)
    5254{
    53         unsigned int i;
    54        
    55         for (i = 0; i < EVENT_END; i++) {
     55        for (unsigned int i = 0; i < EVENT_END; i++) {
    5656                spinlock_initialize(&events[i].lock, "event.lock");
    5757                events[i].answerbox = NULL;
    5858                events[i].counter = 0;
    5959                events[i].imethod = 0;
     60                events[i].masked = false;
     61                events[i].unmask_callback = NULL;
    6062        }
    6163}
    6264
     65/** Unsubscribe kernel events associated with an answerbox
     66 *
     67 * @param answerbox Answerbox to be unsubscribed.
     68 *
     69 */
     70void event_cleanup_answerbox(answerbox_t *answerbox)
     71{
     72        for (unsigned int i = 0; i < EVENT_END; i++) {
     73                spinlock_lock(&events[i].lock);
     74               
     75                if (events[i].answerbox == answerbox) {
     76                        events[i].answerbox = NULL;
     77                        events[i].counter = 0;
     78                        events[i].imethod = 0;
     79                        events[i].masked = false;
     80                }
     81               
     82                spinlock_unlock(&events[i].lock);
     83        }
     84}
     85
     86/** Define a callback function for the event unmask event.
     87 *
     88 * @param evno     Event type.
     89 * @param callback Callback function to be called when
     90 *                 the event is unmasked.
     91 *
     92 */
     93void event_set_unmask_callback(event_type_t evno, event_callback_t callback)
     94{
     95        ASSERT(evno < EVENT_END);
     96       
     97        spinlock_lock(&events[evno].lock);
     98        events[evno].unmask_callback = callback;
     99        spinlock_unlock(&events[evno].lock);
     100}
     101
     102/** Send kernel notification event
     103 *
     104 * @param evno Event type.
     105 * @param mask Mask further notifications after a successful
     106 *             sending.
     107 * @param a1   First argument.
     108 * @param a2   Second argument.
     109 * @param a3   Third argument.
     110 * @param a4   Fourth argument.
     111 * @param a5   Fifth argument.
     112 *
     113 * @return EOK if notification was successfully sent.
     114 * @return ENOMEM if the notification IPC message failed to allocate.
     115 * @return EBUSY if the notifications of the given type are
     116 *         currently masked.
     117 * @return ENOENT if the notifications of the given type are
     118 *         currently not subscribed.
     119 *
     120 */
     121int event_notify(event_type_t evno, bool mask, sysarg_t a1, sysarg_t a2,
     122    sysarg_t a3, sysarg_t a4, sysarg_t a5)
     123{
     124        ASSERT(evno < EVENT_END);
     125       
     126        spinlock_lock(&events[evno].lock);
     127       
     128        int ret;
     129       
     130        if (events[evno].answerbox != NULL) {
     131                if (!events[evno].masked) {
     132                        call_t *call = ipc_call_alloc(FRAME_ATOMIC);
     133                       
     134                        if (call) {
     135                                call->flags |= IPC_CALL_NOTIF;
     136                                call->priv = ++events[evno].counter;
     137                               
     138                                IPC_SET_IMETHOD(call->data, events[evno].imethod);
     139                                IPC_SET_ARG1(call->data, a1);
     140                                IPC_SET_ARG2(call->data, a2);
     141                                IPC_SET_ARG3(call->data, a3);
     142                                IPC_SET_ARG4(call->data, a4);
     143                                IPC_SET_ARG5(call->data, a5);
     144                               
     145                                irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
     146                                list_append(&call->link, &events[evno].answerbox->irq_notifs);
     147                                irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
     148                               
     149                                waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
     150                               
     151                                if (mask)
     152                                        events[evno].masked = true;
     153                               
     154                                ret = EOK;
     155                        } else
     156                                ret = ENOMEM;
     157                } else
     158                        ret = EBUSY;
     159        } else
     160                ret = ENOENT;
     161       
     162        spinlock_unlock(&events[evno].lock);
     163       
     164        return ret;
     165}
     166
     167/** Subscribe event notifications
     168 *
     169 * @param evno      Event type.
     170 * @param imethod   IPC interface and method to be used for
     171 *                  the notifications.
     172 * @param answerbox Answerbox to send the notifications to.
     173 *
     174 * @return EOK if the subscription was successful.
     175 * @return EEXISTS if the notifications of the given type are
     176 *         already subscribed.
     177 *
     178 */
    63179static int event_subscribe(event_type_t evno, sysarg_t imethod,
    64180    answerbox_t *answerbox)
    65181{
    66         if (evno >= EVENT_END)
    67                 return ELIMIT;
     182        ASSERT(evno < EVENT_END);
    68183       
    69184        spinlock_lock(&events[evno].lock);
     
    75190                events[evno].imethod = imethod;
    76191                events[evno].counter = 0;
     192                events[evno].masked = false;
    77193                res = EOK;
    78194        } else
     
    84200}
    85201
     202/** Unmask event notifications
     203 *
     204 * @param evno Event type to unmask.
     205 *
     206 */
     207static void event_unmask(event_type_t evno)
     208{
     209        ASSERT(evno < EVENT_END);
     210       
     211        spinlock_lock(&events[evno].lock);
     212        events[evno].masked = false;
     213        event_callback_t callback = events[evno].unmask_callback;
     214        spinlock_unlock(&events[evno].lock);
     215       
     216        /*
     217         * Check if there is an unmask callback
     218         * function defined for this event.
     219         */
     220        if (callback != NULL)
     221                callback();
     222}
     223
     224/** Event notification syscall wrapper
     225 *
     226 * @param evno    Event type to subscribe.
     227 * @param imethod IPC interface and method to be used for
     228 *                the notifications.
     229 *
     230 * @return EOK on success.
     231 * @return ELIMIT on unknown event type.
     232 * @return EEXISTS if the notifications of the given type are
     233 *         already subscribed.
     234 *
     235 */
    86236sysarg_t sys_event_subscribe(sysarg_t evno, sysarg_t imethod)
    87237{
     238        if (evno >= EVENT_END)
     239                return ELIMIT;
     240       
    88241        return (sysarg_t) event_subscribe((event_type_t) evno, (sysarg_t)
    89242            imethod, &TASK->answerbox);
    90243}
    91244
    92 bool event_is_subscribed(event_type_t evno)
    93 {
    94         bool res;
    95        
    96         ASSERT(evno < EVENT_END);
    97        
    98         spinlock_lock(&events[evno].lock);
    99         res = events[evno].answerbox != NULL;
    100         spinlock_unlock(&events[evno].lock);
    101        
    102         return res;
    103 }
    104 
    105 
    106 void event_cleanup_answerbox(answerbox_t *answerbox)
    107 {
    108         unsigned int i;
    109        
    110         for (i = 0; i < EVENT_END; i++) {
    111                 spinlock_lock(&events[i].lock);
    112                 if (events[i].answerbox == answerbox) {
    113                         events[i].answerbox = NULL;
    114                         events[i].counter = 0;
    115                         events[i].imethod = 0;
    116                 }
    117                 spinlock_unlock(&events[i].lock);
    118         }
    119 }
    120 
    121 void event_notify(event_type_t evno, sysarg_t a1, sysarg_t a2, sysarg_t a3,
    122     sysarg_t a4, sysarg_t a5)
    123 {
    124         ASSERT(evno < EVENT_END);
    125        
    126         spinlock_lock(&events[evno].lock);
    127         if (events[evno].answerbox != NULL) {
    128                 call_t *call = ipc_call_alloc(FRAME_ATOMIC);
    129                 if (call) {
    130                         call->flags |= IPC_CALL_NOTIF;
    131                         call->priv = ++events[evno].counter;
    132                         IPC_SET_IMETHOD(call->data, events[evno].imethod);
    133                         IPC_SET_ARG1(call->data, a1);
    134                         IPC_SET_ARG2(call->data, a2);
    135                         IPC_SET_ARG3(call->data, a3);
    136                         IPC_SET_ARG4(call->data, a4);
    137                         IPC_SET_ARG5(call->data, a5);
    138                        
    139                         irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
    140                         list_append(&call->link, &events[evno].answerbox->irq_notifs);
    141                         irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
    142                        
    143                         waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
    144                 }
    145         }
    146         spinlock_unlock(&events[evno].lock);
     245/** Event notification unmask syscall wrapper
     246 *
     247 * Note that currently no tests are performed whether the calling
     248 * task is entitled to unmask the notifications. However, thanks
     249 * to the fact that notification masking is only a performance
     250 * optimization, this has probably no security implications.
     251 *
     252 * @param evno Event type to unmask.
     253 *
     254 * @return EOK on success.
     255 * @return ELIMIT on unknown event type.
     256 *
     257 */
     258sysarg_t sys_event_unmask(sysarg_t evno)
     259{
     260        if (evno >= EVENT_END)
     261                return ELIMIT;
     262       
     263        event_unmask((event_type_t) evno);
     264        return EOK;
    147265}
    148266
  • kernel/generic/src/ipc/ipc.c

    r13ecdac9 r1affcdf3  
    4444#include <synch/synch.h>
    4545#include <ipc/ipc.h>
     46#include <ipc/ipc_methods.h>
    4647#include <ipc/kbox.h>
    4748#include <ipc/event.h>
  • kernel/generic/src/ipc/irq.c

    r13ecdac9 r1affcdf3  
    174174        irq->notif_cfg.code = code;
    175175        irq->notif_cfg.counter = 0;
     176        irq->driver_as = AS;
    176177       
    177178        /*
     
    364365                return IRQ_DECLINE;
    365366       
     367#define CMD_MEM_READ(target) \
     368do { \
     369        void *va = code->cmds[i].addr; \
     370        if (AS != irq->driver_as) \
     371                as_switch(AS, irq->driver_as); \
     372        memcpy_from_uspace(&target, va, (sizeof(target))); \
     373        if (dstarg) \
     374                scratch[dstarg] = target; \
     375} while(0)
     376
     377#define CMD_MEM_WRITE(val) \
     378do { \
     379        void *va = code->cmds[i].addr; \
     380        if (AS != irq->driver_as) \
     381                as_switch(AS, irq->driver_as); \
     382        memcpy_to_uspace(va, &val, sizeof(val)); \
     383} while (0)
     384
     385        as_t *current_as = AS;
    366386        size_t i;
    367387        for (i = 0; i < code->cmdcount; i++) {
     
    422442                        }
    423443                        break;
     444                case CMD_MEM_READ_8: {
     445                        uint8_t val;
     446                        CMD_MEM_READ(val);
     447                        break;
     448                        }
     449                case CMD_MEM_READ_16: {
     450                        uint16_t val;
     451                        CMD_MEM_READ(val);
     452                        break;
     453                        }
     454                case CMD_MEM_READ_32: {
     455                        uint32_t val;
     456                        CMD_MEM_READ(val);
     457                        break;
     458                        }
     459                case CMD_MEM_WRITE_8: {
     460                        uint8_t val = code->cmds[i].value;
     461                        CMD_MEM_WRITE(val);
     462                        break;
     463                        }
     464                case CMD_MEM_WRITE_16: {
     465                        uint16_t val = code->cmds[i].value;
     466                        CMD_MEM_WRITE(val);
     467                        break;
     468                        }
     469                case CMD_MEM_WRITE_32: {
     470                        uint32_t val = code->cmds[i].value;
     471                        CMD_MEM_WRITE(val);
     472                        break;
     473                        }
     474                case CMD_MEM_WRITE_A_8:
     475                        if (srcarg) {
     476                                uint8_t val = scratch[srcarg];
     477                                CMD_MEM_WRITE(val);
     478                        }
     479                        break;
     480                case CMD_MEM_WRITE_A_16:
     481                        if (srcarg) {
     482                                uint16_t val = scratch[srcarg];
     483                                CMD_MEM_WRITE(val);
     484                        }
     485                        break;
     486                case CMD_MEM_WRITE_A_32:
     487                        if (srcarg) {
     488                                uint32_t val = scratch[srcarg];
     489                                CMD_MEM_WRITE(val);
     490                        }
     491                        break;
    424492                case CMD_BTEST:
    425493                        if ((srcarg) && (dstarg)) {
     
    435503                        break;
    436504                case CMD_ACCEPT:
     505                        if (AS != current_as)
     506                                as_switch(AS, current_as);
    437507                        return IRQ_ACCEPT;
    438508                case CMD_DECLINE:
    439509                default:
     510                        if (AS != current_as)
     511                                as_switch(AS, current_as);
    440512                        return IRQ_DECLINE;
    441513                }
    442514        }
     515        if (AS != current_as)
     516                as_switch(AS, current_as);
    443517       
    444518        return IRQ_DECLINE;
  • kernel/generic/src/ipc/kbox.c

    r13ecdac9 r1affcdf3  
    3737#include <synch/mutex.h>
    3838#include <ipc/ipc.h>
     39#include <ipc/ipc_methods.h>
    3940#include <ipc/ipcrsc.h>
    4041#include <arch.h>
     
    169170                switch (IPC_GET_IMETHOD(call->data)) {
    170171               
    171                 case IPC_M_DEBUG_ALL:
     172                case IPC_M_DEBUG:
    172173                        /* Handle debug call. */
    173174                        udebug_call_receive(call);
  • kernel/generic/src/ipc/sysipc.c

    r13ecdac9 r1affcdf3  
    4040#include <debug.h>
    4141#include <ipc/ipc.h>
     42#include <ipc/ipc_methods.h>
    4243#include <ipc/sysipc.h>
    4344#include <ipc/irq.h>
     
    460461        }
    461462#ifdef CONFIG_UDEBUG
    462         case IPC_M_DEBUG_ALL:
     463        case IPC_M_DEBUG:
    463464                return udebug_request_preprocess(call, phone);
    464465#endif
     
    495496                /*
    496497                 * This must be an affirmative answer to IPC_M_DATA_READ
    497                  * or IPC_M_DEBUG_ALL/UDEBUG_M_MEM_READ...
     498                 * or IPC_M_DEBUG/UDEBUG_M_MEM_READ...
    498499                 *
    499500                 */
     
    531532       
    532533        switch (IPC_GET_IMETHOD(call->data)) {
    533         case IPC_M_DEBUG_ALL:
     534        case IPC_M_DEBUG:
    534535                return -1;
    535536        default:
Note: See TracChangeset for help on using the changeset viewer.