mirror of
https://github.com/drasko/codezero.git
synced 2026-01-20 14:53:16 +01:00
Made changes to map devices dynamically upon irq registration.
All will be reverted since mapping devices statically is much simpler.
This commit is contained in:
48
src/lib/addr.c
Normal file
48
src/lib/addr.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This module allocates an unused address range from
|
||||
* a given memory region defined as the pool range.
|
||||
*
|
||||
* Copyright (C) 2007 - 2009 Bahadir Balban
|
||||
*/
|
||||
#include <lib/bit.h>
|
||||
#include <l4/macros.h>
|
||||
#include <l4/types.h>
|
||||
#include INC_GLUE(memory.h)
|
||||
#include <lib/addr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
extern struct kernel_resources kres;
|
||||
|
||||
void *address_new(struct address_pool *pool, int npages)
|
||||
{
|
||||
unsigned int pfn;
|
||||
|
||||
if ((int)(pfn = ids_new_contiguous(pool->idpool, npages)) < 0)
|
||||
return 0;
|
||||
|
||||
return (void *)__pfn_to_addr(pfn) + pool->start;
|
||||
}
|
||||
|
||||
int address_del(struct address_pool *pool, void *addr, int npages)
|
||||
{
|
||||
unsigned long pfn = __pfn(page_align(addr) - pool->start);
|
||||
|
||||
if (ids_del_contiguous(pool->idpool, pfn, npages) < 0) {
|
||||
printf("%s: Invalid address range returned to "
|
||||
"virtual address pool.\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *kernel_new_address(int npages)
|
||||
{
|
||||
return address_new(&kres->kernel_address_pool, npages);
|
||||
}
|
||||
|
||||
int kernel_delete_address(void *addr, int npages)
|
||||
{
|
||||
address_del(&kres->kernel_address_pool, addr, npages);
|
||||
}
|
||||
|
||||
@@ -139,8 +139,15 @@ void wake_up_all(struct waitqueue_head *wqh, unsigned int flags)
|
||||
/* Wake up single waiter */
|
||||
void wake_up(struct waitqueue_head *wqh, unsigned int flags)
|
||||
{
|
||||
unsigned int irqflags;
|
||||
|
||||
BUG_ON(wqh->sleepers < 0);
|
||||
spin_lock(&wqh->slock);
|
||||
|
||||
/* Irq version */
|
||||
if (flags & WAKEUP_IRQ)
|
||||
spin_lock_irq(&wqh->lock, &irqflags);
|
||||
else
|
||||
spin_lock(&wqh->slock);
|
||||
if (wqh->sleepers > 0) {
|
||||
struct waitqueue *wq = link_to_struct(wqh->task_list.next,
|
||||
struct waitqueue,
|
||||
@@ -153,7 +160,10 @@ void wake_up(struct waitqueue_head *wqh, unsigned int flags)
|
||||
if (flags & WAKEUP_INTERRUPT)
|
||||
sleeper->flags |= TASK_INTERRUPTED;
|
||||
//printk("(%d) Waking up (%d)\n", current->tid, sleeper->tid);
|
||||
spin_unlock(&wqh->slock);
|
||||
if (flags & WAKEUP_IRQ)
|
||||
spin_unlock_irqrestore(&wqh->slock, irqflags);
|
||||
else
|
||||
spin_unlock(&wqh->slock);
|
||||
|
||||
if (flags & WAKEUP_SYNC)
|
||||
sched_resume_sync(sleeper);
|
||||
@@ -161,7 +171,10 @@ void wake_up(struct waitqueue_head *wqh, unsigned int flags)
|
||||
sched_resume_async(sleeper);
|
||||
return;
|
||||
}
|
||||
spin_unlock(&wqh->slock);
|
||||
if (flags & WAKEUP_IRQ)
|
||||
spin_unlock_irqrestore(&wqh->slock, irqflags);
|
||||
else
|
||||
spin_unlock(&wqh->slock);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -174,6 +187,9 @@ int wake_up_task(struct ktcb *task, unsigned int flags)
|
||||
struct waitqueue_head *wqh;
|
||||
struct waitqueue *wq;
|
||||
|
||||
/* Not yet handled. need spin_lock_irqs */
|
||||
BUG_ON(flags & WAKEUP_IRQ);
|
||||
|
||||
spin_lock(&task->waitlock);
|
||||
if (!task->waiting_on) {
|
||||
spin_unlock(&task->waitlock);
|
||||
|
||||
Reference in New Issue
Block a user