devtree.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Based on reduced version of METAG
  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/reboot.h>
  12. #include <linux/memblock.h>
  13. #include <linux/of.h>
  14. #include <linux/of_fdt.h>
  15. #include <asm/prom.h>
  16. #include <asm/clk.h>
  17. /* called from unflatten_device_tree() to bootstrap devicetree itself */
  18. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  19. {
  20. return __va(memblock_alloc(size, align));
  21. }
  22. /**
  23. * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
  24. * @dt: virtual address pointer to dt blob
  25. *
  26. * If a dtb was passed to the kernel, then use it to choose the correct
  27. * machine_desc and to setup the system.
  28. */
  29. int __init setup_machine_fdt(void *dt)
  30. {
  31. struct boot_param_header *devtree = dt;
  32. unsigned long dt_root;
  33. char *model, *compat;
  34. void *clk;
  35. char manufacturer[16];
  36. unsigned long len;
  37. /* check device tree validity */
  38. if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
  39. return 1;
  40. /* Search the mdescs for the 'best' compatible value match */
  41. initial_boot_params = devtree;
  42. dt_root = of_get_flat_dt_root();
  43. /* compat = "<manufacturer>,<model>" */
  44. compat = of_get_flat_dt_prop(dt_root, "compatible", NULL);
  45. if (!compat)
  46. compat = "<unknown>";
  47. model = strchr(compat, ',');
  48. if (model)
  49. model++;
  50. strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
  51. pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);
  52. /* Retrieve various information from the /chosen node */
  53. of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
  54. /* Initialize {size,address}-cells info */
  55. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  56. /* Setup memory, calling early_init_dt_add_memory_arch */
  57. of_scan_flat_dt(early_init_dt_scan_memory, NULL);
  58. clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
  59. if (clk)
  60. arc_set_core_freq(of_read_ulong(clk, len/4));
  61. return 0;
  62. }