prom.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/export.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. static char mips_machine_name[64] = "Unknown";
  24. __init void mips_set_machine_name(const char *name)
  25. {
  26. if (name == NULL)
  27. return;
  28. strlcpy(mips_machine_name, name, sizeof(mips_machine_name));
  29. pr_info("MIPS: machine is %s\n", mips_get_machine_name());
  30. }
  31. char *mips_get_machine_name(void)
  32. {
  33. return mips_machine_name;
  34. }
  35. #ifdef CONFIG_OF
  36. int __init early_init_dt_scan_memory_arch(unsigned long node,
  37. const char *uname, int depth,
  38. void *data)
  39. {
  40. return early_init_dt_scan_memory(node, uname, depth, data);
  41. }
  42. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  43. {
  44. return add_memory_region(base, size, BOOT_MEM_RAM);
  45. }
  46. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  47. {
  48. return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
  49. }
  50. #ifdef CONFIG_BLK_DEV_INITRD
  51. void __init early_init_dt_setup_initrd_arch(unsigned long start,
  52. unsigned long end)
  53. {
  54. initrd_start = (unsigned long)__va(start);
  55. initrd_end = (unsigned long)__va(end);
  56. initrd_below_start_ok = 1;
  57. }
  58. #endif
  59. int __init early_init_dt_scan_model(unsigned long node, const char *uname,
  60. int depth, void *data)
  61. {
  62. if (!depth) {
  63. char *model = of_get_flat_dt_prop(node, "model", NULL);
  64. if (model)
  65. mips_set_machine_name(model);
  66. }
  67. return 0;
  68. }
  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, arcs_cmdline);
  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. /* try to load the mips machine name */
  82. of_scan_flat_dt(early_init_dt_scan_model, NULL);
  83. }
  84. void __init __dt_setup_arch(struct boot_param_header *bph)
  85. {
  86. if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
  87. pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
  88. return;
  89. }
  90. initial_boot_params = bph;
  91. early_init_devtree(initial_boot_params);
  92. }
  93. #endif