prom.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * MIPS support for CONFIG_OF device tree support
  3. *
  4. * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/errno.h>
  13. #include <linux/types.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/initrd.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/of.h>
  18. #include <linux/of_fdt.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_platform.h>
  21. #include <asm/page.h>
  22. #include <asm/prom.h>
  23. int __init early_init_dt_scan_memory_arch(unsigned long node,
  24. const char *uname, int depth,
  25. void *data)
  26. {
  27. return early_init_dt_scan_memory(node, uname, depth, data);
  28. }
  29. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  30. {
  31. return add_memory_region(base, size, BOOT_MEM_RAM);
  32. }
  33. int __init reserve_mem_mach(unsigned long addr, unsigned long size)
  34. {
  35. return reserve_bootmem(addr, size, BOOTMEM_DEFAULT);
  36. }
  37. void __init free_mem_mach(unsigned long addr, unsigned long size)
  38. {
  39. return free_bootmem(addr, size);
  40. }
  41. u64 __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  42. {
  43. return virt_to_phys(
  44. __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS))
  45. );
  46. }
  47. #ifdef CONFIG_BLK_DEV_INITRD
  48. void __init early_init_dt_setup_initrd_arch(unsigned long start,
  49. unsigned long end)
  50. {
  51. initrd_start = (unsigned long)__va(start);
  52. initrd_end = (unsigned long)__va(end);
  53. initrd_below_start_ok = 1;
  54. }
  55. #endif
  56. /*
  57. * irq_create_of_mapping - Hook to resolve OF irq specifier into a Linux irq#
  58. *
  59. * Currently the mapping mechanism is trivial; simple flat hwirq numbers are
  60. * mapped 1:1 onto Linux irq numbers. Cascaded irq controllers are not
  61. * supported.
  62. */
  63. unsigned int irq_create_of_mapping(struct device_node *controller,
  64. const u32 *intspec, unsigned int intsize)
  65. {
  66. return intspec[0];
  67. }
  68. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  69. void __init early_init_devtree(void *params)
  70. {
  71. /* Setup flat device-tree pointer */
  72. initial_boot_params = params;
  73. /* Retrieve various informations from the /chosen node of the
  74. * device-tree, including the platform type, initrd location and
  75. * size, and more ...
  76. */
  77. of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
  78. /* Scan memory nodes */
  79. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  80. of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
  81. }
  82. void __init device_tree_init(void)
  83. {
  84. unsigned long base, size;
  85. if (!initial_boot_params)
  86. return;
  87. base = virt_to_phys((void *)initial_boot_params);
  88. size = initial_boot_params->totalsize;
  89. /* Before we do anything, lets reserve the dt blob */
  90. reserve_mem_mach(base, size);
  91. unflatten_device_tree();
  92. /* free the space reserved for the dt blob */
  93. free_mem_mach(base, size);
  94. }