mm: refactor pmm -> page

This commit is contained in:
Matheus
2026-07-01 11:56:06 -03:00
parent 39e63c3e44
commit 6f8700e678
35 changed files with 226 additions and 226 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
#include <kernel/interrupt.h>
#include <kernel/scheduler.h>
#include <kernel/alloc.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/pci.h>
#include <kernel/timekeeper.h>
#include <arch/cpu.h>
+4 -4
View File
@@ -2,7 +2,7 @@
#include <logging.h>
#include <kernel/hda.h>
#include <kernel/init.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <list.h>
#include <semaphore.h>
#include <kernel/alloc.h>
@@ -376,12 +376,12 @@ static hda_stream_t *hda_allocate_output_stream(hda_t *hda) {
hda->streams[stream_n] = stream;
hda->regs->intctl |= (1 << stream_n);
stream->bdl_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
stream->bdl_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(stream->bdl_phys);
hda_bdl_entry_t *bdl = MAKE_HHDM(stream->bdl_phys);
for (int i = 0; i < HDA_BUFFER_PAGE_COUNT; ++i) {
void *phys_page = pmm_allocpage(PMM_SECTION_DEFAULT);
void *phys_page = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(phys_page);
memset(MAKE_HHDM(phys_page), 0, PAGE_SIZE);
@@ -907,7 +907,7 @@ static void initcontroller(pcienum_t *e) {
sched_sleep_us(1000);
// we can fit all of corb/rirb in a single page
void *corb_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *corb_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(corb_phys);
void *corb = MAKE_HHDM(corb_phys);
memset(corb, 0, PAGE_SIZE);
+17 -17
View File
@@ -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
View File
@@ -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;
+4 -4
View File
@@ -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;
}
+4 -4
View File
@@ -5,7 +5,7 @@
#include <kernel/alloc.h>
#include <kernel/devfs.h>
#include <arch/cpu.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/usercopy.h>
#include <kernel/term.h>
#include <kernel/init.h>
@@ -147,14 +147,14 @@ static int mmap(int minor, void *addr, uintmax_t offset, int flags) {
return arch_mmu_map(current_vmm_context()->pagetable, FROM_HHDM((void *)((uintptr_t)fbs[minor]->address + offset)), addr, vnodeflagstommuflags(flags)) ? 0 : ENOMEM;
} else {
size_t size = offset + PAGE_SIZE < end ? PAGE_SIZE : end - offset;
paddr = pmm_allocpage(PMM_SECTION_DEFAULT);
paddr = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (paddr == NULL)
return ENOMEM;
memcpy(MAKE_HHDM(paddr), (void *)((uintptr_t)fbs[minor]->address + offset), size);
if (arch_mmu_map(current_vmm_context()->pagetable, paddr, addr, vnodeflagstommuflags(flags) | ARCH_MMU_FLAGS_WC) == false) {
pmm_release(paddr);
mm_release_page(paddr);
return ENOMEM;
}
@@ -168,7 +168,7 @@ static int munmap(int minor, void *addr, uintmax_t offset, int flags) {
arch_mmu_unmap(current_vmm_context()->pagetable, addr);
arch_mmu_invalidate_range(addr, PAGE_SIZE);
if (release)
pmm_release(phys);
mm_release_page(phys);
return 0;
}
+1 -1
View File
@@ -1,6 +1,6 @@
#include <kernel/virtio.h>
#include <logging.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/eth.h>
#include <kernel/net.h>
#include <hashtable.h>
+6 -6
View File
@@ -4,7 +4,7 @@
#include <arch/io.h>
#include <kernel/net.h>
#include <kernel/scheduler.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/eth.h>
#include <kernel/interrupt.h>
@@ -198,7 +198,7 @@ static int rtl8169_sendpacket(netdev_t *internal, netdesc_t desc, mac_t target,
static int rtl8169_allocdesc(netdev_t *netdev, size_t requested_size, netdesc_t *desc) {
__assert(requested_size <= netdev->mtu);
size_t true_size = sizeof(ethframe_t) + requested_size;
void *physical = pmm_allocpage(PMM_SECTION_DEFAULT);
void *physical = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (physical == NULL)
return ENOMEM;
@@ -209,7 +209,7 @@ static int rtl8169_allocdesc(netdev_t *netdev, size_t requested_size, netdesc_t
}
static int rtl8169_freedesc(netdev_t *netdev, netdesc_t *desc) {
pmm_release(FROM_HHDM(desc->address));
mm_release_page(FROM_HHDM(desc->address));
return 0;
}
@@ -275,9 +275,9 @@ static void init_controller(pcienum_t *pci_enum) {
printf("rtl8169.%d: %x:%x:%x:%x:%x:%x\n", id, mac.address[0], mac.address[1], mac.address[2], mac.address[3], mac.address[4], mac.address[5]);
// set up descriptor rings
descriptor_t *tx_ring_phys = pmm_alloc(ROUND_UP(sizeof(descriptor_t) * TX_DESCRIPTOR_COUNT, PAGE_SIZE) / PAGE_SIZE, PMM_SECTION_DEFAULT);
descriptor_t *tx_ring_phys = mm_alloc_pages(ROUND_UP(sizeof(descriptor_t) * TX_DESCRIPTOR_COUNT, PAGE_SIZE) / PAGE_SIZE, MEMORY_SECTION_DEFAULT);
__assert(tx_ring_phys);
descriptor_t *rx_ring_phys = pmm_alloc(ROUND_UP(sizeof(descriptor_t) * RX_DESCRIPTOR_COUNT, PAGE_SIZE) / PAGE_SIZE, PMM_SECTION_DEFAULT);
descriptor_t *rx_ring_phys = mm_alloc_pages(ROUND_UP(sizeof(descriptor_t) * RX_DESCRIPTOR_COUNT, PAGE_SIZE) / PAGE_SIZE, MEMORY_SECTION_DEFAULT);
__assert(rx_ring_phys);
descriptor_t *tx_ring = MAKE_HHDM(tx_ring_phys);
@@ -288,7 +288,7 @@ static void init_controller(pcienum_t *pci_enum) {
// fill rx descriptors
// XXX figure out a better way of doing this
void *rx_buffer = pmm_alloc(ROUND_UP((RX_DESCRIPTOR_COUNT * RX_BUFFER_SIZE), PAGE_SIZE) / PAGE_SIZE, PMM_SECTION_DEFAULT);
void *rx_buffer = mm_alloc_pages(ROUND_UP((RX_DESCRIPTOR_COUNT * RX_BUFFER_SIZE), PAGE_SIZE) / PAGE_SIZE, MEMORY_SECTION_DEFAULT);
__assert(rx_buffer);
for (int i = 0; i < RX_DESCRIPTOR_COUNT; ++i) {
+1 -1
View File
@@ -285,7 +285,7 @@ static int udp_recv(socket_t *socket, sockdesc_t *sockdesc) {
__assert(sockdesc->donecount == copycount);
// remove the message if not asked to peek
// remove the message if not asked to peek TODO: if sonecount != header.length, add truncate flag. also do the same to localsocket
if ((flags & SOCKET_RECV_FLAGS_PEEK) == 0)
ringbuffer_truncate(&udpsocket->ringbuffer, sizeof(header) + header.length);
+4 -4
View File
@@ -1,6 +1,6 @@
#include <kernel/virtio.h>
#include <logging.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/eth.h>
#include <kernel/net.h>
#include <hashtable.h>
@@ -84,7 +84,7 @@ static void tx_irq(isr_t *isr, context_t *context) {
static int vionet_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc) {
__assert(requestedsize <= netdev->mtu);
size_t truesize = PREFIX_SIZE + requestedsize;
void *phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (phys == NULL)
return ENOMEM;
@@ -95,7 +95,7 @@ static int vionet_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *d
}
static int vionet_freedesc(netdev_t *netdev, netdesc_t *desc) {
pmm_release(FROM_HHDM(desc->address));
mm_release_page(FROM_HHDM(desc->address));
return 0;
}
@@ -210,7 +210,7 @@ int vionet_newdevice(viodevice_t *viodevice) {
// XXX is the memory saving of allocating hundreds of KiBs of contiguous physical memory really worth it?
// the system literally might not have enough (contiguous) physical memory for this, especially considering
// this device is initialised deeper into the boot process.
void *receivebuffer = pmm_alloc(ROUND_UP((rxsize * BUFFER_SIZE), PAGE_SIZE) / PAGE_SIZE, PMM_SECTION_DEFAULT);
void *receivebuffer = mm_alloc_pages(ROUND_UP((rxsize * BUFFER_SIZE), PAGE_SIZE) / PAGE_SIZE, MEMORY_SECTION_DEFAULT);
__assert(receivebuffer);
for (int i = 0; i < rxsize; ++i) {
+2 -2
View File
@@ -6,7 +6,7 @@
#include <printf.h>
#include <logging.h>
#include <string.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <arch/mmu.h>
#include <kernel/init.h>
#include <logging.h>
@@ -31,7 +31,7 @@ static void *internalalloc(size_t n) {
#else
// TODO make more efficient. works for now
static void *internalalloc(size_t n) {
void *addr = pmm_alloc(n / PAGE_SIZE + 1, PMM_SECTION_DEFAULT);
void *addr = mm_alloc_pages(n / PAGE_SIZE + 1, MEMORY_SECTION_DEFAULT);
__assert(addr);
return MAKE_HHDM(addr);
}
+1 -1
View File
@@ -1,5 +1,5 @@
#include <kernel/alloc.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/usb.h>
#include <logging.h>
+6 -6
View File
@@ -4,7 +4,7 @@
#include <kernel/init.h>
#include <kernel/interrupt.h>
#include <kernel/pci.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/usb.h>
#include <kernel/vmm.h>
#include <list.h>
@@ -28,7 +28,7 @@ static void xhci_release_submission_page(xhci_submission_t *submission) {
uint32_t cmd_type = xhci_trb_type(&submission->cmd_trb);
if ((cmd_type == TRB_NORMAL || cmd_type == TRB_DATA_STAGE) && submission->cmd_trb.parameters != 0)
pmm_release((void *)(submission->cmd_trb.parameters & ~(PAGE_SIZE - 1)));
mm_release_page((void *)(submission->cmd_trb.parameters & ~(PAGE_SIZE - 1)));
}
static bool xhci_reclaim_submission_slot(xhci_submission_t *slot, xhci_submission_t *submission) {
@@ -614,7 +614,7 @@ static int xhci_ctrl_start(usb_ctrl_t *ctrl) {
xhci->opregs->config = max_slots;
// Set up the Device Context Base Address Array.
void *dcbaa_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *dcbaa_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(dcbaa_phys);
uint64_t *dcbaa_virt = MAKE_HHDM(dcbaa_phys);
@@ -629,12 +629,12 @@ static int xhci_ctrl_start(usb_ctrl_t *ctrl) {
printf("xhci: setting up %u scratchpad buffers\n", max_scratchpads);
__assert(max_scratchpads < PAGE_SIZE / sizeof(uint64_t));
void *scratchpad_array_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *scratchpad_array_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(scratchpad_array_phys);
uint64_t *scratchpad_array_virt = MAKE_HHDM(scratchpad_array_phys);
for (uint32_t i = 0; i < max_scratchpads; i++) {
void *scratchpad_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *scratchpad_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(scratchpad_phys);
memset(MAKE_HHDM(scratchpad_phys), 0, PAGE_SIZE);
scratchpad_array_virt[i] = (uint64_t)scratchpad_phys;
@@ -650,7 +650,7 @@ static int xhci_ctrl_start(usb_ctrl_t *ctrl) {
xhci->opregs->crcr = (uint64_t)xhci->command_ring.ring_phys | XHCI_CRCR_RCS;
// Set up Event Ring Segment Table.
void *erst_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *erst_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
__assert(erst_phys);
xhci_erst_entry_t *erst_virt = MAKE_HHDM(erst_phys);
+8 -8
View File
@@ -1,7 +1,7 @@
#include <kernel/xhci.h>
#include <kernel/alloc.h>
#include <errno.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <logging.h>
#include <util.h>
@@ -132,9 +132,9 @@ static void xhci_release_device_resources(xhci_ctrl_t *xhci, xhci_device_t *dev)
}
if (dev->input_ctx_phys)
pmm_release(dev->input_ctx_phys);
mm_release_page(dev->input_ctx_phys);
if (dev->device_ctx_phys)
pmm_release(dev->device_ctx_phys);
mm_release_page(dev->device_ctx_phys);
free(dev);
}
@@ -394,22 +394,22 @@ static int xhci_ctrl_address_device(usb_ctrl_t *ctrl, usb_hub_t *hub, uint8_t po
if (xhci_dev == NULL)
return ENOMEM;
void *device_ctx_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *device_ctx_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (device_ctx_phys == NULL) {
free(xhci_dev);
return ENOMEM;
}
void *input_ctx_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *input_ctx_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (input_ctx_phys == NULL) {
pmm_release(device_ctx_phys);
mm_release_page(device_ctx_phys);
free(xhci_dev);
return ENOMEM;
}
if (xhci_alloc_ring(xhci, &xhci_dev->ep_rings[0], false)) {
pmm_release(input_ctx_phys);
pmm_release(device_ctx_phys);
mm_release_page(input_ctx_phys);
mm_release_page(device_ctx_phys);
free(xhci_dev);
return ENOMEM;
}
+4 -4
View File
@@ -1,11 +1,11 @@
#include <kernel/xhci.h>
#include <kernel/alloc.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <errno.h>
#include <logging.h>
int xhci_alloc_ring(xhci_ctrl_t *ctrl, xhci_ring_t *r, bool event_ring) {
void *ring_phys = pmm_allocpage(PMM_SECTION_DEFAULT);
void *ring_phys = mm_alloc_page(MEMORY_SECTION_DEFAULT);
if (ring_phys == NULL)
return ENOMEM;
@@ -24,7 +24,7 @@ int xhci_alloc_ring(xhci_ctrl_t *ctrl, xhci_ring_t *r, bool event_ring) {
} else {
r->submissions = alloc(sizeof(xhci_submission_t) * r->size);
if (r->submissions == NULL) {
pmm_release(ring_phys);
mm_release_page(ring_phys);
return ENOMEM;
}
@@ -37,7 +37,7 @@ int xhci_alloc_ring(xhci_ctrl_t *ctrl, xhci_ring_t *r, bool event_ring) {
}
void xhci_free_ring(xhci_ring_t *ring) {
pmm_release(ring->ring_phys);
mm_release_page(ring->ring_phys);
free(ring->submissions);
}
+5 -5
View File
@@ -2,7 +2,7 @@
#include <errno.h>
#include <kernel/alloc.h>
#include <kernel/vmm.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <logging.h>
typedef struct {
@@ -27,7 +27,7 @@ static int xhci_count_sg_trbs(iovec_iterator_t *iov, size_t total_size, size_t *
if (page == NULL)
return EFAULT;
pmm_release(page);
mm_release_page(page);
done += min(page_remaining, total_size - done);
count++;
@@ -64,7 +64,7 @@ int xhci_data_xfer(xhci_ctrl_t *xhci, xhci_device_t *dev, usb_xfer_t *xfer, xhci
xhci_trb_t trb = {0};
if (xfer->flags & USB_XFER_FLAG_BUFFER_PHYSICAL) {
pmm_hold(xfer->data - page_offset);
mm_hold_page(xfer->data - page_offset);
trb.parameters = (uint64_t)xfer->data;
} else {
// This should never be called with user pages. Doing so is a bug. For user-fronting code, use
@@ -187,7 +187,7 @@ int xhci_sg_data_xfer(xhci_ctrl_t *xhci, xhci_ring_t *ring, xhci_device_t *dev,
fail:
for (size_t i = 0; i < prepared_count; ++i)
pmm_release(prepared[i].page);
mm_release_page(prepared[i].page);
free(prepared);
xhci_ring_unreserve(ring, trb_count);
return err;
@@ -239,7 +239,7 @@ int xhci_control_xfer(xhci_ctrl_t *xhci, xhci_device_t *dev, usb_xfer_t *xfer, x
if (xfer->data_length) {
if (xfer->flags & USB_XFER_FLAG_BUFFER_PHYSICAL) {
pmm_hold(xfer->data - page_offset);
mm_hold_page(xfer->data - page_offset);
data_trb.parameters = (uint64_t)xfer->data;
} else {
void *page = vmm_getphysical(xfer->data - page_offset, VMM_GET_PHYSICAL_FLAGS_HOLD);
+2 -2
View File
@@ -2,7 +2,7 @@
#include <kernel/pci.h>
#include <logging.h>
#include <kernel/alloc.h>
#include <kernel/pmm.h>
#include <kernel/page.h>
#include <kernel/init.h>
#define VIRTIO_VENDOR 0x1af4
@@ -63,7 +63,7 @@ void *virtio_createqueue(viodevice_t *viodevice, vioqueue_t *vioqueue, int queue
size_t bytesize = VIO_QUEUE_BYTESIZE(size);
size_t pagesize = ROUND_UP(bytesize, PAGE_SIZE) / PAGE_SIZE;
void *queuephys = pmm_alloc(pagesize, PMM_SECTION_DEFAULT);
void *queuephys = mm_alloc_pages(pagesize, MEMORY_SECTION_DEFAULT);
__assert(queuephys);
memset(MAKE_HHDM(queuephys), 0, bytesize);