Statistics
| Branch: | Revision:

root / hw / omap_l4.c @ 46115ac4

History | View | Annotate | Download (8.2 kB)

1 2c1d9ecb cmchao
/*
2 2c1d9ecb cmchao
 * TI OMAP L4 interconnect emulation.
3 2c1d9ecb cmchao
 *
4 2c1d9ecb cmchao
 * Copyright (C) 2007-2009 Nokia Corporation
5 2c1d9ecb cmchao
 * Written by Andrzej Zaborowski <andrew@openedhand.com>
6 2c1d9ecb cmchao
 *
7 2c1d9ecb cmchao
 * This program is free software; you can redistribute it and/or
8 2c1d9ecb cmchao
 * modify it under the terms of the GNU General Public License as
9 2c1d9ecb cmchao
 * published by the Free Software Foundation; either version 2 or
10 2c1d9ecb cmchao
 * (at your option) any later version of the License.
11 2c1d9ecb cmchao
 *
12 2c1d9ecb cmchao
 * This program is distributed in the hope that it will be useful,
13 2c1d9ecb cmchao
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 2c1d9ecb cmchao
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 2c1d9ecb cmchao
 * GNU General Public License for more details.
16 2c1d9ecb cmchao
 *
17 2c1d9ecb cmchao
 * You should have received a copy of the GNU General Public License along
18 2c1d9ecb cmchao
 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 2c1d9ecb cmchao
 */
20 2c1d9ecb cmchao
#include "hw.h"
21 2c1d9ecb cmchao
#include "omap.h"
22 2c1d9ecb cmchao
23 2c1d9ecb cmchao
#ifdef L4_MUX_HACK
24 2c1d9ecb cmchao
static int omap_l4_io_entries;
25 2c1d9ecb cmchao
static int omap_cpu_io_entry;
26 2c1d9ecb cmchao
static struct omap_l4_entry {
27 2c1d9ecb cmchao
        CPUReadMemoryFunc * const *mem_read;
28 2c1d9ecb cmchao
        CPUWriteMemoryFunc * const *mem_write;
29 2c1d9ecb cmchao
        void *opaque;
30 2c1d9ecb cmchao
} *omap_l4_io_entry;
31 2c1d9ecb cmchao
static CPUReadMemoryFunc * const *omap_l4_io_readb_fn;
32 2c1d9ecb cmchao
static CPUReadMemoryFunc * const *omap_l4_io_readh_fn;
33 2c1d9ecb cmchao
static CPUReadMemoryFunc * const *omap_l4_io_readw_fn;
34 2c1d9ecb cmchao
static CPUWriteMemoryFunc * const *omap_l4_io_writeb_fn;
35 2c1d9ecb cmchao
static CPUWriteMemoryFunc * const *omap_l4_io_writeh_fn;
36 2c1d9ecb cmchao
static CPUWriteMemoryFunc * const *omap_l4_io_writew_fn;
37 2c1d9ecb cmchao
static void **omap_l4_io_opaque;
38 2c1d9ecb cmchao
39 2c1d9ecb cmchao
int l4_register_io_memory(CPUReadMemoryFunc * const *mem_read,
40 2c1d9ecb cmchao
                CPUWriteMemoryFunc * const *mem_write, void *opaque)
41 2c1d9ecb cmchao
{
42 2c1d9ecb cmchao
    omap_l4_io_entry[omap_l4_io_entries].mem_read = mem_read;
43 2c1d9ecb cmchao
    omap_l4_io_entry[omap_l4_io_entries].mem_write = mem_write;
44 2c1d9ecb cmchao
    omap_l4_io_entry[omap_l4_io_entries].opaque = opaque;
45 2c1d9ecb cmchao
46 2c1d9ecb cmchao
    return omap_l4_io_entries ++;
47 2c1d9ecb cmchao
}
48 2c1d9ecb cmchao
49 2c1d9ecb cmchao
static uint32_t omap_l4_io_readb(void *opaque, target_phys_addr_t addr)
50 2c1d9ecb cmchao
{
51 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
52 2c1d9ecb cmchao
53 2c1d9ecb cmchao
    return omap_l4_io_readb_fn[i](omap_l4_io_opaque[i], addr);
54 2c1d9ecb cmchao
}
55 2c1d9ecb cmchao
56 2c1d9ecb cmchao
static uint32_t omap_l4_io_readh(void *opaque, target_phys_addr_t addr)
57 2c1d9ecb cmchao
{
58 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
59 2c1d9ecb cmchao
60 2c1d9ecb cmchao
    return omap_l4_io_readh_fn[i](omap_l4_io_opaque[i], addr);
61 2c1d9ecb cmchao
}
62 2c1d9ecb cmchao
63 2c1d9ecb cmchao
static uint32_t omap_l4_io_readw(void *opaque, target_phys_addr_t addr)
64 2c1d9ecb cmchao
{
65 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
66 2c1d9ecb cmchao
67 2c1d9ecb cmchao
    return omap_l4_io_readw_fn[i](omap_l4_io_opaque[i], addr);
68 2c1d9ecb cmchao
}
69 2c1d9ecb cmchao
70 2c1d9ecb cmchao
static void omap_l4_io_writeb(void *opaque, target_phys_addr_t addr,
71 2c1d9ecb cmchao
                uint32_t value)
