treeboot-currituck.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright © 2011 Tony Breeds IBM Corporation
  3. *
  4. * Based on earlier code:
  5. * Copyright (C) Paul Mackerras 1997.
  6. *
  7. * Matt Porter <mporter@kernel.crashing.org>
  8. * Copyright 2002-2005 MontaVista Software Inc.
  9. *
  10. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  11. * Copyright (c) 2003, 2004 Zultys Technologies
  12. *
  13. * Copyright 2007 David Gibson, IBM Corporation.
  14. * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
  15. * Copyright © 2011 David Kleikamp IBM Corporation
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * as published by the Free Software Foundation; either version
  20. * 2 of the License, or (at your option) any later version.
  21. */
  22. #include <stdarg.h>
  23. #include <stddef.h>
  24. #include "types.h"
  25. #include "elf.h"
  26. #include "string.h"
  27. #include "stdio.h"
  28. #include "page.h"
  29. #include "ops.h"
  30. #include "reg.h"
  31. #include "io.h"
  32. #include "dcr.h"
  33. #include "4xx.h"
  34. #include "44x.h"
  35. #include "libfdt.h"
  36. BSS_STACK(4096);
  37. #define MAX_RANKS 0x4
  38. #define DDR3_MR0CF 0x80010011U
  39. static unsigned long long ibm_currituck_memsize;
  40. static unsigned long long ibm_currituck_detect_memsize(void)
  41. {
  42. u32 reg;
  43. unsigned i;
  44. unsigned long long memsize = 0;
  45. for(i = 0; i < MAX_RANKS; i++){
  46. reg = mfdcrx(DDR3_MR0CF + i);
  47. if (!(reg & 1))
  48. continue;
  49. reg &= 0x0000f000;
  50. reg >>= 12;
  51. memsize += (0x800000ULL << reg);
  52. }
  53. return memsize;
  54. }
  55. static void ibm_currituck_fixups(void)
  56. {
  57. void *devp = finddevice("/");
  58. u32 dma_ranges[7];
  59. dt_fixup_memory(0x0ULL, ibm_currituck_memsize);
  60. while ((devp = find_node_by_devtype(devp, "pci"))) {
  61. if (getprop(devp, "dma-ranges", dma_ranges, sizeof(dma_ranges)) < 0) {
  62. printf("%s: Failed to get dma-ranges\r\n", __func__);
  63. continue;
  64. }
  65. dma_ranges[5] = ibm_currituck_memsize >> 32;
  66. dma_ranges[6] = ibm_currituck_memsize & 0xffffffffUL;
  67. setprop(devp, "dma-ranges", dma_ranges, sizeof(dma_ranges));
  68. }
  69. }
  70. #define SPRN_PIR 0x11E /* Processor Indentification Register */
  71. void platform_init(void)
  72. {
  73. unsigned long end_of_ram, avail_ram;
  74. u32 pir_reg;
  75. int node, size;
  76. const u32 *timebase;
  77. ibm_currituck_memsize = ibm_currituck_detect_memsize();
  78. if (ibm_currituck_memsize >> 32)
  79. end_of_ram = ~0UL;
  80. else
  81. end_of_ram = ibm_currituck_memsize;
  82. avail_ram = end_of_ram - (unsigned long)_end;
  83. simple_alloc_init(_end, avail_ram, 128, 64);
  84. platform_ops.fixups = ibm_currituck_fixups;
  85. platform_ops.exit = ibm44x_dbcr_reset;
  86. pir_reg = mfspr(SPRN_PIR);
  87. /* Make sure FDT blob is sane */
  88. if (fdt_check_header(_dtb_start) != 0)
  89. fatal("Invalid device tree blob\n");
  90. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  91. "cpu", sizeof("cpu"));
  92. if (!node)
  93. fatal("Cannot find cpu node\n");
  94. timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
  95. if (timebase && (size == 4))
  96. timebase_period_ns = 1000000000 / *timebase;
  97. fdt_set_boot_cpuid_phys(_dtb_start, pir_reg);
  98. fdt_init(_dtb_start);
  99. serial_console_init();
  100. }