paging.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 page directory currently loaded in CR3. On SMP this
  14. * is per-CPU; on one CPU it is the running process's directory. */
  15. unsigned int paging_current_cr3(void);
  16. /* Physical address of the bootstrap/kernel page directory that new process
  17. * directories clone. */
  18. unsigned int paging_kernel_cr3(void);
  19. /* Allocate a fresh page directory that clones the kernel identity map and
  20. * return its physical address (0 on out-of-memory). */
  21. unsigned int paging_new_directory(void);
  22. /* Page-table entry flags (4 KB pages). */
  23. #define PTE_PRESENT 0x001
  24. #define PTE_WRITABLE 0x002
  25. #define PTE_USER 0x004
  26. /* Map one 4 KB page (va -> phys) in page directory `cr3`, allocating a page
  27. * table if needed. Returns 1 on success, 0 on out-of-memory. */
  28. int paging_map_page(unsigned int cr3, unsigned int va, unsigned int phys,
  29. unsigned int flags);
  30. /* Physical address mapped at `va`, or 0 when the page is not present. */
  31. unsigned int paging_page_phys(unsigned int cr3, unsigned int va);
  32. /* Clear one 4 KB page (va) in page directory `cr3` (no-op when the page
  33. * table is absent). */
  34. void paging_unmap_page(unsigned int cr3, unsigned int va);
  35. /* Release the user mappings in [va, va+size): clear the PTEs, free empty page
  36. * tables and, when `free_phys` is set, free the mapped physical pages. With
  37. * `free_phys` clear the pages belong to someone else (e.g. a mapped window
  38. * canvas) and only the mapping/page tables are released. Used by the process
  39. * reaper; ranges should cover the user-owned mappings only. */
  40. void paging_release_user_range(unsigned int cr3, unsigned int va,
  41. unsigned int size, int free_phys);
  42. /* 1 when every page in [va, va+size) is a user-accessible 4 KB mapping in
  43. * `cr3` (and writable when `write` is set). Syscall services use this before
  44. * touching a pointer supplied by ring 3. */
  45. int paging_user_range_ok(unsigned int cr3, unsigned int va,
  46. unsigned int size, int write);
  47. /* Identity-map an MMIO range (e.g. a GPU register aperture) uncacheable into
  48. * the current page directory. Uses 4 MB pages; the range is rounded up to a
  49. * whole number of 4 MB pages. */
  50. void paging_map_mmio(unsigned int phys_base, unsigned int size);
  51. /* Same, but into an explicit page directory (used to update per-process
  52. * directories; see process_map_mmio_all()). */
  53. void paging_map_mmio_cr3(unsigned int cr3, unsigned int phys_base,
  54. unsigned int size);
  55. #endif