mpc10x_memory.c 3.2 KB

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