paging.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Paging: identity-map RAM + the VESA LFB and enable CR0.PG (4 MB pages). */
  2. #ifndef PAGING_H
  3. #define PAGING_H
  4. void paging_init(void);
  5. /* Re-apply the framebuffer page types (after GPU BAR mappings that cover it). */
  6. void paging_lfb_refresh(void);
  7. /* 1 when the LFB is mapped for write-combining. */
  8. int paging_lfb_wc(void);
  9. /* Map a physical window identity-mapped with caching enabled (4 MB pages).
  10. * Used for the stolen-VRAM alias, which is ordinary DRAM; the effective type
  11. * is whatever the MTRRs say (write-combining when we added an entry). */
  12. void paging_map_ram(unsigned int base, unsigned int size);
  13. /* Physical address of the bootstrap (current) page directory. */
  14. unsigned int paging_current_cr3(void);
  15. /* Allocate a fresh page directory that clones the kernel identity map and
  16. * return its physical address (0 on out-of-memory). */
  17. unsigned int paging_new_directory(void);
  18. /* Page-table entry flags (4 KB pages). */
  19. #define PTE_PRESENT 0x001
  20. #define PTE_WRITABLE 0x002
  21. #define PTE_USER 0x004
  22. /* Map one 4 KB page (va -> phys) in page directory `cr3`, allocating a page
  23. * table if needed. Returns 1 on success, 0 on out-of-memory. */
  24. int paging_map_page(unsigned int cr3, unsigned int va, unsigned int phys,
  25. unsigned int flags);
  26. /* Physical address mapped at `va`, or 0 when the page is not present. */
  27. unsigned int paging_page_phys(unsigned int cr3, unsigned int va);
  28. /* Clear one 4 KB page (va) in page directory `cr3` (no-op when the page
  29. * table is absent). */
  30. void paging_unmap_page(unsigned int cr3, unsigned int va);
  31. /* Release the user mappings in [va, va+size): clear the PTEs, free empty page
  32. * tables and, when `free_phys` is set, free the mapped physical pages. With
  33. * `free_phys` clear the pages belong to someone else (e.g. a mapped window
  34. * canvas) and only the mapping/page tables are released. Used by the process
  35. * reaper; ranges should cover the user-owned mappings only. */
  36. void paging_release_user_range(unsigned int cr3, unsigned int va,
  37. unsigned int size, int free_phys);
  38. /* 1 when every page in [va, va+size) is a user-accessible 4 KB mapping in
  39. * `cr3` (and writable when `write` is set). Syscall services use this before
  40. * touching a pointer supplied by ring 3. */
  41. int paging_user_range_ok(unsigned int cr3, unsigned int va,
  42. unsigned int size, int write);
  43. /* Identity-map an MMIO range (e.g. a GPU register aperture) uncacheable into
  44. * the current page directory. Uses 4 MB pages; the range is rounded up to a
  45. * whole number of 4 MB pages. */
  46. void paging_map_mmio(unsigned int phys_base, unsigned int size);
  47. /* Same, but into an explicit page directory (used to update per-process
  48. * directories; see process_map_mmio_all()). */
  49. void paging_map_mmio_cr3(unsigned int cr3, unsigned int phys_base,
  50. unsigned int size);
  51. #endif