root / hw / pcmcia / pxa2xx.c @ 327ed10f
History | View | Annotate | Download (7.2 kB)
1 | a171fe39 | balrog | /*
|
---|---|---|---|
2 | a171fe39 | balrog | * Intel XScale PXA255/270 PC Card and CompactFlash Interface.
|
3 | a171fe39 | balrog | *
|
4 | a171fe39 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | a171fe39 | balrog | * Written by Andrzej Zaborowski <balrog@zabor.org>
|
6 | a171fe39 | balrog | *
|
7 | a171fe39 | balrog | * This code is licensed under the GPLv2.
|
8 | 6b620ca3 | Paolo Bonzini | *
|
9 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
10 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
11 | a171fe39 | balrog | */
|
12 | a171fe39 | balrog | |
13 | 83c9f4ca | Paolo Bonzini | #include "hw/hw.h" |
14 | 80bbaee6 | Andreas Färber | #include "hw/sysbus.h" |
15 | 83c9f4ca | Paolo Bonzini | #include "hw/pcmcia.h" |
16 | 0d09e41a | Paolo Bonzini | #include "hw/arm/pxa.h" |
17 | a171fe39 | balrog | |
18 | 80bbaee6 | Andreas Färber | #define TYPE_PXA2XX_PCMCIA "pxa2xx-pcmcia" |
19 | 80bbaee6 | Andreas Färber | #define PXA2XX_PCMCIA(obj) \
|
20 | 80bbaee6 | Andreas Färber | OBJECT_CHECK(PXA2xxPCMCIAState, obj, TYPE_PXA2XX_PCMCIA) |
21 | 4beeaa71 | Benoît Canet | |
22 | bc24a225 | Paul Brook | struct PXA2xxPCMCIAState {
|
23 | 80bbaee6 | Andreas Färber | SysBusDevice parent_obj; |
24 | 80bbaee6 | Andreas Färber | |
25 | bc24a225 | Paul Brook | PCMCIASocket slot; |
26 | 80bbaee6 | Andreas Färber | MemoryRegion container_mem; |
27 | 354a8c06 | Benoît Canet | MemoryRegion common_iomem; |
28 | 4beeaa71 | Benoît Canet | MemoryRegion attr_iomem; |
29 | 59aee13c | Benoît Canet | MemoryRegion iomem; |
30 | a171fe39 | balrog | |
31 | a171fe39 | balrog | qemu_irq irq; |
32 | a171fe39 | balrog | qemu_irq cd_irq; |
33 | 80bbaee6 | Andreas Färber | |
34 | 80bbaee6 | Andreas Färber | PCMCIACardState *card; |
35 | a171fe39 | balrog | }; |
36 | a171fe39 | balrog | |
37 | 354a8c06 | Benoît Canet | static uint64_t pxa2xx_pcmcia_common_read(void *opaque, |
38 | a8170e5e | Avi Kivity | hwaddr offset, unsigned size)
|
39 | a171fe39 | balrog | { |
40 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
41 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
42 | a171fe39 | balrog | |
43 | a171fe39 | balrog | if (s->slot.attached) {
|
44 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
45 | d1f2c96a | Andreas Färber | return pcc->common_read(s->card, offset);
|
46 | a171fe39 | balrog | } |
47 | a171fe39 | balrog | |
48 | a171fe39 | balrog | return 0; |
49 | a171fe39 | balrog | } |
50 | a171fe39 | balrog | |
51 | a8170e5e | Avi Kivity | static void pxa2xx_pcmcia_common_write(void *opaque, hwaddr offset, |
52 | 354a8c06 | Benoît Canet | uint64_t value, unsigned size)
|
53 | a171fe39 | balrog | { |
54 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
55 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
56 | a171fe39 | balrog | |
57 | a171fe39 | balrog | if (s->slot.attached) {
|
58 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
59 | d1f2c96a | Andreas Färber | pcc->common_write(s->card, offset, value); |
60 | a171fe39 | balrog | } |
61 | a171fe39 | balrog | } |
62 | a171fe39 | balrog | |
63 | 4beeaa71 | Benoît Canet | static uint64_t pxa2xx_pcmcia_attr_read(void *opaque, |
64 | a8170e5e | Avi Kivity | hwaddr offset, unsigned size)
|
65 | a171fe39 | balrog | { |
66 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
67 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
68 | a171fe39 | balrog | |
69 | a171fe39 | balrog | if (s->slot.attached) {
|
70 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
71 | d1f2c96a | Andreas Färber | return pcc->attr_read(s->card, offset);
|
72 | a171fe39 | balrog | } |
73 | a171fe39 | balrog | |
74 | a171fe39 | balrog | return 0; |
75 | a171fe39 | balrog | } |
76 | a171fe39 | balrog | |
77 | a8170e5e | Avi Kivity | static void pxa2xx_pcmcia_attr_write(void *opaque, hwaddr offset, |
78 | 4beeaa71 | Benoît Canet | uint64_t value, unsigned size)
|
79 | a171fe39 | balrog | { |
80 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
81 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
82 | a171fe39 | balrog | |
83 | a171fe39 | balrog | if (s->slot.attached) {
|
84 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
85 | d1f2c96a | Andreas Färber | pcc->attr_write(s->card, offset, value); |
86 | a171fe39 | balrog | } |
87 | a171fe39 | balrog | } |
88 | a171fe39 | balrog | |
89 | 59aee13c | Benoît Canet | static uint64_t pxa2xx_pcmcia_io_read(void *opaque, |
90 | a8170e5e | Avi Kivity | hwaddr offset, unsigned size)
|
91 | a171fe39 | balrog | { |
92 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
93 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
94 | a171fe39 | balrog | |
95 | a171fe39 | balrog | if (s->slot.attached) {
|
96 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
97 | d1f2c96a | Andreas Färber | return pcc->io_read(s->card, offset);
|
98 | a171fe39 | balrog | } |
99 | a171fe39 | balrog | |
100 | a171fe39 | balrog | return 0; |
101 | a171fe39 | balrog | } |
102 | a171fe39 | balrog | |
103 | a8170e5e | Avi Kivity | static void pxa2xx_pcmcia_io_write(void *opaque, hwaddr offset, |
104 | 59aee13c | Benoît Canet | uint64_t value, unsigned size)
|
105 | a171fe39 | balrog | { |
106 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
107 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
108 | a171fe39 | balrog | |
109 | a171fe39 | balrog | if (s->slot.attached) {
|
110 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
111 | d1f2c96a | Andreas Färber | pcc->io_write(s->card, offset, value); |
112 | a171fe39 | balrog | } |
113 | a171fe39 | balrog | } |
114 | a171fe39 | balrog | |
115 | 354a8c06 | Benoît Canet | static const MemoryRegionOps pxa2xx_pcmcia_common_ops = { |
116 | 354a8c06 | Benoît Canet | .read = pxa2xx_pcmcia_common_read, |
117 | 354a8c06 | Benoît Canet | .write = pxa2xx_pcmcia_common_write, |
118 | 354a8c06 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN |
119 | a171fe39 | balrog | }; |
120 | a171fe39 | balrog | |
121 | 4beeaa71 | Benoît Canet | static const MemoryRegionOps pxa2xx_pcmcia_attr_ops = { |
122 | 4beeaa71 | Benoît Canet | .read = pxa2xx_pcmcia_attr_read, |
123 | 4beeaa71 | Benoît Canet | .write = pxa2xx_pcmcia_attr_write, |
124 | 4beeaa71 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN |
125 | a171fe39 | balrog | }; |
126 | a171fe39 | balrog | |
127 | 59aee13c | Benoît Canet | static const MemoryRegionOps pxa2xx_pcmcia_io_ops = { |
128 | 59aee13c | Benoît Canet | .read = pxa2xx_pcmcia_io_read, |
129 | 59aee13c | Benoît Canet | .write = pxa2xx_pcmcia_io_write, |
130 | 59aee13c | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN |
131 | a171fe39 | balrog | }; |
132 | a171fe39 | balrog | |
133 | a171fe39 | balrog | static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level) |
134 | a171fe39 | balrog | { |
135 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
136 | a171fe39 | balrog | if (!s->irq)
|
137 | a171fe39 | balrog | return;
|
138 | a171fe39 | balrog | |
139 | a171fe39 | balrog | qemu_set_irq(s->irq, level); |
140 | a171fe39 | balrog | } |
141 | a171fe39 | balrog | |
142 | 354a8c06 | Benoît Canet | PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem, |
143 | a8170e5e | Avi Kivity | hwaddr base) |
144 | a171fe39 | balrog | { |
145 | 80bbaee6 | Andreas Färber | DeviceState *dev; |
146 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s; |
147 | a171fe39 | balrog | |
148 | 80bbaee6 | Andreas Färber | dev = qdev_create(NULL, TYPE_PXA2XX_PCMCIA);
|
149 | 80bbaee6 | Andreas Färber | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
|
150 | 80bbaee6 | Andreas Färber | s = PXA2XX_PCMCIA(dev); |
151 | 80bbaee6 | Andreas Färber | |
152 | 80bbaee6 | Andreas Färber | if (base == 0x30000000) { |
153 | 80bbaee6 | Andreas Färber | s->slot.slot_string = "PXA PC Card Socket 1";
|
154 | 80bbaee6 | Andreas Färber | } else {
|
155 | 80bbaee6 | Andreas Färber | s->slot.slot_string = "PXA PC Card Socket 0";
|
156 | 80bbaee6 | Andreas Färber | } |
157 | 80bbaee6 | Andreas Färber | |
158 | 80bbaee6 | Andreas Färber | qdev_init_nofail(dev); |
159 | 80bbaee6 | Andreas Färber | |
160 | 80bbaee6 | Andreas Färber | return s;
|
161 | 80bbaee6 | Andreas Färber | } |
162 | 80bbaee6 | Andreas Färber | |
163 | 80bbaee6 | Andreas Färber | static void pxa2xx_pcmcia_realize(DeviceState *dev, Error **errp) |
164 | 80bbaee6 | Andreas Färber | { |
165 | 80bbaee6 | Andreas Färber | PXA2xxPCMCIAState *s = PXA2XX_PCMCIA(dev); |
166 | 80bbaee6 | Andreas Färber | |
167 | 80bbaee6 | Andreas Färber | pcmcia_socket_register(&s->slot); |
168 | 80bbaee6 | Andreas Färber | } |
169 | 80bbaee6 | Andreas Färber | |
170 | 80bbaee6 | Andreas Färber | static void pxa2xx_pcmcia_initfn(Object *obj) |
171 | 80bbaee6 | Andreas Färber | { |
172 | 80bbaee6 | Andreas Färber | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
173 | 80bbaee6 | Andreas Färber | PXA2xxPCMCIAState *s = PXA2XX_PCMCIA(obj); |
174 | 80bbaee6 | Andreas Färber | |
175 | 80bbaee6 | Andreas Färber | memory_region_init(&s->container_mem, obj, "container", 0x10000000); |
176 | 80bbaee6 | Andreas Färber | sysbus_init_mmio(sbd, &s->container_mem); |
177 | a171fe39 | balrog | |
178 | a171fe39 | balrog | /* Socket I/O Memory Space */
|
179 | 2c9b15ca | Paolo Bonzini | memory_region_init_io(&s->iomem, NULL, &pxa2xx_pcmcia_io_ops, s,
|
180 | 59aee13c | Benoît Canet | "pxa2xx-pcmcia-io", 0x04000000); |
181 | 80bbaee6 | Andreas Färber | memory_region_add_subregion(&s->container_mem, 0x00000000,
|
182 | 59aee13c | Benoît Canet | &s->iomem); |
183 | a171fe39 | balrog | |
184 | a171fe39 | balrog | /* Then next 64 MB is reserved */
|
185 | a171fe39 | balrog | |
186 | a171fe39 | balrog | /* Socket Attribute Memory Space */
|
187 | 2c9b15ca | Paolo Bonzini | memory_region_init_io(&s->attr_iomem, NULL, &pxa2xx_pcmcia_attr_ops, s,
|
188 | 4beeaa71 | Benoît Canet | "pxa2xx-pcmcia-attribute", 0x04000000); |
189 | 80bbaee6 | Andreas Färber | memory_region_add_subregion(&s->container_mem, 0x08000000,
|
190 | 4beeaa71 | Benoît Canet | &s->attr_iomem); |
191 | a171fe39 | balrog | |
192 | a171fe39 | balrog | /* Socket Common Memory Space */
|
193 | 2c9b15ca | Paolo Bonzini | memory_region_init_io(&s->common_iomem, NULL, &pxa2xx_pcmcia_common_ops, s,
|
194 | 354a8c06 | Benoît Canet | "pxa2xx-pcmcia-common", 0x04000000); |
195 | 80bbaee6 | Andreas Färber | memory_region_add_subregion(&s->container_mem, 0x0c000000,
|
196 | 354a8c06 | Benoît Canet | &s->common_iomem); |
197 | a171fe39 | balrog | |
198 | a171fe39 | balrog | s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0]; |
199 | 3f582262 | balrog | |
200 | 80bbaee6 | Andreas Färber | object_property_add_link(obj, "card", TYPE_PCMCIA_CARD,
|
201 | 80bbaee6 | Andreas Färber | (Object **)&s->card, NULL);
|
202 | a171fe39 | balrog | } |
203 | a171fe39 | balrog | |
204 | a171fe39 | balrog | /* Insert a new card into a slot */
|
205 | bc24a225 | Paul Brook | int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card) |
206 | a171fe39 | balrog | { |
207 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
208 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
209 | d1f2c96a | Andreas Färber | |
210 | d1f2c96a | Andreas Färber | if (s->slot.attached) {
|
211 | a171fe39 | balrog | return -EEXIST;
|
212 | d1f2c96a | Andreas Färber | } |
213 | a171fe39 | balrog | |
214 | a171fe39 | balrog | if (s->cd_irq) {
|
215 | a171fe39 | balrog | qemu_irq_raise(s->cd_irq); |
216 | a171fe39 | balrog | } |
217 | a171fe39 | balrog | |
218 | a171fe39 | balrog | s->card = card; |
219 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
220 | a171fe39 | balrog | |
221 | d1f2c96a | Andreas Färber | s->slot.attached = true;
|
222 | a171fe39 | balrog | s->card->slot = &s->slot; |
223 | d1f2c96a | Andreas Färber | pcc->attach(s->card); |
224 | a171fe39 | balrog | |
225 | a171fe39 | balrog | return 0; |
226 | a171fe39 | balrog | } |
227 | a171fe39 | balrog | |
228 | a171fe39 | balrog | /* Eject card from the slot */
|
229 | 853ca11d | Andreas Färber | int pxa2xx_pcmcia_detach(void *opaque) |
230 | a171fe39 | balrog | { |
231 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
232 | d1f2c96a | Andreas Färber | PCMCIACardClass *pcc; |
233 | d1f2c96a | Andreas Färber | |
234 | d1f2c96a | Andreas Färber | if (!s->slot.attached) {
|
235 | a171fe39 | balrog | return -ENOENT;
|
236 | d1f2c96a | Andreas Färber | } |
237 | a171fe39 | balrog | |
238 | d1f2c96a | Andreas Färber | pcc = PCMCIA_CARD_GET_CLASS(s->card); |
239 | d1f2c96a | Andreas Färber | pcc->detach(s->card); |
240 | b9d38e95 | Blue Swirl | s->card->slot = NULL;
|
241 | b9d38e95 | Blue Swirl | s->card = NULL;
|
242 | a171fe39 | balrog | |
243 | d1f2c96a | Andreas Färber | s->slot.attached = false;
|
244 | a171fe39 | balrog | |
245 | d1f2c96a | Andreas Färber | if (s->irq) {
|
246 | a171fe39 | balrog | qemu_irq_lower(s->irq); |
247 | d1f2c96a | Andreas Färber | } |
248 | d1f2c96a | Andreas Färber | if (s->cd_irq) {
|
249 | a171fe39 | balrog | qemu_irq_lower(s->cd_irq); |
250 | d1f2c96a | Andreas Färber | } |
251 | a171fe39 | balrog | |
252 | a171fe39 | balrog | return 0; |
253 | a171fe39 | balrog | } |
254 | a171fe39 | balrog | |
255 | a171fe39 | balrog | /* Who to notify on card events */
|
256 | a171fe39 | balrog | void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq) |
257 | a171fe39 | balrog | { |
258 | bc24a225 | Paul Brook | PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; |
259 | a171fe39 | balrog | s->irq = irq; |
260 | a171fe39 | balrog | s->cd_irq = cd_irq; |
261 | a171fe39 | balrog | } |
262 | 80bbaee6 | Andreas Färber | |
263 | 80bbaee6 | Andreas Färber | static void pxa2xx_pcmcia_class_init(ObjectClass *oc, void *data) |
264 | 80bbaee6 | Andreas Färber | { |
265 | 80bbaee6 | Andreas Färber | DeviceClass *dc = DEVICE_CLASS(oc); |
266 | 80bbaee6 | Andreas Färber | |
267 | 80bbaee6 | Andreas Färber | dc->realize = pxa2xx_pcmcia_realize; |
268 | 80bbaee6 | Andreas Färber | } |
269 | 80bbaee6 | Andreas Färber | |
270 | 80bbaee6 | Andreas Färber | static const TypeInfo pxa2xx_pcmcia_type_info = { |
271 | 80bbaee6 | Andreas Färber | .name = TYPE_PXA2XX_PCMCIA, |
272 | 80bbaee6 | Andreas Färber | .parent = TYPE_SYS_BUS_DEVICE, |
273 | 80bbaee6 | Andreas Färber | .instance_size = sizeof(PXA2xxPCMCIAState),
|
274 | 80bbaee6 | Andreas Färber | .instance_init = pxa2xx_pcmcia_initfn, |
275 | 80bbaee6 | Andreas Färber | .class_init = pxa2xx_pcmcia_class_init, |
276 | 80bbaee6 | Andreas Färber | }; |
277 | 80bbaee6 | Andreas Färber | |
278 | 80bbaee6 | Andreas Färber | static void pxa2xx_pcmcia_register_types(void) |
279 | 80bbaee6 | Andreas Färber | { |
280 | 80bbaee6 | Andreas Färber | type_register_static(&pxa2xx_pcmcia_type_info); |
281 | 80bbaee6 | Andreas Färber | } |
282 | 80bbaee6 | Andreas Färber | |
283 | 80bbaee6 | Andreas Färber | type_init(pxa2xx_pcmcia_register_types) |