]> Git Repo - qemu.git/blob - hw/omap_l4.c
omap_l4: add memory API variant of omap_l4_attach()
[qemu.git] / hw / omap_l4.c
1 /*
2  * TI OMAP L4 interconnect emulation.
3  *
4  * Copyright (C) 2007-2009 Nokia Corporation
5  * Written by Andrzej Zaborowski <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 or
10  * (at your option) any later version of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "hw.h"
21 #include "omap.h"
22
23 struct omap_l4_s {
24     MemoryRegion *address_space;
25     target_phys_addr_t base;
26     int ta_num;
27     struct omap_target_agent_s ta[0];
28 };
29
30 struct omap_l4_s *omap_l4_init(MemoryRegion *address_space,
31                                target_phys_addr_t base, int ta_num)
32 {
33     struct omap_l4_s *bus = g_malloc0(
34                     sizeof(*bus) + ta_num * sizeof(*bus->ta));
35
36     bus->address_space = address_space;
37     bus->ta_num = ta_num;
38     bus->base = base;
39
40     return bus;
41 }
42
43 target_phys_addr_t omap_l4_region_base(struct omap_target_agent_s *ta,
44                                        int region)
45 {
46     return ta->bus->base + ta->start[region].offset;
47 }
48
49 target_phys_addr_t omap_l4_region_size(struct omap_target_agent_s *ta,
50                                        int region)
51 {
52     return ta->start[region].size;
53 }
54
55 static uint32_t omap_l4ta_read(void *opaque, target_phys_addr_t addr)
56 {
57     struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
58
59     switch (addr) {
60     case 0x00:  /* COMPONENT */
61         return s->component;
62
63     case 0x20:  /* AGENT_CONTROL */
64         return s->control;
65
66     case 0x28:  /* AGENT_STATUS */
67         return s->status;
68     }
69
70     OMAP_BAD_REG(addr);
71     return 0;
72 }
73
74 static void omap_l4ta_write(void *opaque, target_phys_addr_t addr,
75                 uint32_t value)
76 {
77     struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
78
79     switch (addr) {
80     case 0x00:  /* COMPONENT */
81     case 0x28:  /* AGENT_STATUS */
82         OMAP_RO_REG(addr);
83         break;
84
85     case 0x20:  /* AGENT_CONTROL */
86         s->control = value & 0x01000700;
87         if (value & 1)                                  /* OCP_RESET */
88             s->status &= ~1;                            /* REQ_TIMEOUT */
89         break;
90
91     default:
92         OMAP_BAD_REG(addr);
93     }
94 }
95
96 static CPUReadMemoryFunc * const omap_l4ta_readfn[] = {
97     omap_badwidth_read16,
98     omap_l4ta_read,
99     omap_badwidth_read16,
100 };
101
102 static CPUWriteMemoryFunc * const omap_l4ta_writefn[] = {
103     omap_badwidth_write32,
104     omap_badwidth_write32,
105     omap_l4ta_write,
106 };
107
108 struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus,
109         const struct omap_l4_region_s *regions,
110         const struct omap_l4_agent_info_s *agents,
111         int cs)
112 {
113     int i, iomemtype;
114     struct omap_target_agent_s *ta = NULL;
115     const struct omap_l4_agent_info_s *info = NULL;
116
117     for (i = 0; i < bus->ta_num; i ++)
118         if (agents[i].ta == cs) {
119             ta = &bus->ta[i];
120             info = &agents[i];
121             break;
122         }
123     if (!ta) {
124         fprintf(stderr, "%s: bad target agent (%i)\n", __FUNCTION__, cs);
125         exit(-1);
126     }
127
128     ta->bus = bus;
129     ta->start = &regions[info->region];
130     ta->regions = info->regions;
131
132     ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
133     ta->status = 0x00000000;
134     ta->control = 0x00000200;   /* XXX 01000200 for L4TAO */
135
136     iomemtype = cpu_register_io_memory(omap_l4ta_readfn,
137                     omap_l4ta_writefn, ta, DEVICE_NATIVE_ENDIAN);
138     ta->base = omap_l4_attach(ta, info->ta_region, iomemtype);
139
140     return ta;
141 }
142
143 target_phys_addr_t omap_l4_attach(struct omap_target_agent_s *ta, int region,
144                 int iotype)
145 {
146     target_phys_addr_t base;
147     ssize_t size;
148
149     if (region < 0 || region >= ta->regions) {
150         fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
151         exit(-1);
152     }
153
154     base = ta->bus->base + ta->start[region].offset;
155     size = ta->start[region].size;
156     if (iotype) {
157         cpu_register_physical_memory(base, size, iotype);
158     }
159
160     return base;
161 }
162
163 target_phys_addr_t omap_l4_attach_region(struct omap_target_agent_s *ta,
164                                          int region, MemoryRegion *mr)
165 {
166     target_phys_addr_t base;
167
168     if (region < 0 || region >= ta->regions) {
169         fprintf(stderr, "%s: bad io region (%i)\n", __FUNCTION__, region);
170         exit(-1);
171     }
172
173     base = ta->bus->base + ta->start[region].offset;
174     if (mr) {
175         memory_region_add_subregion(ta->bus->address_space, base, mr);
176     }
177
178     return base;
179 }
This page took 0.035782 seconds and 4 git commands to generate.