git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: use a more decent physical memory map
[lunaix-os.git]
/
lunaix-os
/
kernel
/
mm
/
cake.c
diff --git
a/lunaix-os/kernel/mm/cake.c
b/lunaix-os/kernel/mm/cake.c
index 5aa9bef0d97a4e259c9f666431fa71c12a5065fb..0e8f3341c5b8a95a23e47ba7925015aa1d0ab8b5 100644
(file)
--- a/
lunaix-os/kernel/mm/cake.c
+++ b/
lunaix-os/kernel/mm/cake.c
@@
-28,11
+28,11
@@
struct llist_header piles = { .next = &piles, .prev = &piles };
void*
__alloc_cake(unsigned int cake_pg)
{
void*
__alloc_cake(unsigned int cake_pg)
{
-
uintptr_t pa =
pmm_alloc_cpage(KERNEL_PID, cake_pg, 0);
+
ptr_t pa = (ptr_t)
pmm_alloc_cpage(KERNEL_PID, cake_pg, 0);
if (!pa) {
return NULL;
}
if (!pa) {
return NULL;
}
- return vm
m_vmap(pa, cake_pg * PG_SIZE, PG_PREM_RW
);
+ return vm
ap(pa, cake_pg * PG_SIZE, PG_PREM_RW, 0
);
}
struct cake_s*
}
struct cake_s*
@@
-44,9
+44,11
@@
__new_cake(struct cake_pile* pile)
return NULL;
}
return NULL;
}
-
in
t max_piece = pile->pieces_per_cake;
+
u32_
t max_piece = pile->pieces_per_cake;
- cake->first_piece = (void*)((uintptr_t)cake + pile->offset);
+ assert(max_piece);
+
+ cake->first_piece = (void*)((ptr_t)cake + pile->offset);
cake->next_free = 0;
pile->cakes_count++;
cake->next_free = 0;
pile->cakes_count++;
@@
-120,6
+122,12
@@
cake_new_pile(char* name,
return pile;
}
return pile;
}
+void
+cake_set_constructor(struct cake_pile* pile, pile_cb ctor)
+{
+ pile->ctor = ctor;
+}
+
void*
cake_grab(struct cake_pile* pile)
{
void*
cake_grab(struct cake_pile* pile)
{
@@
-147,8
+155,14
@@
cake_grab(struct cake_pile* pile)
llist_append(&pile->partial, &pos->cakes);
}
llist_append(&pile->partial, &pos->cakes);
}
- return (void*)((uintptr_t)pos->first_piece +
- found_index * pile->piece_size);
+ void* ptr =
+ (void*)((ptr_t)pos->first_piece + found_index * pile->piece_size);
+
+ if (pile->ctor) {
+ pile->ctor(pile, ptr);
+ }
+
+ return ptr;
}
int
}
int
@@
-164,8
+178,7
@@
cake_release(struct cake_pile* pile, void* area)
if (pos->first_piece > area) {
continue;
}
if (pos->first_piece > area) {
continue;
}
- piece_index =
- (uintptr_t)(area - pos->first_piece) / pile->piece_size;
+ piece_index = (ptr_t)(area - pos->first_piece) / pile->piece_size;
if (piece_index < pile->pieces_per_cake) {
goto found;
}
if (piece_index < pile->pieces_per_cake) {
goto found;
}
@@
-188,4
+201,10
@@
found:
}
return 1;
}
return 1;
+}
+
+void
+cake_ctor_zeroing(struct cake_pile* pile, void* piece)
+{
+ memset(piece, 0, pile->piece_size);
}
\ No newline at end of file
}
\ No newline at end of file