Ignore:
File:
1 edited

Legend:

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

    r17b3cc6 r55b77d9  
    4242 *
    4343 * The structure of a notification message is as follows:
    44  * - IMETHOD: interface and method as registered by
    45  *            the SYS_IRQ_REGISTER syscall
     44 * - IMETHOD: interface and method as registered by the SYS_REGISTER_IRQ
     45 *            syscall
    4646 * - ARG1: payload modified by a 'top-half' handler
    4747 * - ARG2: payload modified by a 'top-half' handler
     
    365365                return IRQ_DECLINE;
    366366       
     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
    367385        as_t *current_as = AS;
    368         if (current_as != irq->driver_as)
    369                 as_switch(AS, irq->driver_as);
    370        
    371         for (size_t i = 0; i < code->cmdcount; i++) {
     386        size_t i;
     387        for (i = 0; i < code->cmdcount; i++) {
    372388                uint32_t dstval;
    373                 void *va;
    374                 uint8_t val8;
    375                 uint16_t val16;
    376                 uint32_t val32;
    377                
    378389                uintptr_t srcarg = code->cmds[i].srcarg;
    379390                uintptr_t dstarg = code->cmds[i].dstarg;
     
    431442                        }
    432443                        break;
    433                 case CMD_MEM_READ_8:
    434                         va = code->cmds[i].addr;
    435                         memcpy_from_uspace(&val8, va, sizeof(val8));
    436                         if (dstarg)
    437                                 scratch[dstarg] = val8;
    438                         break;
    439                 case CMD_MEM_READ_16:
    440                         va = code->cmds[i].addr;
    441                         memcpy_from_uspace(&val16, va, sizeof(val16));
    442                         if (dstarg)
    443                                 scratch[dstarg] = val16;
    444                         break;
    445                 case CMD_MEM_READ_32:
    446                         va = code->cmds[i].addr;
    447                         memcpy_from_uspace(&val32, va, sizeof(val32));
    448                         if (dstarg)
    449                                 scratch[dstarg] = val32;
    450                         break;
    451                 case CMD_MEM_WRITE_8:
    452                         val8 = code->cmds[i].value;
    453                         va = code->cmds[i].addr;
    454                         memcpy_to_uspace(va, &val8, sizeof(val8));
    455                         break;
    456                 case CMD_MEM_WRITE_16:
    457                         val16 = code->cmds[i].value;
    458                         va = code->cmds[i].addr;
    459                         memcpy_to_uspace(va, &val16, sizeof(val16));
    460                         break;
    461                 case CMD_MEM_WRITE_32:
    462                         val32 = code->cmds[i].value;
    463                         va = code->cmds[i].addr;
    464                         memcpy_to_uspace(va, &val32, sizeof(val32));
    465                         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                        }
    466474                case CMD_MEM_WRITE_A_8:
    467475                        if (srcarg) {
    468                                 val8 = scratch[srcarg];
    469                                 va = code->cmds[i].addr;
    470                                 memcpy_to_uspace(va, &val8, sizeof(val8));
     476                                uint8_t val = scratch[srcarg];
     477                                CMD_MEM_WRITE(val);
    471478                        }
    472479                        break;
    473480                case CMD_MEM_WRITE_A_16:
    474481                        if (srcarg) {
    475                                 val16 = scratch[srcarg];
    476                                 va = code->cmds[i].addr;
    477                                 memcpy_to_uspace(va, &val16, sizeof(val16));
     482                                uint16_t val = scratch[srcarg];
     483                                CMD_MEM_WRITE(val);
    478484                        }
    479485                        break;
    480486                case CMD_MEM_WRITE_A_32:
    481487                        if (srcarg) {
    482                                 val32 = scratch[srcarg];
    483                                 va = code->cmds[i].addr;
    484                                 memcpy_to_uspace(va, &val32, sizeof(val32));
     488                                uint32_t val = scratch[srcarg];
     489                                CMD_MEM_WRITE(val);
    485490                        }
    486491                        break;
     
    508513                }
    509514        }
    510        
    511515        if (AS != current_as)
    512516                as_switch(AS, current_as);
Note: See TracChangeset for help on using the changeset viewer.