72 2c1d9ecb cmchao
{
73 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
74 2c1d9ecb cmchao
75 2c1d9ecb cmchao
    return omap_l4_io_writeb_fn[i](omap_l4_io_opaque[i], addr, value);
76 2c1d9ecb cmchao
}
77 2c1d9ecb cmchao
78 2c1d9ecb cmchao
static void omap_l4_io_writeh(void *opaque, target_phys_addr_t addr,
79 2c1d9ecb cmchao
                uint32_t value)
80 2c1d9ecb cmchao
{
81 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
82 2c1d9ecb cmchao
83 2c1d9ecb cmchao
    return omap_l4_io_writeh_fn[i](omap_l4_io_opaque[i], addr, value);
84 2c1d9ecb cmchao
}
85 2c1d9ecb cmchao
86 2c1d9ecb cmchao
static void omap_l4_io_writew(void *opaque, target_phys_addr_t addr,
87 2c1d9ecb cmchao
                uint32_t value)
88 2c1d9ecb cmchao
{
89 2c1d9ecb cmchao
    unsigned int i = (addr - OMAP2_L4_BASE) >> TARGET_PAGE_BITS;
90 2c1d9ecb cmchao
91 2c1d9ecb cmchao
    return omap_l4_io_writew_fn[i](omap_l4_io_opaque[i], addr, value);
92 2c1d9ecb cmchao
}
93 2c1d9ecb cmchao
94 2c1d9ecb cmchao
static CPUReadMemoryFunc * const omap_l4_io_readfn[] = {
95 2c1d9ecb cmchao
    omap_l4_io_readb,
96 2c1d9ecb cmchao
    omap_l4_io_readh,
97 2c1d9ecb cmchao
    omap_l4_io_readw,
98 2c1d9ecb cmchao
};
99 2c1d9ecb cmchao
100 2c1d9ecb cmchao
static CPUWriteMemoryFunc * const omap_l4_io_writefn[] = {
101 2c1d9ecb cmchao
    omap_l4_io_writeb,
102 2c1d9ecb cmchao
    omap_l4_io_writeh,
103 2c1d9ecb cmchao
    omap_l4_io_writew,
104 2c1d9ecb cmchao
};
105 2c1d9ecb cmchao
#else
106 2c1d9ecb cmchao
int l4_register_io_memory(CPUReadMemoryFunc * const *mem_read,
107 2c1d9ecb cmchao
                          CPUWriteMemoryFunc * const *mem_write,
108 2c1d9ecb cmchao
                          void *opaque)
