akaros/kern/src/ns/devtab.c
<<
>>
Prefs
   1/*
   2 * Stub.
   3 */
   4//#define DEBUG
   5#include <kmalloc.h>
   6#include <string.h>
   7#include <stdio.h>
   8#include <assert.h>
   9#include <error.h>
  10#include <pmap.h>
  11#include <sys/queue.h>
  12#include <smp.h>
  13#include <kref.h>
  14#include <atomic.h>
  15#include <alarm.h>
  16#include <event.h>
  17#include <umem.h>
  18
  19void devtabreset(void)
  20{
  21        ERRSTACK(1);
  22        volatile int i;
  23
  24        if (waserror()) {
  25                panic("A devtab reset (probably %p) failed!", devtab[i].reset);
  26                poperror();
  27                return;
  28        }
  29        for (i = 0; &devtab[i] < __devtabend; i++) {
  30                if (devtab[i].reset)
  31                        devtab[i].reset();
  32        }
  33        poperror();
  34}
  35
  36void devtabinit(void)
  37{
  38        ERRSTACK(1);
  39        volatile int i;
  40
  41        if (waserror()) {
  42                panic("A devtab init (probably %p) failed!", devtab[i].init);
  43                poperror();
  44                return;
  45        }
  46        for (i = 0; &devtab[i] < __devtabend; i++) {
  47                /* if we have errors, check the align of struct dev and objdump
  48                 */
  49                printd("i %d, '%s', dev %p, init %p\n", i, devtab[i].name,
  50                       &devtab[i], devtab[i].init);
  51                if (devtab[i].init)
  52                        devtab[i].init();
  53        }
  54        poperror();
  55}
  56
  57void devtabshutdown(void)
  58{
  59        int i;
  60
  61        /*
  62         * Shutdown in reverse order.
  63         */
  64        for (i = 0; &devtab[i] < __devtabend; i++) ;
  65        for (i--; i >= 0; i--) {
  66                if (devtab[i].shutdown)
  67                        devtab[i].shutdown();
  68        }
  69}
  70
  71struct dev *devtabget(const char *name, int user)
  72{
  73        int i = devno(name, user);
  74
  75        if (i > 0)
  76                return &devtab[i];
  77
  78        printk("devtabget FAILED %s\n", name);
  79        error(ENOENT, ERROR_FIXME);
  80}
  81
  82long devtabread(struct chan *c, void *buf, long n, int64_t off)
  83{
  84        ERRSTACK(1);
  85
  86        int i;
  87        struct dev *dev;
  88        char *alloc, *e, *p;
  89
  90        alloc = kzmalloc(READSTR, MEM_WAIT);
  91        if (alloc == NULL)
  92                error(ENOMEM, ERROR_FIXME);
  93
  94        p = alloc;
  95        e = p + READSTR;
  96        for (i = 0; &devtab[i] < __devtabend; i++) {
  97                dev = &devtab[i];
  98                printd("p %p e %p e-p %d\n", p, e, e - p);
  99                printd("do %d %s\n", i, dev->name);
 100                p += snprintf(p, e - p, "#%s\n", dev->name);
 101        }
 102
 103        if (waserror()) {
 104                kfree(alloc);
 105                nexterror();
 106        }
 107        n = readstr(off, buf, n, alloc);
 108
 109        kfree(alloc);
 110        poperror();
 111
 112        return n;
 113}
 114