mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
mm: refactor pmm -> page
This commit is contained in:
+17
-17
@@ -1,7 +1,7 @@
|
||||
#include <kernel/init.h>
|
||||
#include <kernel/pci.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <kernel/block.h>
|
||||
#include <logging.h>
|
||||
|
||||
@@ -282,7 +282,7 @@ static int cmd_identify(ahci_t *ahci, int port, identify_t *results_phys) {
|
||||
.prdtl = 1,
|
||||
};
|
||||
|
||||
command_table_t *command_table_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
command_table_t *command_table_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (command_table_phys == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -300,7 +300,7 @@ static int cmd_identify(ahci_t *ahci, int port, identify_t *results_phys) {
|
||||
|
||||
int error = dispatch_command_and_wait(ahci, port, &command_header);
|
||||
|
||||
pmm_release(command_table_phys);
|
||||
mm_release_page(command_table_phys);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -308,7 +308,7 @@ static int cmd_identify(ahci_t *ahci, int port, identify_t *results_phys) {
|
||||
static void release_prdt(command_table_t *command_table, uint16_t prdtl) {
|
||||
for (int i = 0; i < prdtl; ++i) {
|
||||
void *address = (void *)((uint64_t)command_table->prdt[i].base_low | ((uint64_t)command_table->prdt[i].base_high << 32));
|
||||
pmm_release(address);
|
||||
mm_release_page(address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ static int setup_prdt(iovec_iterator_t *iterator, command_table_t *command_table
|
||||
__assert(page);
|
||||
// not block aligned
|
||||
if (page_remaining % 512) {
|
||||
pmm_release(page);
|
||||
mm_release_page(page);
|
||||
err = EINVAL;
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -367,7 +367,7 @@ static int rw(port_data_t *port_data, iovec_iterator_t *iterator, uintmax_t lba,
|
||||
.flags = (sizeof(fis_h2d_t) / 4) | (write ? CMDHDR_WRITE : 0),
|
||||
};
|
||||
|
||||
command_table_t *command_table_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
command_table_t *command_table_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (command_table_phys == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -412,7 +412,7 @@ static int rw(port_data_t *port_data, iovec_iterator_t *iterator, uintmax_t lba,
|
||||
done += do_count;
|
||||
}
|
||||
|
||||
pmm_release(command_table_phys);
|
||||
mm_release_page(command_table_phys);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -427,13 +427,13 @@ static int read(void *private, iovec_iterator_t *buffer, uintmax_t lba, size_t c
|
||||
|
||||
static void init_port(ahci_t *ahci, int port) {
|
||||
// send identify command
|
||||
identify_t *identify_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
identify_t *identify_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
__assert(identify_phys);
|
||||
identify_t *identify = MAKE_HHDM(identify_phys);
|
||||
memset(identify, 0, 512);
|
||||
|
||||
if (cmd_identify(ahci, port, identify_phys)) {
|
||||
pmm_release(identify_phys);
|
||||
mm_release_page(identify_phys);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -446,13 +446,13 @@ static void init_port(ahci_t *ahci, int port) {
|
||||
|
||||
if (logical_sector_size != 512) {
|
||||
printf("ahci%dp%d: unsupported logical sector size %lu\n", ahci->id, port, logical_sector_size);
|
||||
pmm_release(identify_phys);
|
||||
mm_release_page(identify_phys);
|
||||
return;
|
||||
}
|
||||
|
||||
ahci->port_data[port]->sector_count = (uint64_t)identify->lba48_size[0] | ((uint64_t)identify->lba48_size[1] << 16) |
|
||||
((uint64_t)identify->lba48_size[2] << 32) | ((uint64_t)identify->lba48_size[3] << 48);
|
||||
pmm_release(identify_phys);
|
||||
mm_release_page(identify_phys);
|
||||
|
||||
printf("ahci%dp%d: ATA drive with %lu sectors\n", ahci->id, port, ahci->port_data[port]->sector_count);
|
||||
|
||||
@@ -553,11 +553,11 @@ static void init_controller(pcienum_t *pci_enum) {
|
||||
ahci->ghc->ghc &= ~GHC_IE;
|
||||
|
||||
// initialize ports
|
||||
void *command_slot_mem = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *command_slot_mem = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
__assert(command_slot_mem);
|
||||
size_t command_slot_offset = 0;
|
||||
|
||||
void *fis_base_mem = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *fis_base_mem = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
__assert(fis_base_mem);
|
||||
size_t fis_base_offset = 0;
|
||||
FOR_EACH_PORT(ahci) {
|
||||
@@ -597,7 +597,7 @@ static void init_controller(pcienum_t *pci_enum) {
|
||||
command_slot_offset += 1024;
|
||||
if (command_slot_offset >= PAGE_SIZE) {
|
||||
// used up the page, allocate another
|
||||
command_slot_mem = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
command_slot_mem = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
__assert(command_slot_mem);
|
||||
command_slot_offset = 0;
|
||||
}
|
||||
@@ -612,7 +612,7 @@ static void init_controller(pcienum_t *pci_enum) {
|
||||
fis_base_offset += 256;
|
||||
if (fis_base_offset >= PAGE_SIZE) {
|
||||
// used up the page, allocate another
|
||||
fis_base_mem = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
fis_base_mem = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
__assert(fis_base_mem);
|
||||
fis_base_offset = 0;
|
||||
}
|
||||
@@ -653,9 +653,9 @@ static void init_controller(pcienum_t *pci_enum) {
|
||||
}
|
||||
|
||||
if (command_slot_offset == 0)
|
||||
pmm_release(command_slot_mem);
|
||||
mm_release_page(command_slot_mem);
|
||||
if (fis_base_offset == 0)
|
||||
pmm_release(fis_base_mem);
|
||||
mm_release_page(fis_base_mem);
|
||||
|
||||
// clear global interrupt status
|
||||
ahci->ghc->is = 0xffffffff;
|
||||
|
||||
+15
-15
@@ -2,7 +2,7 @@
|
||||
#include <logging.h>
|
||||
#include <kernel/vmm.h>
|
||||
#include <util.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/interrupt.h>
|
||||
#include <kernel/dpc.h>
|
||||
@@ -342,7 +342,7 @@ static int identify(nvmecontroller_t *controller, void *buffer, int what, int na
|
||||
entrypair_t pair = {0};
|
||||
PAIR_INIT(&pair, SUB_DW0_OPCODE_IDENTIFY, SUB_DW0_UNFUSED, SUB_DW0_PRP, namespace);
|
||||
|
||||
pair.sub.datapointer[0] = (uint64_t)pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
pair.sub.datapointer[0] = (uint64_t)mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (pair.sub.datapointer[0] == 0)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -351,7 +351,7 @@ static int identify(nvmecontroller_t *controller, void *buffer, int what, int na
|
||||
enqueueandwait(&controller->adminqueue, &pair);
|
||||
|
||||
memcpy(buffer, MAKE_HHDM(pair.sub.datapointer[0]), IDENTIFY_SIZE);
|
||||
pmm_release((void *)pair.sub.datapointer[0]);
|
||||
mm_release_page((void *)pair.sub.datapointer[0]);
|
||||
return COMP_CMDINFO_STATUS(pair.comp.cmdinfo) ? EIO : 0;
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ static int createiocompqueue(nvmecontroller_t *controller, queuedesc_t *desc, si
|
||||
size_t size = entrycount * sizeof(compentry_t);
|
||||
size_t pagesize = ROUND_UP(size, PAGE_SIZE) / PAGE_SIZE;
|
||||
|
||||
void *queuepages = pmm_alloc(pagesize, PMM_SECTION_DEFAULT);
|
||||
void *queuepages = mm_alloc_pages(pagesize, MEMORY_SECTION_DEFAULT);
|
||||
if (queuepages == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -415,7 +415,7 @@ static int createiocompqueue(nvmecontroller_t *controller, queuedesc_t *desc, si
|
||||
enqueueandwait(&controller->adminqueue, &pair);
|
||||
|
||||
if (COMP_CMDINFO_STATUS(pair.comp.cmdinfo)) {
|
||||
pmm_free(queuepages, pagesize);
|
||||
mm_release_range(queuepages, pagesize);
|
||||
return EIO;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ static int createiosubqueue(nvmecontroller_t *controller, queuedesc_t *desc, siz
|
||||
size_t size = entrycount * sizeof(subentry_t);
|
||||
size_t pagesize = ROUND_UP(size, PAGE_SIZE) / PAGE_SIZE;
|
||||
|
||||
void *queuepages = pmm_alloc(pagesize, PMM_SECTION_DEFAULT);
|
||||
void *queuepages = mm_alloc_pages(pagesize, MEMORY_SECTION_DEFAULT);
|
||||
if (queuepages == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -447,7 +447,7 @@ static int createiosubqueue(nvmecontroller_t *controller, queuedesc_t *desc, siz
|
||||
enqueueandwait(&controller->adminqueue, &pair);
|
||||
|
||||
if (COMP_CMDINFO_STATUS(pair.comp.cmdinfo)) {
|
||||
pmm_free(queuepages, pagesize);
|
||||
mm_release_range(queuepages, pagesize);
|
||||
return EIO;
|
||||
}
|
||||
|
||||
@@ -510,15 +510,15 @@ static int iowrite(nvmenamespace_t *namespace, uint64_t prp[2], uint64_t lba, ui
|
||||
#define PAGES_IN_PRP_PAGE (PAGE_SIZE / sizeof(uint64_t))
|
||||
|
||||
static void free_prps(uint64_t prp[2], bool has_list) {
|
||||
pmm_release((void *)ROUND_DOWN(prp[0], PAGE_SIZE));
|
||||
mm_release_page((void *)ROUND_DOWN(prp[0], PAGE_SIZE));
|
||||
if (has_list) {
|
||||
uint64_t *prp_list = MAKE_HHDM((uint64_t *)prp[1]);
|
||||
for (int i = 0; prp_list[i] && i < PAGES_IN_PRP_PAGE; ++i)
|
||||
pmm_release((void *)prp_list[i]);
|
||||
mm_release_page((void *)prp_list[i]);
|
||||
}
|
||||
|
||||
if (prp[1])
|
||||
pmm_release((void *)prp[1]);
|
||||
mm_release_page((void *)prp[1]);
|
||||
}
|
||||
|
||||
// sets up prps based on an iovec iterator.
|
||||
@@ -576,7 +576,7 @@ static int setup_prps(nvmenamespace_t *namespace, iovec_iterator_t *iovec_iterat
|
||||
}
|
||||
|
||||
// we have to allocate a proper prp list now
|
||||
uint64_t *prp_list_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
uint64_t *prp_list_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (prp_list_phys == NULL) {
|
||||
// out of memory, we'll have to make do with 2 pages
|
||||
*has_list = false;
|
||||
@@ -603,7 +603,7 @@ static int setup_prps(nvmenamespace_t *namespace, iovec_iterator_t *iovec_iterat
|
||||
if (page_offset || page_remaining % namespace->blocksize) {
|
||||
prp_list[i] = 0;
|
||||
free_prps(prp, true);
|
||||
pmm_release(page);
|
||||
mm_release_page(page);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
@@ -777,7 +777,7 @@ static void initcontroller(pcienum_t *e) {
|
||||
|
||||
bar0->aqattr = aqattr;
|
||||
|
||||
void *acq = pmm_alloc(2, PMM_SECTION_DEFAULT);
|
||||
void *acq = mm_alloc_pages(2, MEMORY_SECTION_DEFAULT);
|
||||
__assert(acq);
|
||||
memset(MAKE_HHDM(acq), 0, PAGE_SIZE * 2);
|
||||
void *asq = (void *)((uintptr_t)acq + PAGE_SIZE);
|
||||
@@ -793,7 +793,7 @@ static void initcontroller(pcienum_t *e) {
|
||||
|
||||
if (STATUS_FATAL(bar0->status)) {
|
||||
printf("nvme: controller returned fatal while initializing\n");
|
||||
pmm_free(acq, 2);
|
||||
mm_release_range(acq, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -835,7 +835,7 @@ static void initcontroller(pcienum_t *e) {
|
||||
if (controllerid->type != 0 && controllerid->type != CONTROLLER_TYPE_IO) {
|
||||
printf("nvme: controller type not supported\n");
|
||||
// FIXME free ISRs
|
||||
pmm_free(acq, 2);
|
||||
mm_release_range(acq, 2);
|
||||
free(controllerid);
|
||||
free(controller);
|
||||
return;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <kernel/slab.h>
|
||||
#include <semaphore.h>
|
||||
#include <kernel/block.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/page.h>
|
||||
#include <string.h>
|
||||
|
||||
#define QUEUE_MAX_SIZE 144
|
||||
@@ -100,7 +100,7 @@ static void vioblk_enqueue(vioblkdev_t *blkdev, requestheader_t *headerphys, voi
|
||||
}
|
||||
|
||||
static int vioblk_rw(vioblkdev_t *blkdev, iovec_iterator_t *iovec_iterator, uintmax_t lba, size_t count, bool write) {
|
||||
void *physpage = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
void *physpage = mm_alloc_page(MEMORY_SECTION_DEFAULT);
|
||||
if (physpage == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -133,7 +133,7 @@ static int vioblk_rw(vioblkdev_t *blkdev, iovec_iterator_t *iovec_iterator, uint
|
||||
|
||||
vioblk_enqueue(blkdev, header, (void *)((uintptr_t)page + page_offset), PAGE_SIZE, status, write);
|
||||
|
||||
pmm_release(page);
|
||||
mm_release_page(page);
|
||||
|
||||
// if we didnt use the whole space in the page, set the iterator back a bit
|
||||
size_t diff_between_available_and_used = page_remaining - docount * 512;
|
||||
@@ -150,7 +150,7 @@ static int vioblk_rw(vioblkdev_t *blkdev, iovec_iterator_t *iovec_iterator, uint
|
||||
done += docount;
|
||||
}
|
||||
|
||||
pmm_release(physpage);
|
||||
mm_release_page(physpage);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user