/Ethereal-msm8939-beta9/arch/metag/kernel/devtree.c

https://bitbucket.org/MilosStamenkovic95/etherealos · C · 114 lines · 71 code · 15 blank · 28 comment · 10 complexity · d9006c482e17c1e125ed13cca469b783 MD5 · raw file

  1. /*
  2. * linux/arch/metag/kernel/devtree.c
  3. *
  4. * Copyright (C) 2012 Imagination Technologies Ltd.
  5. *
  6. * Based on ARM version:
  7. * Copyright (C) 2009 Canonical Ltd. <jeremy.kerr@canonical.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/export.h>
  15. #include <linux/types.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/memblock.h>
  18. #include <linux/of.h>
  19. #include <linux/of_fdt.h>
  20. #include <asm/setup.h>
  21. #include <asm/page.h>
  22. #include <asm/mach/arch.h>
  23. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  24. {
  25. pr_err("%s(%llx, %llx)\n",
  26. __func__, base, size);
  27. }
  28. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  29. {
  30. return alloc_bootmem_align(size, align);
  31. }
  32. /**
  33. * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
  34. * @dt: virtual address pointer to dt blob
  35. *
  36. * If a dtb was passed to the kernel, then use it to choose the correct
  37. * machine_desc and to setup the system.
  38. */
  39. struct machine_desc * __init setup_machine_fdt(void *dt)
  40. {
  41. struct boot_param_header *devtree = dt;
  42. struct machine_desc *mdesc, *mdesc_best = NULL;
  43. unsigned int score, mdesc_score = ~1;
  44. unsigned long dt_root;
  45. const char *model;
  46. /* check device tree validity */
  47. if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
  48. return NULL;
  49. /* Search the mdescs for the 'best' compatible value match */
  50. initial_boot_params = devtree;
  51. dt_root = of_get_flat_dt_root();
  52. for_each_machine_desc(mdesc) {
  53. score = of_flat_dt_match(dt_root, mdesc->dt_compat);
  54. if (score > 0 && score < mdesc_score) {
  55. mdesc_best = mdesc;
  56. mdesc_score = score;
  57. }
  58. }
  59. if (!mdesc_best) {
  60. const char *prop;
  61. long size;
  62. pr_err("\nError: unrecognized/unsupported device tree compatible list:\n[ ");
  63. prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
  64. if (prop) {
  65. while (size > 0) {
  66. printk("'%s' ", prop);
  67. size -= strlen(prop) + 1;
  68. prop += strlen(prop) + 1;
  69. }
  70. }
  71. printk("]\n\n");
  72. dump_machine_table(); /* does not return */
  73. }
  74. model = of_get_flat_dt_prop(dt_root, "model", NULL);
  75. if (!model)
  76. model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
  77. if (!model)
  78. model = "<unknown>";
  79. pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
  80. /* Retrieve various information from the /chosen node */
  81. of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
  82. return mdesc_best;
  83. }
  84. /**
  85. * copy_fdt - Copy device tree into non-init memory.
  86. *
  87. * We must copy the flattened device tree blob into non-init memory because the
  88. * unflattened device tree will reference the strings in it directly.
  89. */
  90. void __init copy_fdt(void)
  91. {
  92. void *alloc = early_init_dt_alloc_memory_arch(
  93. be32_to_cpu(initial_boot_params->totalsize), 0x40);
  94. if (alloc) {
  95. memcpy(alloc, initial_boot_params,
  96. be32_to_cpu(initial_boot_params->totalsize));
  97. initial_boot_params = alloc;
  98. }
  99. }