kv2: initialize memory manager, early pci devices
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
e5b55a6ba5
commit
a252a3f8e9
58 changed files with 1270 additions and 505 deletions
61
lib/list.c
Normal file
61
lib/list.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include "kernel/spinlock.h"
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/list.h>
|
||||
|
||||
static mem_cache_t *list_cache;
|
||||
|
||||
void list_create(list_t *list)
|
||||
{
|
||||
list->head = NULL;
|
||||
list->tail = NULL;
|
||||
}
|
||||
|
||||
list_item_t *list_insert(list_t *list, void *item)
|
||||
{
|
||||
spinlock_acquire(&list->lock);
|
||||
list_item_t *ret = slab_alloc(list_cache);
|
||||
ret->ptr = item;
|
||||
ret->list = list;
|
||||
ret->next = NULL;
|
||||
ret->prev = NULL;
|
||||
|
||||
if (!list->head)
|
||||
list->head = ret;
|
||||
|
||||
if (list->tail) {
|
||||
list->tail->next = ret;
|
||||
ret->prev = list->tail;
|
||||
}
|
||||
|
||||
list->tail = ret;
|
||||
spinlock_release(&list->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void list_remove(list_item_t *item)
|
||||
{
|
||||
list_t *list = item->list;
|
||||
|
||||
spinlock_acquire(&list->lock);
|
||||
if (item == list->head)
|
||||
list->head = item->next;
|
||||
if (item == list->tail)
|
||||
list->tail = item->prev;
|
||||
|
||||
if (item->next)
|
||||
item->next->prev = item->prev;
|
||||
|
||||
if (item->prev)
|
||||
item->prev->next = item->next;
|
||||
spinlock_release(&list->lock);
|
||||
|
||||
slab_free(list_cache, item);
|
||||
}
|
||||
|
||||
void list_init()
|
||||
{
|
||||
list_cache = slab_create("list_cache", sizeof(list_item_t), 64 * KB, 0x8);
|
||||
}
|
||||
Loading…
Reference in a new issue