ioremap.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * OpenRISC ioremap.c
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * Modifications for the OpenRISC architecture:
  10. * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
  11. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  12. */
  13. #include <linux/vmalloc.h>
  14. #include <linux/io.h>
  15. #include <linux/pgtable.h>
  16. #include <asm/pgalloc.h>
  17. #include <asm/fixmap.h>
  18. #include <asm/bug.h>
  19. #include <linux/sched.h>
  20. #include <asm/tlbflush.h>
  21. extern int mem_init_done;
  22. /*
  23. * OK, this one's a bit tricky... ioremap can get called before memory is
  24. * initialized (early serial console does this) and will want to alloc a page
  25. * for its mapping. No userspace pages will ever get allocated before memory
  26. * is initialized so this applies only to kernel pages. In the event that
  27. * this is called before memory is initialized we allocate the page using
  28. * the memblock infrastructure.
  29. */
  30. pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm)
  31. {
  32. pte_t *pte;
  33. if (likely(mem_init_done)) {
  34. pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
  35. } else {
  36. pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
  37. if (!pte)
  38. panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
  39. __func__, PAGE_SIZE, PAGE_SIZE);
  40. }
  41. return pte;
  42. }