Not the cleanest, but better than before...
This commit is contained in:
parent
b824abf250
commit
e5a8ed3a68
@ -19,6 +19,9 @@ uintptr_t placement_pointer = (uintptr_t)&end;
|
||||
uintptr_t heap_end = (uintptr_t)NULL;
|
||||
uintptr_t kernel_heap_alloc_point = KERNEL_HEAP_INIT;
|
||||
|
||||
static volatile uint8_t frame_alloc_lock = 0;
|
||||
uint32_t first_n_frames(int n);
|
||||
|
||||
void
|
||||
kmalloc_startat(
|
||||
uintptr_t address
|
||||
@ -43,6 +46,23 @@ kmalloc_real(
|
||||
address = malloc(size);
|
||||
}
|
||||
if (phys) {
|
||||
if (align && size > 0x1000) {
|
||||
for (uintptr_t i = (uintptr_t)address; i < (uintptr_t)address + size; i += 0x1000) {
|
||||
clear_frame(map_to_physical(i));
|
||||
}
|
||||
/* XXX This is going to get touchy... */
|
||||
spin_lock(&frame_alloc_lock);
|
||||
uint32_t index = first_n_frames((size + 0xFFF) / 0x1000);
|
||||
if (index == 0xFFFFFFFF) {
|
||||
return 0;
|
||||
}
|
||||
for (unsigned int i = 0; i < (size + 0xFFF) / 0x1000; ++i) {
|
||||
set_frame((index + i) * 0x1000);
|
||||
page_t * page = get_page((uintptr_t)address + (i * 0x1000),0,kernel_directory);
|
||||
page->frame = index + i;
|
||||
}
|
||||
spin_unlock(&frame_alloc_lock);
|
||||
}
|
||||
*phys = map_to_physical((uintptr_t)address);
|
||||
}
|
||||
return (uintptr_t)address;
|
||||
@ -135,6 +155,21 @@ uint32_t test_frame(uintptr_t frame_addr) {
|
||||
return (frames[index] & (0x1 << offset));
|
||||
}
|
||||
|
||||
uint32_t first_n_frames(int n) {
|
||||
for (uint32_t i = 0; i < nframes * 0x1000; i += 0x1000) {
|
||||
int bad = 0;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
if (test_frame(i + 0x1000 * j)) {
|
||||
bad = j+1;
|
||||
}
|
||||
}
|
||||
if (!bad) {
|
||||
return i / 0x1000;
|
||||
}
|
||||
}
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
uint32_t first_frame(void) {
|
||||
uint32_t i, j;
|
||||
|
||||
@ -163,8 +198,6 @@ uint32_t first_frame(void) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static volatile uint8_t frame_alloc_lock = 0;
|
||||
|
||||
void
|
||||
alloc_frame(
|
||||
page_t *page,
|
||||
|
@ -174,28 +174,14 @@ DEFINE_SHELL_FUNCTION(rtl, "rtl8139 experiments") {
|
||||
}
|
||||
}
|
||||
|
||||
rtl_rx_buffer = (uint8_t *)kvmalloc(0x3000);
|
||||
|
||||
/* This is a terrible hack, we need to be able to allocate
|
||||
* linear pages from, say, sbrk or similar.... */
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x0000, 1, current_directory), 1, 0, 0x20000000);
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x1000, 1, current_directory), 1, 0, 0x20001000);
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x2000, 1, current_directory), 1, 0, 0x20002000);
|
||||
|
||||
/* Also map them in the kernel directory */
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x0000, 1, kernel_directory), 1, 0, 0x20000000);
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x1000, 1, kernel_directory), 1, 0, 0x20001000);
|
||||
dma_frame(get_page((uintptr_t)rtl_rx_buffer + 0x2000, 1, kernel_directory), 1, 0, 0x20002000);
|
||||
|
||||
rtl_rx_buffer = (uint8_t *)kvmalloc_p(0x3000, &rtl_rx_phys);
|
||||
memset(rtl_rx_buffer, 0x00, 0x3000);
|
||||
|
||||
rtl_rx_phys = 0x20000000;
|
||||
|
||||
fprintf(tty, "Buffers:\n");
|
||||
fprintf(tty, " rx 0x%x [phys 0x%x:0x%x]\n", rtl_rx_buffer, rtl_rx_phys, map_to_physical((uintptr_t)rtl_rx_buffer));
|
||||
fprintf(tty, " rx 0x%x [phys 0x%x and 0x%x and 0x%x]\n", rtl_rx_buffer, rtl_rx_phys, map_to_physical((uintptr_t)rtl_rx_buffer + 0x1000), map_to_physical((uintptr_t)rtl_rx_buffer + 0x2000));
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
fprintf(tty, " tx 0x%x [phys 0x%x:0x%x]\n", rtl_tx_buffer[i], rtl_tx_phys[i], map_to_physical((uintptr_t)rtl_tx_buffer[i]));
|
||||
fprintf(tty, " tx 0x%x [phys 0x%x]\n", rtl_tx_buffer[i], rtl_tx_phys[i]);
|
||||
}
|
||||
|
||||
fprintf(tty, "Initializing receive buffer.\n");
|
||||
|
Loading…
Reference in New Issue
Block a user