treeboot-akebono.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright © 2013 Tony Breeds IBM Corporation
  3. * Copyright © 2013 Alistair Popple IBM Corporation
  4. *
  5. * Based on earlier code:
  6. * Copyright (C) Paul Mackerras 1997.
  7. *
  8. * Matt Porter <mporter@kernel.crashing.org>
  9. * Copyright 2002-2005 MontaVista Software Inc.
  10. *
  11. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  12. * Copyright (c) 2003, 2004 Zultys Technologies
  13. *
  14. * Copyright 2007 David Gibson, IBM Corporation.
  15. * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
  16. * Copyright © 2011 David Kleikamp IBM Corporation
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #include <stdarg.h>
  24. #include <stddef.h>
  25. #include "types.h"
  26. #include "elf.h"
  27. #include "string.h"
  28. #include "stdlib.h"
  29. #include "stdio.h"
  30. #include "page.h"
  31. #include "ops.h"
  32. #include "reg.h"
  33. #include "io.h"
  34. #include "dcr.h"
  35. #include "4xx.h"
  36. #include "44x.h"
  37. #include "libfdt.h"
  38. BSS_STACK(4096);
  39. #define SPRN_PIR 0x11E /* Processor Identification Register */
  40. #define USERDATA_LEN 256 /* Length of userdata passed in by PIBS */
  41. #define MAX_RANKS 0x4
  42. #define DDR3_MR0CF 0x80010011U
  43. #define CCTL0_MCO2 0x8000080FU
  44. #define CCTL0_MCO3 0x80000810U
  45. #define CCTL0_MCO4 0x80000811U
  46. #define CCTL0_MCO5 0x80000812U
  47. #define CCTL0_MCO6 0x80000813U
  48. static unsigned long long ibm_akebono_memsize;
  49. static long long unsigned mac_addr;
  50. static unsigned long long ibm_akebono_detect_memsize(void)
  51. {
  52. u32 reg;
  53. unsigned i;
  54. unsigned long long memsize = 0;
  55. for (i = 0; i < MAX_RANKS; i++) {
  56. reg = mfdcrx(DDR3_MR0CF + i);
  57. if (!(reg & 1))
  58. continue;
  59. reg &= 0x0000f000;
  60. reg >>= 12;
  61. memsize += (0x800000ULL << reg);
  62. }
  63. return memsize;
  64. }
  65. static void ibm_akebono_fixups(void)
  66. {
  67. void *emac;
  68. u32 reg;
  69. dt_fixup_memory(0x0ULL, ibm_akebono_memsize);
  70. /* Fixup the SD timeout frequency */
  71. mtdcrx(CCTL0_MCO4, 0x1);
  72. /* Disable SD high-speed mode (which seems to be broken) */
  73. reg = mfdcrx(CCTL0_MCO2) & ~0x2;
  74. mtdcrx(CCTL0_MCO2, reg);
  75. /* Set the MAC address */
  76. emac = finddevice("/plb/opb/ethernet");
  77. if (emac > 0) {
  78. if (mac_addr)
  79. setprop(emac, "local-mac-address",
  80. ((u8 *) &mac_addr) + 2 , 6);
  81. }
  82. }
  83. void platform_init(char *userdata)
  84. {
  85. unsigned long end_of_ram, avail_ram;
  86. u32 pir_reg;
  87. int node, size;
  88. const u32 *timebase;
  89. int len, i, userdata_len;
  90. char *end;
  91. userdata[USERDATA_LEN - 1] = '\0';
  92. userdata_len = strlen(userdata);
  93. for (i = 0; i < userdata_len - 15; i++) {
  94. if (strncmp(&userdata[i], "local-mac-addr=", 15) == 0) {
  95. if (i > 0 && userdata[i - 1] != ' ') {
  96. /* We've only found a substring ending
  97. * with local-mac-addr so this isn't
  98. * our mac address. */
  99. continue;
  100. }
  101. mac_addr = strtoull(&userdata[i + 15], &end, 16);
  102. /* Remove the "local-mac-addr=<...>" from the kernel
  103. * command line, including the tailing space if
  104. * present. */
  105. if (*end == ' ')
  106. end++;
  107. len = ((int) end) - ((int) &userdata[i]);
  108. memmove(&userdata[i], end,
  109. userdata_len - (len + i) + 1);
  110. break;
  111. }
  112. }
  113. loader_info.cmdline = userdata;
  114. loader_info.cmdline_len = 256;
  115. ibm_akebono_memsize = ibm_akebono_detect_memsize();
  116. if (ibm_akebono_memsize >> 32)
  117. end_of_ram = ~0UL;
  118. else
  119. end_of_ram = ibm_akebono_memsize;
  120. avail_ram = end_of_ram - (unsigned long)_end;
  121. simple_alloc_init(_end, avail_ram, 128, 64);
  122. platform_ops.fixups = ibm_akebono_fixups;
  123. platform_ops.exit = ibm44x_dbcr_reset;
  124. pir_reg = mfspr(SPRN_PIR);
  125. /* Make sure FDT blob is sane */
  126. if (fdt_check_header(_dtb_start) != 0)
  127. fatal("Invalid device tree blob\n");
  128. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  129. "cpu", sizeof("cpu"));
  130. if (!node)
  131. fatal("Cannot find cpu node\n");
  132. timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
  133. if (timebase && (size == 4))
  134. timebase_period_ns = 1000000000 / *timebase;
  135. fdt_set_boot_cpuid_phys(_dtb_start, pir_reg);
  136. fdt_init(_dtb_start);
  137. serial_console_init();
  138. }