Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <asm/setup.h> |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 15 | #include <asm/errno.h> |
| 16 | #include <asm/sizes.h> |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 17 | #include <asm/pgtable.h> |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 19 | #include <linux/memory.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <mach/msm_memtypes.h> |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 21 | #include <mach/socinfo.h> |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 22 | #include "smd_private.h" |
| 23 | |
Naveen Ramaraj | 50442d0 | 2011-09-08 16:07:19 -0700 | [diff] [blame] | 24 | #if defined(CONFIG_ARCH_MSM8960) |
| 25 | #include "rpm_resources.h" |
| 26 | #endif |
| 27 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 28 | static struct mem_region_t { |
| 29 | u64 start; |
| 30 | u64 size; |
| 31 | /* reserved for future use */ |
| 32 | u64 num_partitions; |
| 33 | int state; |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 34 | } mem_regions[MAX_NR_REGIONS]; |
| 35 | |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 36 | static struct mutex mem_regions_mutex; |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 37 | static unsigned int nr_mem_regions; |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 38 | static int mem_regions_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | |
Naveen Ramaraj | 50442d0 | 2011-09-08 16:07:19 -0700 | [diff] [blame] | 40 | enum { |
| 41 | STATE_POWER_DOWN = 0x0, |
Naveen Ramaraj | 2e96c9f | 2011-09-22 14:16:03 -0700 | [diff] [blame] | 42 | STATE_ACTIVE = 0x2, |
Naveen Ramaraj | 50442d0 | 2011-09-08 16:07:19 -0700 | [diff] [blame] | 43 | STATE_DEFAULT = STATE_ACTIVE |
| 44 | }; |
| 45 | |
| 46 | static int default_mask = ~0x0; |
| 47 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | /* Return the number of chipselects populated with a memory bank */ |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 49 | /* This is 7x30 only and will be re-implemented in the future */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 51 | #if defined(CONFIG_ARCH_MSM7X30) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | unsigned int get_num_populated_chipselects() |
| 53 | { |
| 54 | /* Currently, Linux cannot determine the memory toplogy of a target */ |
| 55 | /* This is a kludge until all this info is figured out from smem */ |
| 56 | |
| 57 | /* There is atleast one chipselect populated for hosting the 1st bank */ |
| 58 | unsigned int num_chipselects = 1; |
| 59 | int i; |
| 60 | for (i = 0; i < meminfo.nr_banks; i++) { |
| 61 | struct membank *bank = &meminfo.bank[i]; |
| 62 | if (bank->start == EBI1_PHYS_OFFSET) |
| 63 | num_chipselects++; |
| 64 | } |
| 65 | return num_chipselects; |
| 66 | } |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 67 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 69 | unsigned int get_num_memory_banks(void) |
| 70 | { |
| 71 | return nr_mem_regions; |
| 72 | } |
| 73 | |
| 74 | unsigned int get_memory_bank_size(unsigned int id) |
| 75 | { |
| 76 | BUG_ON(id >= nr_mem_regions); |
| 77 | return mem_regions[id].size; |
| 78 | } |
| 79 | |
| 80 | unsigned int get_memory_bank_start(unsigned int id) |
| 81 | { |
| 82 | BUG_ON(id >= nr_mem_regions); |
| 83 | return mem_regions[id].start; |
| 84 | } |
| 85 | |
| 86 | int __init meminfo_init(unsigned int type, unsigned int min_bank_size) |
| 87 | { |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 88 | unsigned int i, j; |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 89 | unsigned long bank_size; |
| 90 | unsigned long bank_start; |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 91 | unsigned long region_size; |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 92 | struct smem_ram_ptable *ram_ptable; |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 93 | /* physical memory banks */ |
| 94 | unsigned int nr_mem_banks = 0; |
| 95 | /* logical memory regions for dmm */ |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 96 | nr_mem_regions = 0; |
| 97 | |
| 98 | ram_ptable = smem_alloc(SMEM_USABLE_RAM_PARTITION_TABLE, |
| 99 | sizeof(struct smem_ram_ptable)); |
| 100 | |
| 101 | if (!ram_ptable) { |
| 102 | pr_err("Could not read ram partition table\n"); |
| 103 | return -EINVAL; |
| 104 | } |
| 105 | |
| 106 | pr_info("meminfo_init: smem ram ptable found: ver: %d len: %d\n", |
| 107 | ram_ptable->version, ram_ptable->len); |
| 108 | |
| 109 | for (i = 0; i < ram_ptable->len; i++) { |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 110 | /* A bank is valid only if is greater than min_bank_size. If |
| 111 | * non-valid memory (e.g. modem memory) became greater than |
| 112 | * min_bank_size, there is currently no way to differentiate. |
| 113 | */ |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 114 | if (ram_ptable->parts[i].type == type && |
| 115 | ram_ptable->parts[i].size >= min_bank_size) { |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 116 | bank_start = ram_ptable->parts[i].start; |
| 117 | bank_size = ram_ptable->parts[i].size; |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 118 | region_size = bank_size / NR_REGIONS_PER_BANK; |
| 119 | |
| 120 | for (j = 0; j < NR_REGIONS_PER_BANK; j++) { |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 121 | mem_regions[nr_mem_regions].start = |
| 122 | bank_start; |
| 123 | mem_regions[nr_mem_regions].size = |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 124 | region_size; |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 125 | mem_regions[nr_mem_regions].state = |
| 126 | STATE_DEFAULT; |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 127 | bank_start += region_size; |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 128 | nr_mem_regions++; |
| 129 | } |
| 130 | nr_mem_banks++; |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
Jack Cheung | d01fd83 | 2012-01-13 22:59:57 -0800 | [diff] [blame] | 133 | mutex_init(&mem_regions_mutex); |
| 134 | mem_regions_mask = default_mask; |
Naveen Ramaraj | bc958dd | 2011-11-11 16:54:09 -0800 | [diff] [blame] | 135 | pr_info("Found %d memory banks grouped into %d memory regions\n", |
| 136 | nr_mem_banks, nr_mem_regions); |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 137 | return 0; |
| 138 | } |