boot_ioremap.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <linux/config.h>
  16. #undef CONFIG_X86_PAE
  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. #define boot_pte_index(address) \
  29. (((address) >> PAGE_SHIFT) & (BOOT_PTE_PTRS - 1))
  30. static inline boot_pte_t* boot_vaddr_to_pte(void *address)
  31. {
  32. boot_pte_t* boot_pg = (boot_pte_t*)pg0;
  33. return &boot_pg[boot_pte_index((unsigned long)address)];
  34. }
  35. /*
  36. * This is only for a caller who is clever enough to page-align
  37. * phys_addr and virtual_source, and who also has a preference
  38. * about which virtual address from which to steal ptes
  39. */
  40. static void __boot_ioremap(unsigned long phys_addr, unsigned long nrpages,
  41. void* virtual_source)
  42. {
  43. boot_pte_t* pte;
  44. int i;
  45. char *vaddr = virtual_source;
  46. pte = boot_vaddr_to_pte(virtual_source);
  47. for (i=0; i < nrpages; i++, phys_addr += PAGE_SIZE, pte++) {
  48. set_pte(pte, pfn_pte(phys_addr>>PAGE_SHIFT, PAGE_KERNEL));
  49. __flush_tlb_one(&vaddr[i*PAGE_SIZE]);
  50. }
  51. }
  52. /* the virtual space we're going to remap comes from this array */
  53. #define BOOT_IOREMAP_PAGES 4
  54. #define BOOT_IOREMAP_SIZE (BOOT_IOREMAP_PAGES*PAGE_SIZE)
  55. static __initdata char boot_ioremap_space[BOOT_IOREMAP_SIZE]
  56. __attribute__ ((aligned (PAGE_SIZE)));
  57. /*
  58. * This only applies to things which need to ioremap before paging_init()
  59. * bt_ioremap() and plain ioremap() are both useless at this point.
  60. *
  61. * When used, we're still using the boot-time pagetables, which only
  62. * have 2 PTE pages mapping the first 8MB
  63. *
  64. * There is no unmap. The boot-time PTE pages aren't used after boot.
  65. * If you really want the space back, just remap it yourself.
  66. * boot_ioremap(&ioremap_space-PAGE_OFFSET, BOOT_IOREMAP_SIZE)
  67. */
  68. __init void* boot_ioremap(unsigned long phys_addr, unsigned long size)
  69. {
  70. unsigned long last_addr, offset;
  71. unsigned int nrpages;
  72. last_addr = phys_addr + size - 1;
  73. /* page align the requested address */
  74. offset = phys_addr & ~PAGE_MASK;
  75. phys_addr &= PAGE_MASK;
  76. size = PAGE_ALIGN(last_addr) - phys_addr;
  77. nrpages = size >> PAGE_SHIFT;
  78. if (nrpages > BOOT_IOREMAP_PAGES)
  79. return NULL;
  80. __boot_ioremap(phys_addr, nrpages, boot_ioremap_space);
  81. return &boot_ioremap_space[offset];
  82. }