boot_ioremap_32.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * arch/i386/mm/boot_ioremap.c
  3. *
  4. * Re-map functions for early boot-time before paging_init() when the
  5. * boot-time pagetables are still in use
  6. *
  7. * Written by Dave Hansen <haveblue@us.ibm.com>
  8. */
  9. /*
  10. * We need to use the 2-level pagetable functions, but CONFIG_X86_PAE
  11. * keeps that from happenning. If anyone has a better way, I'm listening.
  12. *
  13. * boot_pte_t is defined only if this all works correctly
  14. */
  15. #undef CONFIG_X86_PAE
  16. #undef CONFIG_PARAVIRT
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/tlbflush.h>
  20. #include <linux/init.h>
  21. #include <linux/stddef.h>
  22. /*
  23. * I'm cheating here. It is known that the two boot PTE pages are
  24. * allocated next to each other. I'm pretending that they're just
  25. * one big array.
  26. */
  27. #define BOOT_PTE_PTRS (PTRS_PER_PTE*2)
  28. static unsigned long boot_pte_index(unsigned long vaddr)
  29. {
  30. return __pa(vaddr) >> PAGE_SHIFT;
  31. }
  32. static inline boot_pte_t* boot_vaddr_to_pte(void *address)
  33. {
  34. boot_pte_t* boot_pg = (boot_pte_t*)pg0;
  35. return &boot_pg[boot_pte_index((unsigned long)address)];
  36. }
  37. /*
  38. * This is only for a caller who is clever enough to page-align
  39. * phys_addr and virtual_source, and who also has a preference
  40. * about which virtual address from which to steal ptes
  41. */
  42. static void __boot_ioremap(unsigned long phys_addr, unsigned long nrpages,
  43. void* virtual_source)
  44. {
  45. boot_pte_t* pte;
  46. int i;
  47. char *vaddr = virtual_source;
  48. pte = boot_vaddr_to_pte(virtual_source);
  49. for (i=0; i < nrpages; i++, phys_addr += PAGE_SIZE, pte++) {
  50. set_pte(pte, pfn_pte(phys_addr>>PAGE_SHIFT, PAGE_KERNEL));
  51. __flush_tlb_one(&vaddr[i*PAGE_SIZE]);
  52. }
  53. }
  54. /* the virtual space we're going to remap comes from this array */
  55. #define BOOT_IOREMAP_PAGES 4
  56. #define BOOT_IOREMAP_SIZE (BOOT_IOREMAP_PAGES*PAGE_SIZE)
  57. static __initdata char boot_ioremap_space[BOOT_IOREMAP_SIZE]
  58. __attribute__ ((aligned (PAGE_SIZE)));
  59. /*
  60. * This only applies to things which need to ioremap before paging_init()
  61. * bt_ioremap() and plain ioremap() are both useless at this point.
  62. *
  63. * When used, we're still using the boot-time pagetables, which only
  64. * have 2 PTE pages mapping the first 8MB
  65. *
  66. * There is no unmap. The boot-time PTE pages aren't used after boot.
  67. * If you really want the space back, just remap it yourself.
  68. * boot_ioremap(&ioremap_space-PAGE_OFFSET, BOOT_IOREMAP_SIZE)
  69. */
  70. __init void* boot_ioremap(unsigned long phys_addr, unsigned long size)
  71. {
  72. unsigned long last_addr, offset;
  73. unsigned int nrpages;
  74. last_addr = phys_addr + size - 1;
  75. /* page align the requested address */
  76. offset = phys_addr & ~PAGE_MASK;
  77. phys_addr &= PAGE_MASK;
  78. size = PAGE_ALIGN(last_addr) - phys_addr;
  79. nrpages = size >> PAGE_SHIFT;
  80. if (nrpages > BOOT_IOREMAP_PAGES)
  81. return NULL;
  82. __boot_ioremap(phys_addr, nrpages, boot_ioremap_space);
  83. return &boot_ioremap_space[offset];
  84. }