blob: 1e075320af65f6a43a75e7298c979cc4703795be [file] [log] [blame]
Dima Zavin9caac252009-01-26 12:37:15 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <string.h>
32#include <sys/types.h>
33#include <platform/iomap.h>
34
35#include "smem.h"
36
37struct smem_ptn {
38 char name[16];
39 unsigned start;
40 unsigned size;
41 unsigned attr;
42} __attribute__ ((__packed__));
43
44struct smem_ptable {
45#define _SMEM_PTABLE_MAGIC_1 0x55ee73aa
46#define _SMEM_PTABLE_MAGIC_2 0xe35ebddb
47 unsigned magic[2];
48 unsigned version;
49 unsigned len;
50 struct smem_ptn parts[16];
51} __attribute__ ((__packed__));
52
53/* partition table from SMEM */
54static struct smem_ptable smem_ptable;
55static unsigned smem_apps_flash_start;
56
57static void dump_smem_ptable(void)
58{
59 int i;
60
61 for (i = 0; i < 16; i++) {
62 struct smem_ptn *p = &smem_ptable.parts[i];
63 if (p->name[0] == '\0')
64 continue;
65 dprintf(SPEW, "%d: %s offs=0x%08x size=0x%08x attr: 0x%08x\n",
66 i, p->name, p->start, p->size, p->attr);
67 }
68}
69
70void smem_ptable_init(void)
71{
72 unsigned i;
73
74 smem_apps_flash_start = 0xffffffff;
75
76 i = smem_read_alloc_entry(SMEM_AARM_PARTITION_TABLE,
77 &smem_ptable, sizeof(smem_ptable));
78 if (i != 0)
79 return;
80
81 if (smem_ptable.magic[0] != _SMEM_PTABLE_MAGIC_1 ||
82 smem_ptable.magic[1] != _SMEM_PTABLE_MAGIC_2)
83 return;
84
85 dump_smem_ptable();
86 dprintf(INFO, "smem ptable found: ver: %d len: %d\n",
87 smem_ptable.version, smem_ptable.len);
88
89 for (i = 0; i < smem_ptable.len; i++) {
90 if (!strcmp(smem_ptable.parts[i].name, "0:APPS"))
91 break;
92 }
93 if (i == smem_ptable.len)
94 return;
95
96 smem_apps_flash_start = smem_ptable.parts[i].start;
97}
98
99unsigned smem_get_apps_flash_start(void)
100{
101 return smem_apps_flash_start;
102}