mpc10x_memory.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * arch/ppc/boot/common/mpc10x_common.c
  3. *
  4. * A routine to find out how much memory the machine has.
  5. *
  6. * Based on:
  7. * arch/ppc/kernel/mpc10x_common.c
  8. *
  9. * Author: Mark A. Greer
  10. * mgreer@mvista.com
  11. *
  12. * 2001-2002 (c) MontaVista, Software, Inc. This file is licensed under
  13. * the terms of the GNU General Public License version 2. This program
  14. * is licensed "as is" without any warranty of any kind, whether express
  15. * or implied.
  16. */
  17. #include <linux/pci.h>
  18. #include <asm/types.h>
  19. #include <asm/io.h>
  20. #include "mpc10x.h"
  21. /*
  22. * *** WARNING - A BAT MUST be set to access the PCI config addr/data regs ***
  23. */
  24. /*
  25. * PCI config space macros, similar to indirect_xxx and early_xxx macros.
  26. * We assume bus 0.
  27. */
  28. #define MPC10X_CFG_read(val, addr, type, op) *val = op((type)(addr))
  29. #define MPC10X_CFG_write(val, addr, type, op) op((type *)(addr), (val))
  30. #define MPC10X_PCI_OP(rw, size, type, op, mask) \
  31. static void \
  32. mpc10x_##rw##_config_##size(unsigned int __iomem *cfg_addr, \
  33. unsigned int *cfg_data, int devfn, int offset, \
  34. type val) \
  35. { \
  36. out_be32(cfg_addr, \
  37. ((offset & 0xfc) << 24) | (devfn << 16) \
  38. | (0 << 8) | 0x80); \
  39. MPC10X_CFG_##rw(val, cfg_data + (offset & mask), type, op); \
  40. return; \
  41. }
  42. MPC10X_PCI_OP(read, byte, u8 *, in_8, 3)
  43. MPC10X_PCI_OP(read, dword, u32 *, in_le32, 0)
  44. /*
  45. * Read the memory controller registers to determine the amount of memory in
  46. * the system. This assumes that the firmware has correctly set up the memory
  47. * controller registers. On CONFIG_PPC_PREP, we know we are being called
  48. * under a PReP memory map. On all other machines, we assume we are under
  49. * a CHRP memory map. Further, on CONFIG_PPC_MULTIPLATFORM we must rename
  50. * this function.
  51. */
  52. #ifdef CONFIG_PPC_MULTIPLATFORM
  53. #define get_mem_size mpc10x_get_mem_size
  54. #endif
  55. unsigned long
  56. get_mem_size(void)
  57. {
  58. unsigned int *config_addr, *config_data, val;
  59. unsigned long start, end, total, offset;
  60. int i;
  61. unsigned char bank_enables;
  62. #ifdef CONFIG_PPC_PREP
  63. config_addr = (unsigned int *)MPC10X_MAPA_CNFG_ADDR;
  64. config_data = (unsigned int *)MPC10X_MAPA_CNFG_DATA;
  65. #else
  66. config_addr = (unsigned int *)MPC10X_MAPB_CNFG_ADDR;
  67. config_data = (unsigned int *)MPC10X_MAPB_CNFG_DATA;
  68. #endif
  69. mpc10x_read_config_byte(config_addr, config_data, PCI_DEVFN(0,0),
  70. MPC10X_MCTLR_MEM_BANK_ENABLES, &bank_enables);
  71. total = 0;
  72. for (i = 0; i < 8; i++) {
  73. if (bank_enables & (1 << i)) {
  74. offset = MPC10X_MCTLR_MEM_START_1 + ((i > 3) ? 4 : 0);
  75. mpc10x_read_config_dword(config_addr, config_data,
  76. PCI_DEVFN(0,0), offset, &val);
  77. start = (val >> ((i & 3) << 3)) & 0xff;
  78. offset = MPC10X_MCTLR_EXT_MEM_START_1 + ((i>3) ? 4 : 0);
  79. mpc10x_read_config_dword(config_addr, config_data,
  80. PCI_DEVFN(0,0), offset, &val);
  81. val = (val >> ((i & 3) << 3)) & 0x03;
  82. start = (val << 28) | (start << 20);
  83. offset = MPC10X_MCTLR_MEM_END_1 + ((i > 3) ? 4 : 0);
  84. mpc10x_read_config_dword(config_addr, config_data,
  85. PCI_DEVFN(0,0), offset, &val);
  86. end = (val >> ((i & 3) << 3)) & 0xff;
  87. offset = MPC10X_MCTLR_EXT_MEM_END_1 + ((i > 3) ? 4 : 0);
  88. mpc10x_read_config_dword(config_addr, config_data,
  89. PCI_DEVFN(0,0), offset, &val);
  90. val = (val >> ((i & 3) << 3)) & 0x03;
  91. end = (val << 28) | (end << 20) | 0xfffff;
  92. total += (end - start + 1);
  93. }
  94. }
  95. return total;
  96. }