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
+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);