Ejemplo n.º 1
0
/*
 * - allocate the max of 32 * 4K buffers for both input and output
 * - receive interrupts on completion of every 16 buffers
 */
long
ac97initbuf(void)
{
    long                l = AC97NBUF;
    struct ac97bufdesc *inbuf = ac97drv.inbuftab;
    struct ac97bufdesc *outbuf = ac97drv.outbuftab;
    uint8_t            *inptr;
    uint8_t            *outptr;

    /* allocate input buffer */
    inptr = kwalloc(AC97NBUF * AC97BUFSIZE);
    if (!inptr) {
        kprintf("AC97: failed to allocate audio input buffer\n");

        return 0;
    }
    /* allocate output buffer */
    outptr = kwalloc(AC97NBUF * AC97BUFSIZE);
    if (!outptr) {
        kprintf("AC97: failed to allocate audio output buffer\n");

        kfree(inptr);

        return 0;
    }
    /* clear buffers */
    kbzero(inptr, AC97NBUF * AC97BUFSIZE);
    kbzero(outptr, AC97NBUF * AC97BUFSIZE);
    /* set up buffer descriptors */
    while (l--) {
        inbuf->adr = (uint32_t)inptr;
        inbuf->info = AC97BUFSIZE - 1;
        outbuf->adr = (uint32_t)outptr;
        outbuf->info = AC97BUFSIZE - 1;
        inbuf++;
        outbuf++;
        inptr += AC97BUFSIZE;
        outptr += AC97BUFSIZE;
    }

    return 1;
}
Ejemplo n.º 2
0
long
procinit(long id, long sched)
{
    volatile struct cpu *cpu;
    struct proc         *proc;
    struct task         *task;
    long                 prio;
    long                 val;
    struct taskstk      *stk;
    void                *ptr;
    uint8_t             *u8ptr;

    if (id < TASKNPREDEF) {
//        cpu = &cputab[0];
        cpu = k_curcpu;
        proc = &proctab[id];
        task = &tasktab[id];
        prio = SCHEDSYSPRIOMIN;
        task->sched = SCHEDSYSTEM;
        task->prio = prio;
        proc->pagedir = (pde_t *)kernpagedir;
        proc->pagetab = (pte_t *)&_pagetab;
        task->state = TASKREADY;
        if (cpu->info.flg & CPUHASFXSR) {
            task->flg |= CPUHASFXSR;
        }
        k_curcpu = cpu;
        k_curunit = 0;
        k_curtask = task;
        k_curpid = id;

        return id;
    } else {
        cpu = &cputab[0];
        id = taskgetid();
        proc = &proctab[id];
        task = &tasktab[id];
        task->state = TASKNEW;
        proc->pid = id;
        proc->nice = 0;
        proc->task = task;
        k_curtask = task;
        task->proc = proc;
        val = 0;
        if (cpu->flg & CPUHASFXSR) {
            val = CPUHASFXSR;
            task->flg |= val;
        }
        val = 0;
        task->flg = val;
        task->score = val;
        task->slice = val;
        task->runtime = val;
        task->slptime = val;
        task->ntick = val;
        val = cpu->ntick;
        task->lastrun = val;
        task->firstrun = val;
        task->lasttick = val;
        if (sched == SCHEDNOCLASS) {
            prio = SCHEDUSERPRIOMIN;
            task->sched = SCHEDNORMAL;
            task->prio = prio;
        } else {
            prio = schedclassminprio(sched);
            task->sched = sched;
            task->prio = prio;
        }
        if (task->state == TASKNEW) {
            /* initialise page directory */
            ptr = kwalloc(NPDE * sizeof(pde_t));
            if (ptr) {
                kbzero(ptr, NPDE * sizeof(pde_t));
                proc->pagedir = ptr;
            } else {
                kfree(proc);
                
                return -1;
            }
#if (VMFLATPHYSTAB)
            /* initialise page tables */
            ptr = kwalloc(PAGETABSIZE);
            if (ptr) {
                kbzero(ptr, PAGETABSIZE);
                proc->pagetab = ptr;
            } else {
                kfree(proc->pagedir);
                kfree(proc);
                
                return -1;
            }
#endif
            /* initialise descriptor table */
            ptr = kmalloc(NPROCFD * sizeof(struct desc));
            if (ptr) {
                kbzero(ptr, NPROCFD * sizeof(struct desc));
                proc->desctab = ptr;
                proc->ndesctab = NPROCFD;
            } else {
                if (id >= TASKNPREDEF) {
                    kfree(proc->pagetab);
                    kfree(proc->pagedir);
                    kfree(proc);
                }
            }
        }
    }
    
    return id;
}