Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 5 | * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved. |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 6 | * |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 14 | * the documentation and/or other materials provided with the |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 15 | * distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 21 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <debug.h> |
| 32 | #include <reg.h> |
| 33 | #include <string.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <platform/iomap.h> |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 36 | #include <lib/ptable.h> |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 37 | |
| 38 | #include "smem.h" |
| 39 | |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 40 | |
| 41 | /* partition table from SMEM */ |
| 42 | static struct smem_ptable smem_ptable; |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 43 | static unsigned smem_apps_flash_start = 0xFFFFFFFF; |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 44 | |
| 45 | static void dump_smem_ptable(void) |
| 46 | { |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 47 | unsigned i; |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 48 | |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 49 | for (i = 0; i < smem_ptable.len; i++) { |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 50 | struct smem_ptn *p = &smem_ptable.parts[i]; |
| 51 | if (p->name[0] == '\0') |
| 52 | continue; |
| 53 | dprintf(SPEW, "%d: %s offs=0x%08x size=0x%08x attr: 0x%08x\n", |
| 54 | i, p->name, p->start, p->size, p->attr); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void smem_ptable_init(void) |
| 59 | { |
| 60 | unsigned i; |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 61 | unsigned ret; |
| 62 | unsigned len; |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 63 | |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 64 | /* Read only the header portion of ptable */ |
| 65 | ret = smem_read_alloc_entry_offset(SMEM_AARM_PARTITION_TABLE, |
| 66 | &smem_ptable, |
| 67 | SMEM_PTABLE_HDR_LEN, |
| 68 | 0); |
| 69 | if (ret) |
| 70 | { |
| 71 | dprintf(CRITICAL, "Failed to read ptable hdr (%d)", ret); |
| 72 | ASSERT(0); |
| 73 | } |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 74 | |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 75 | /* Verify ptable magic */ |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 76 | if (smem_ptable.magic[0] != _SMEM_PTABLE_MAGIC_1 || |
| 77 | smem_ptable.magic[1] != _SMEM_PTABLE_MAGIC_2) |
| 78 | return; |
| 79 | |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 80 | /* Ensure that # of partitions is less than the max we have allocated. */ |
| 81 | ASSERT(smem_ptable.len <= SMEM_PTABLE_MAX_PARTS); |
| 82 | |
| 83 | /* Find out length of partition data based on table version. */ |
| 84 | if (smem_ptable.version <= 3) |
| 85 | { |
| 86 | len = SMEM_PTABLE_HDR_LEN + SMEM_PTABLE_MAX_PARTS_V3*sizeof(struct smem_ptn); |
| 87 | } |
| 88 | else if (smem_ptable.version == 4) |
| 89 | { |
| 90 | len = SMEM_PTABLE_HDR_LEN + SMEM_PTABLE_MAX_PARTS_V4*sizeof(struct smem_ptn); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | dprintf(CRITICAL, "Unknown ptable version (%d)", smem_ptable.version); |
| 95 | ASSERT(0); |
| 96 | } |
| 97 | |
| 98 | ret = smem_read_alloc_entry(SMEM_AARM_PARTITION_TABLE, |
| 99 | &smem_ptable, |
| 100 | len); |
| 101 | if (ret) |
| 102 | { |
| 103 | dprintf(CRITICAL, "Failed to read ptable (%d)", ret); |
| 104 | ASSERT(0); |
| 105 | } |
| 106 | |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 107 | dump_smem_ptable(); |
| 108 | dprintf(INFO, "smem ptable found: ver: %d len: %d\n", |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 109 | smem_ptable.version, smem_ptable.len); |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 110 | |
| 111 | for (i = 0; i < smem_ptable.len; i++) { |
| 112 | if (!strcmp(smem_ptable.parts[i].name, "0:APPS")) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 113 | break; |
Dima Zavin | 9caac25 | 2009-01-26 12:37:15 -0800 | [diff] [blame] | 114 | } |
| 115 | if (i == smem_ptable.len) |
| 116 | return; |
| 117 | |
| 118 | smem_apps_flash_start = smem_ptable.parts[i].start; |
| 119 | } |
| 120 | |
| 121 | unsigned smem_get_apps_flash_start(void) |
| 122 | { |
| 123 | return smem_apps_flash_start; |
| 124 | } |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 125 | |
| 126 | void smem_add_modem_partitions(struct ptable *flash_ptable) |
| 127 | { |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 128 | unsigned i; |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 129 | |
| 130 | if (smem_ptable.magic[0] != _SMEM_PTABLE_MAGIC_1 || |
| 131 | smem_ptable.magic[1] != _SMEM_PTABLE_MAGIC_2) |
| 132 | return; |
| 133 | |
Amol Jadi | 6133e8d | 2012-10-07 22:15:02 -0700 | [diff] [blame] | 134 | for (i = 0; i < smem_ptable.len; i++) { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 135 | char *token; |
| 136 | char *pname = NULL; |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 137 | struct smem_ptn *p = &smem_ptable.parts[i]; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 138 | if (p->name[0] == '\0') |
| 139 | continue; |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 140 | token = strtok(p->name, ":"); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 141 | while (token) { |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 142 | pname = token; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 143 | token = strtok(NULL, ":"); |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 144 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 145 | if (pname) { |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 146 | ptable_add(flash_ptable, pname, p->start, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 147 | p->size, 0, TYPE_MODEM_PARTITION, |
| 148 | PERM_WRITEABLE); |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 153 | /* RAM Partition table from SMEM */ |
| 154 | int smem_ram_ptable_init(struct smem_ram_ptable *smem_ram_ptable) |
| 155 | { |
| 156 | unsigned i; |
| 157 | |
| 158 | i = smem_read_alloc_entry(SMEM_USABLE_RAM_PARTITION_TABLE, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 159 | smem_ram_ptable, |
| 160 | sizeof(struct smem_ram_ptable)); |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 161 | if (i != 0) |
| 162 | return 0; |
| 163 | |
| 164 | if (smem_ram_ptable->magic[0] != _SMEM_RAM_PTABLE_MAGIC_1 || |
| 165 | smem_ram_ptable->magic[1] != _SMEM_RAM_PTABLE_MAGIC_2) |
| 166 | return 0; |
| 167 | |
Ajay Dudani | ebb0b5b | 2011-08-02 14:35:55 -0700 | [diff] [blame] | 168 | dprintf(SPEW, "smem ram ptable found: ver: %d len: %d\n", |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 169 | smem_ram_ptable->version, smem_ram_ptable->len); |
| 170 | |
| 171 | return 1; |
| 172 | } |