map.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #define _KADDR(pa) UINT2PTR(kseg0+((uintptr)(pa)))
  15. #define _PADDR(va) PTR2UINT(((uintptr)(va)) - kseg0)
  16. #define TMFM (64*MiB)
  17. int km, ku, k2;
  18. void*
  19. KADDR(uintptr_t pa)
  20. {
  21. uint8_t* va;
  22. va = UINT2PTR(pa);
  23. if(pa < TMFM) {
  24. km++;
  25. return KSEG0+va;
  26. }
  27. assert(pa < KSEG2);
  28. k2++;
  29. return KSEG2+va;
  30. }
  31. uintmem
  32. PADDR(void* va)
  33. {
  34. uintmem pa;
  35. pa = PTR2UINT(va);
  36. if(pa >= KSEG0 && pa < KSEG0+TMFM)
  37. return pa-KSEG0;
  38. if(pa > KSEG2)
  39. return pa-KSEG2;
  40. panic("PADDR: va %#p pa #%p @ %#p\n", va, _PADDR(va), getcallerpc());
  41. return 0;
  42. }
  43. KMap*
  44. kmap(Page* page)
  45. {
  46. DBG("kmap(%#llx) @ %#p: %#p %#p\n",
  47. page->pa, getcallerpc(),
  48. page->pa, KADDR(page->pa));
  49. return KADDR(page->pa);
  50. }