]>
Commit | Line | Data |
---|---|---|
b2123a48 RH |
1 | /* |
2 | * ARM dummy L210, L220, PL310 cache controller. | |
3 | * | |
4 | * Copyright (c) 2010-2012 Calxeda | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2 or any later version, as published by the Free Software | |
9 | * Foundation. | |
10 | * | |
11 | * This program is distributed in the hope it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along with | |
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | * | |
19 | */ | |
20 | ||
83c9f4ca | 21 | #include "hw/sysbus.h" |
b2123a48 RH |
22 | |
23 | /* L2C-310 r3p2 */ | |
24 | #define CACHE_ID 0x410000c8 | |
25 | ||
ae1953d0 | 26 | typedef struct L2x0State { |
b2123a48 RH |
27 | SysBusDevice busdev; |
28 | MemoryRegion iomem; | |
29 | uint32_t cache_type; | |
30 | uint32_t ctrl; | |
31 | uint32_t aux_ctrl; | |
32 | uint32_t data_ctrl; | |
33 | uint32_t tag_ctrl; | |
34 | uint32_t filter_start; | |
35 | uint32_t filter_end; | |
ae1953d0 | 36 | } L2x0State; |
b2123a48 RH |
37 | |
38 | static const VMStateDescription vmstate_l2x0 = { | |
39 | .name = "l2x0", | |
40 | .version_id = 1, | |
41 | .minimum_version_id = 1, | |
42 | .fields = (VMStateField[]) { | |
ae1953d0 AF |
43 | VMSTATE_UINT32(ctrl, L2x0State), |
44 | VMSTATE_UINT32(aux_ctrl, L2x0State), | |
45 | VMSTATE_UINT32(data_ctrl, L2x0State), | |
46 | VMSTATE_UINT32(tag_ctrl, L2x0State), | |
47 | VMSTATE_UINT32(filter_start, L2x0State), | |
48 | VMSTATE_UINT32(filter_end, L2x0State), | |
b2123a48 RH |
49 | VMSTATE_END_OF_LIST() |
50 | } | |
51 | }; | |
52 | ||
53 | ||
a8170e5e | 54 | static uint64_t l2x0_priv_read(void *opaque, hwaddr offset, |
b2123a48 RH |
55 | unsigned size) |
56 | { | |
57 | uint32_t cache_data; | |
ae1953d0 | 58 | L2x0State *s = (L2x0State *)opaque; |
b2123a48 RH |
59 | offset &= 0xfff; |
60 | if (offset >= 0x730 && offset < 0x800) { | |
61 | return 0; /* cache ops complete */ | |
62 | } | |
63 | switch (offset) { | |
64 | case 0: | |
65 | return CACHE_ID; | |
66 | case 0x4: | |
67 | /* aux_ctrl values affect cache_type values */ | |
68 | cache_data = (s->aux_ctrl & (7 << 17)) >> 15; | |
69 | cache_data |= (s->aux_ctrl & (1 << 16)) >> 16; | |
70 | return s->cache_type |= (cache_data << 18) | (cache_data << 6); | |
71 | case 0x100: | |
72 | return s->ctrl; | |
73 | case 0x104: | |
74 | return s->aux_ctrl; | |
75 | case 0x108: | |
76 | return s->tag_ctrl; | |
77 | case 0x10C: | |
78 | return s->data_ctrl; | |
79 | case 0xC00: | |
80 | return s->filter_start; | |
81 | case 0xC04: | |
82 | return s->filter_end; | |
83 | case 0xF40: | |
84 | return 0; | |
85 | case 0xF60: | |
86 | return 0; | |
87 | case 0xF80: | |
88 | return 0; | |
89 | default: | |
a35d4e42 PM |
90 | qemu_log_mask(LOG_GUEST_ERROR, |
91 | "l2x0_priv_read: Bad offset %x\n", (int)offset); | |
b2123a48 RH |
92 | break; |
93 | } | |
94 | return 0; | |
95 | } | |
96 | ||
a8170e5e | 97 | static void l2x0_priv_write(void *opaque, hwaddr offset, |
b2123a48 RH |
98 | uint64_t value, unsigned size) |
99 | { | |
ae1953d0 | 100 | L2x0State *s = (L2x0State *)opaque; |
b2123a48 RH |
101 | offset &= 0xfff; |
102 | if (offset >= 0x730 && offset < 0x800) { | |
103 | /* ignore */ | |
104 | return; | |
105 | } | |
106 | switch (offset) { | |
107 | case 0x100: | |
108 | s->ctrl = value & 1; | |
109 | break; | |
110 | case 0x104: | |
111 | s->aux_ctrl = value; | |
112 | break; | |
113 | case 0x108: | |
114 | s->tag_ctrl = value; | |
115 | break; | |
116 | case 0x10C: | |
117 | s->data_ctrl = value; | |
118 | break; | |
119 | case 0xC00: | |
120 | s->filter_start = value; | |
121 | break; | |
122 | case 0xC04: | |
123 | s->filter_end = value; | |
124 | break; | |
125 | case 0xF40: | |
126 | return; | |
127 | case 0xF60: | |
128 | return; | |
129 | case 0xF80: | |
130 | return; | |
131 | default: | |
a35d4e42 PM |
132 | qemu_log_mask(LOG_GUEST_ERROR, |
133 | "l2x0_priv_write: Bad offset %x\n", (int)offset); | |
b2123a48 RH |
134 | break; |
135 | } | |
136 | } | |
137 | ||
138 | static void l2x0_priv_reset(DeviceState *dev) | |
139 | { | |
ae1953d0 | 140 | L2x0State *s = DO_UPCAST(L2x0State, busdev.qdev, dev); |
b2123a48 RH |
141 | |
142 | s->ctrl = 0; | |
143 | s->aux_ctrl = 0x02020000; | |
144 | s->tag_ctrl = 0; | |
145 | s->data_ctrl = 0; | |
146 | s->filter_start = 0; | |
147 | s->filter_end = 0; | |
148 | } | |
149 | ||
150 | static const MemoryRegionOps l2x0_mem_ops = { | |
151 | .read = l2x0_priv_read, | |
152 | .write = l2x0_priv_write, | |
153 | .endianness = DEVICE_NATIVE_ENDIAN, | |
154 | }; | |
155 | ||
156 | static int l2x0_priv_init(SysBusDevice *dev) | |
157 | { | |
ae1953d0 | 158 | L2x0State *s = FROM_SYSBUS(L2x0State, dev); |
b2123a48 | 159 | |
3c161542 PB |
160 | memory_region_init_io(&s->iomem, OBJECT(dev), &l2x0_mem_ops, s, |
161 | "l2x0_cc", 0x1000); | |
b2123a48 RH |
162 | sysbus_init_mmio(dev, &s->iomem); |
163 | return 0; | |
164 | } | |
165 | ||
39bffca2 | 166 | static Property l2x0_properties[] = { |
ae1953d0 | 167 | DEFINE_PROP_UINT32("cache-type", L2x0State, cache_type, 0x1c100100), |
39bffca2 AL |
168 | DEFINE_PROP_END_OF_LIST(), |
169 | }; | |
170 | ||
999e12bb AL |
171 | static void l2x0_class_init(ObjectClass *klass, void *data) |
172 | { | |
173 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); | |
39bffca2 | 174 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
175 | |
176 | k->init = l2x0_priv_init; | |
39bffca2 AL |
177 | dc->vmsd = &vmstate_l2x0; |
178 | dc->no_user = 1; | |
179 | dc->props = l2x0_properties; | |
180 | dc->reset = l2x0_priv_reset; | |
999e12bb AL |
181 | } |
182 | ||
8c43a6f0 | 183 | static const TypeInfo l2x0_info = { |
999e12bb | 184 | .name = "l2x0", |
39bffca2 | 185 | .parent = TYPE_SYS_BUS_DEVICE, |
ae1953d0 | 186 | .instance_size = sizeof(L2x0State), |
999e12bb | 187 | .class_init = l2x0_class_init, |
b2123a48 RH |
188 | }; |
189 | ||
83f7d43a | 190 | static void l2x0_register_types(void) |
b2123a48 | 191 | { |
39bffca2 | 192 | type_register_static(&l2x0_info); |
b2123a48 RH |
193 | } |
194 | ||
83f7d43a | 195 | type_init(l2x0_register_types) |