paging.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* Clear translation controls a BIOS protected-mode call may have left set
  6. * (CR4.PAE/PGE/LA57/PCIDE, EFER.LME) before this 32-bit kernel enables its
  7. * own page directory. Called by paging_init(); the AP trampoline applies
  8. * the same policy inline. */
  9. void paging_prepare_cpu(void);
  10. /* Re-apply the framebuffer page types (after GPU BAR mappings that cover it). */
  11. void paging_lfb_refresh(void);
  12. /* 1 when the LFB is mapped for write-combining. */
  13. int paging_lfb_wc(void);
  14. /* Map a physical window identity-mapped with caching enabled (4 MB pages).
  15. * Used for the stolen-VRAM alias, which is ordinary DRAM; the effective type
  16. * is whatever the MTRRs say (write-combining when we added an entry). */
  17. void paging_map_ram(unsigned int base, unsigned int size);
  18. /* Physical address of the page directory currently loaded in CR3. On SMP this
  19. * is per-CPU; on one CPU it is the running process's directory. */
  20. unsigned int paging_current_cr3(void);
  21. /* Physical address of the bootstrap/kernel page directory that new process
  22. * directories clone. */
  23. unsigned int paging_kernel_cr3(void);
  24. /* Allocate a fresh page directory that clones the kernel identity map and
  25. * return its physical address (0 on out-of-memory). */
  26. unsigned int paging_new_directory(void);
  27. /* Page-table entry flags (4 KB pages). */
  28. #define PTE_PRESENT 0x001
  29. #define PTE_WRITABLE 0x002
  30. #define PTE_USER 0x004
  31. /* Map one 4 KB page (va -> phys) in page directory `cr3`, allocating a page
  32. * table if needed. Returns 1 on success, 0 on out-of-memory. */
  33. int paging_map_page(unsigned int cr3, unsigned int va, unsigned int phys,
  34. unsigned int flags);
  35. /* Physical address mapped at `va`, or 0 when the page is not present. */
  36. unsigned int paging_page_phys(unsigned int cr3, unsigned int va);
  37. /* Clear one 4 KB page (va) in page directory `cr3` (no-op when the page
  38. * table is absent). */
  39. void paging_unmap_page(unsigned int cr3, unsigned int va);
  40. /* Release the user mappings in [va, va+size): clear the PTEs, free empty page
  41. * tables and, when `free_phys` is set, free the mapped physical pages. With
  42. * `free_phys` clear the pages belong to someone else (e.g. a mapped window
  43. * canvas) and only the mapping/page tables are released. Used by the process
  44. * reaper; ranges should cover the user-owned mappings only. */
  45. void paging_release_user_range(unsigned int cr3, unsigned int va,
  46. unsigned int size, int free_phys);
  47. /* 1 when every page in [va, va+size) is a user-accessible 4 KB mapping in
  48. * `cr3` (and writable when `write` is set). Syscall services use this before
  49. * touching a pointer supplied by ring 3. */
  50. int paging_user_range_ok(unsigned int cr3, unsigned int va,
  51. unsigned int size, int write);
  52. /* Identity-map an MMIO range (e.g. a GPU register aperture) uncacheable into
  53. * the current page directory. Uses 4 MB pages; the range is rounded up to a
  54. * whole number of 4 MB pages. */
  55. void paging_map_mmio(unsigned int phys_base, unsigned int size);
  56. /* Same, but into an explicit page directory (used to update per-process
  57. * directories; see process_map_mmio_all()). */
  58. void paging_map_mmio_cr3(unsigned int cr3, unsigned int phys_base,
  59. unsigned int size);
  60. #endif