109 2c1d9ecb cmchao
{
110 2507c12a Alexander Graf
    return cpu_register_io_memory(mem_read, mem_write, opaque,
111 2507c12a Alexander Graf
                                  DEVICE_NATIVE_ENDIAN);
112 2c1d9ecb cmchao
}
113 2c1d9ecb cmchao
#endif
114 2c1d9ecb cmchao
115 2c1d9ecb cmchao
struct omap_l4_s {
116 2c1d9ecb cmchao
    target_phys_addr_t base;
117 2c1d9ecb cmchao
    int ta_num;
118 2c1d9ecb cmchao
    struct omap_target_agent_s ta[0];
119 2c1d9ecb cmchao
};
120 2c1d9ecb cmchao
121 2c1d9ecb cmchao
struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
122 2c1d9ecb cmchao
{
123 2c1d9ecb cmchao
    struct omap_l4_s *bus = qemu_mallocz(
124 2c1d9ecb cmchao
                    sizeof(*bus) + ta_num * sizeof(*bus->ta));
125 2c1d9ecb cmchao
126 2c1d9ecb cmchao
    bus->ta_num = ta_num;
127 2c1d9ecb cmchao
    bus->base = base;
128 2c1d9ecb cmchao
129 2c1d9ecb cmchao
#ifdef L4_MUX_HACK
130 2c1d9ecb cmchao
    omap_l4_io_entries = 1;
131 2c1d9ecb cmchao
    omap_l4_io_entry = qemu_mallocz(125 * sizeof(*omap_l4_io_entry));
132 2c1d9ecb cmchao
133 2c1d9ecb cmchao
    omap_cpu_io_entry =
134 2c1d9ecb cmchao
            cpu_register_io_memory(omap_l4_io_readfn,
135 2507c12a Alexander Graf
                            omap_l4_io_writefn, bus, DEVICE_NATIVE_ENDIAN);
136 2c1d9ecb cmchao
# define L4_PAGES        (0xb4000 / TARGET_PAGE_SIZE)
137 2c1d9ecb cmchao
    omap_l4_io_readb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
138 2c1d9ecb cmchao
    omap_l4_io_readh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
139 2c1d9ecb cmchao
    omap_l4_io_readw_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
140 2c1d9ecb cmchao
    omap_l4_io_writeb_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
141 2c1d9ecb cmchao
    omap_l4_io_writeh_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
142 2c1d9ecb cmchao
    omap_l4_io_writew_fn = qemu_mallocz(sizeof(void *) * L4_PAGES);
143 2c1d9ecb cmchao
    omap_l4_io_opaque = qemu_mallocz(sizeof(void *) * L4_PAGES);
144 2c1d9ecb cmchao
#endif
145 2c1d9ecb cmchao
146 2c1d9ecb cmchao
    return bus;
147 2c1d9ecb cmchao
}
148 2c1d9ecb cmchao
149 2c1d9ecb cmchao
static uint32_t omap_l4ta_read(void *opaque, target_phys_addr_t addr)
150 2c1d9ecb cmchao
{
151 2c1d9ecb cmchao
    struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
152 2c1d9ecb cmchao
153 2c1d9ecb cmchao
    switch (addr) {
154 2c1d9ecb cmchao
    case 0x00:        /* COMPONENT */
155 2c1d9ecb cmchao
        return s->component;
156 2c1d9ecb cmchao
157 2c1d9ecb cmchao
    case 0x20:        /* AGENT_CONTROL */
158 2c1d9ecb cmchao
        return s->control;
159 2c1d9ecb cmchao
160 2c1d9ecb cmchao
    case 0x28:        /* AGENT_STATUS */
161 2c1d9ecb cmchao
        return s->status;
162 2c1d9ecb cmchao
    }
163 2c1d9ecb cmchao
164 2c1d9ecb cmchao
    OMAP_BAD_REG(addr);
165 2c1d9ecb cmchao
    return 0;
166 2c1d9ecb cmchao
}
167 2c1d9ecb cmchao
168 2c1d9ecb cmchao
static void omap_l4ta_write(void *opaque, target_phys_addr_t addr,
169 2c1d9ecb cmchao
                uint32_t value)
170 2c1d9ecb cmchao
{
171 2c1d9ecb cmchao
    struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
172 2c1d9ecb cmchao
173 2c1d9ecb cmchao
    switch (addr) {
174 2c1d9ecb cmchao
    case 0x00:        /* COMPONENT */
175 2c1d9ecb cmchao
    case 0x28:        /* AGENT_STATUS */
176 2c1d9ecb cmchao
        OMAP_RO_REG(addr);
177 2c1d9ecb cmchao
        break;
178 2c1d9ecb cmchao
179 2c1d9ecb cmchao
    case 0x20:        /* AGENT_CONTROL */
180 2c1d9ecb cmchao
        s->control = value & 0x01000700;
181 2c1d9ecb cmchao
        if (value & 1)                                        /* OCP_RESET */
182 2c1d9ecb cmchao
            s->status &= ~1;                                /* REQ_TIMEOUT */
183 2c1d9ecb cmchao
        break;
184 2c1d9ecb cmchao
185 2c1d9ecb cmchao
    default:
186 2c1d9ecb cmchao
        OMAP_BAD_REG(addr);
187 2c1d9ecb cmchao
    }
188 2c1d9ecb cmchao
}
189 2c1d9ecb cmchao
190 2c1d9ecb cmchao
static CPUReadMemoryFunc * const omap_l4ta_readfn[] = {
191 2c1d9ecb cmchao
    omap_badwidth_read16,
192 2c1d9ecb cmchao
    omap_l4ta_read,
193 2c1d9ecb cmchao
    omap_badwidth_read16,
194 2c1d9ecb cmchao
};
195 2c1d9ecb cmchao
196 2c1d9ecb cmchao
static CPUWriteMemoryFunc * const omap_l4ta_writefn[] = {
197 2c1d9ecb cmchao
    omap_badwidth_write32,
198 2c1d9ecb cmchao
    omap_badwidth_write32,
199 2c1d9ecb cmchao
    omap_l4ta_write,
200 2c1d9ecb cmchao
};
201 2c1d9ecb cmchao
202 2c1d9ecb cmchao
struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus,
203 2c1d9ecb cmchao
        const struct omap_l4_region_s *regions,
204 2c1d9ecb cmchao
        const struct omap_l4_agent_info_s *agents,
205 2c1d9ecb cmchao
        int cs)
