map.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /* physical is from 2 -> 4 GiB */
  17. #define TMFM (4ULL*GiB)
  18. /* the wacko hole in RISCV address space makes KADDR a bit more complex. */
  19. int km, ku, k2;
  20. void*
  21. KADDR(uintptr_t pa)
  22. {
  23. if((pa > 2 * GiB) && (pa < TMFM)) {
  24. km++;
  25. return (void *)(KSEG0|pa);
  26. }
  27. assert(pa < (uintptr_t)kseg2);
  28. k2++;
  29. return (void *)((uintptr_t)kseg2|pa);
  30. }
  31. uintmem
  32. PADDR(void* va)
  33. {
  34. uintmem pa;
  35. pa = PTR2UINT(va);
  36. if(pa >= KSEG0) {
  37. return (uintmem)(uint32_t)pa; //-KSEG0;
  38. }
  39. if(pa > (uintptr_t)kseg2) {
  40. return pa-(uintptr_t)kseg2;
  41. }
  42. panic("PADDR: va %#p pa #%p @ %#p\n", va, _PADDR(va), getcallerpc());
  43. return 0;
  44. }
  45. KMap*
  46. kmap(Page* page)
  47. {
  48. DBG("kmap(%#llx) @ %#p: %#p %#p\n",
  49. page->pa, getcallerpc(),
  50. page->pa, KADDR(page->pa));
  51. return KADDR(page->pa);
  52. }