206 2c1d9ecb cmchao
{
207 2c1d9ecb cmchao
    int i, iomemtype;
208 2c1d9ecb cmchao
    struct omap_target_agent_s *ta = NULL;
209 2c1d9ecb cmchao
    const struct omap_l4_agent_info_s *info = NULL;
210 2c1d9ecb cmchao
211 2c1d9ecb cmchao
    for (i = 0; i < bus->ta_num; i ++)
212 2c1d9ecb cmchao
        if (agents[i].ta == cs) {
213 2c1d9ecb cmchao
            ta = &bus->ta[i];
214 2c1d9ecb cmchao
            info = &agents[i];
215 2c1d9ecb cmchao
            break;
216 2c1d9ecb cmchao
        }
217 2c1d9ecb cmchao
    if (!ta) {
218 2c1d9ecb cmchao
        fprintf(stderr, "%s: bad target agent (%i)\n", __FUNCTION__, cs);
219 2c1d9ecb cmchao
        exit(-1);
220 2c1d9ecb cmchao
    }
221 2c1d9ecb cmchao
222 2c1d9ecb cmchao
    ta->bus = bus;
223 2c1d9ecb cmchao
    ta->start = &regions[info->region];
224 2c1d9ecb cmchao
    ta->regions = info->regions;
225 2c1d9ecb cmchao
226 2c1d9ecb cmchao
    ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
227 2c1d9ecb cmchao
    ta->status = 0x00000000;
228 2c1d9ecb cmchao
    ta->control = 0x00000200;        /* XXX 01000200 for L4TAO */
229 2c1d9ecb cmchao
230 2c1d9ecb cmchao
    iomemtype = l4_register_io_memory(omap_l4ta_readfn,
231 2c1d9ecb cmchao
                    omap_l4ta_writefn, ta);
232 2c1d9ecb cmchao
    ta->base = omap_l4_attach(ta, info->ta_region, iomemtype);
233 2c1d9ecb cmchao
234 2c1d9ecb cmchao
    return ta;
235 2c1d9ecb cmchao
}
236 2c1d9ecb cmchao
237 2c1d9ecb cmchao
target_phys_addr_t omap_l4_attach(struct omap_target_agent_s *ta, int region,
238 2c1d9ecb cmchao
                int iotype)
239 2c1d9ecb cmchao
{
240 2c1d9ecb cmchao
    target_phys_addr_t base;
241 2c1d9ecb cmchao
    ssize_t size;
242 2c1d9ecb cmchao
#ifdef L4_MUX_HACK
243 2c1d9ecb cmchao
    int i;
244 2c1d9ecb cmchao
#endif
245 2c1d9ecb cmchao
246 2c1d9ecb cmchao
    if (region < 0 || region >= ta->regions) {
247 2c1d9ecb cmchao
        fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
248 2c1d9ecb cmchao
        exit(-1);
249 2c1d9ecb cmchao
    }
250 2c1d9ecb cmchao
251 2c1d9ecb cmchao
    base = ta->bus->base + ta->start[region].offset;
252 2c1d9ecb cmchao
    size = ta->start[region].size;
253 2c1d9ecb cmchao
    if (iotype) {
254 2c1d9ecb cmchao
#ifndef L4_MUX_HACK
255 2c1d9ecb cmchao
        cpu_register_physical_memory(base, size, iotype);
256 2c1d9ecb cmchao
#else
257 2c1d9ecb cmchao
        cpu_register_physical_memory(base, size, omap_cpu_io_entry);
258 2c1d9ecb cmchao
        i = (base - ta->bus->base) / TARGET_PAGE_SIZE;
259 2c1d9ecb cmchao
        for (; size > 0; size -= TARGET_PAGE_SIZE, i ++) {
260 2c1d9ecb cmchao
            omap_l4_io_readb_fn[i] = omap_l4_io_entry[iotype].mem_read[0];
261 2c1d9ecb cmchao
            omap_l4_io_readh_fn[i] = omap_l4_io_entry[iotype].mem_read[1];
262 2c1d9ecb cmchao
            omap_l4_io_readw_fn[i] = omap_l4_io_entry[iotype].mem_read[2];
263 2c1d9ecb cmchao
            omap_l4_io_writeb_fn[i] = omap_l4_io_entry[iotype].mem_write[0];
264 2c1d9ecb cmchao
            omap_l4_io_writeh_fn[i] = omap_l4_io_entry[iotype].mem_write[1];
265 2c1d9ecb cmchao
            omap_l4_io_writew_fn[i] = omap_l4_io_entry[iotype].mem_write[2];
266 2c1d9ecb cmchao
            omap_l4_io_opaque[i] = omap_l4_io_entry[iotype].opaque;
267 2c1d9ecb cmchao
        }
268 2c1d9ecb cmchao
#endif
269 2c1d9ecb cmchao
    }
270 2c1d9ecb cmchao
271 2c1d9ecb cmchao
    return base;
272 2c1d9ecb cmchao
}