]>
Commit | Line | Data |
---|---|---|
23b96cdb AF |
1 | /* |
2 | * QEMU Intel 82374 emulation (Enhanced DMA controller) | |
3 | * | |
4 | * Copyright (c) 2010 Hervé Poussineau | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | ||
0430891c | 25 | #include "qemu/osdep.h" |
4968a2c6 | 26 | #include "qapi/error.h" |
0b8fa32f | 27 | #include "qemu/module.h" |
0d09e41a | 28 | #include "hw/isa/isa.h" |
a27bd6c7 | 29 | #include "hw/qdev-properties.h" |
d6454270 | 30 | #include "migration/vmstate.h" |
55f613ac | 31 | #include "hw/dma/i8257.h" |
db1015e9 | 32 | #include "qom/object.h" |
23b96cdb | 33 | |
449ae7ec | 34 | #define TYPE_I82374 "i82374" |
8063396b | 35 | OBJECT_DECLARE_SIMPLE_TYPE(I82374State, I82374) |
449ae7ec | 36 | |
23b96cdb AF |
37 | //#define DEBUG_I82374 |
38 | ||
39 | #ifdef DEBUG_I82374 | |
40 | #define DPRINTF(fmt, ...) \ | |
41 | do { fprintf(stderr, "i82374: " fmt , ## __VA_ARGS__); } while (0) | |
42 | #else | |
43 | #define DPRINTF(fmt, ...) \ | |
44 | do {} while (0) | |
45 | #endif | |
46 | #define BADF(fmt, ...) \ | |
47 | do { fprintf(stderr, "i82374 ERROR: " fmt , ## __VA_ARGS__); } while (0) | |
48 | ||
db1015e9 | 49 | struct I82374State { |
449ae7ec HP |
50 | ISADevice parent_obj; |
51 | ||
52 | uint32_t iobase; | |
23b96cdb | 53 | uint8_t commands[8]; |
848696bf | 54 | PortioList port_list; |
db1015e9 | 55 | }; |
23b96cdb AF |
56 | |
57 | static const VMStateDescription vmstate_i82374 = { | |
58 | .name = "i82374", | |
59 | .version_id = 0, | |
60 | .minimum_version_id = 0, | |
61 | .fields = (VMStateField[]) { | |
62 | VMSTATE_UINT8_ARRAY(commands, I82374State, 8), | |
63 | VMSTATE_END_OF_LIST() | |
64 | }, | |
65 | }; | |
66 | ||
67 | static uint32_t i82374_read_isr(void *opaque, uint32_t nport) | |
68 | { | |
69 | uint32_t val = 0; | |
70 | ||
71 | BADF("%s: %08x\n", __func__, nport); | |
72 | ||
73 | DPRINTF("%s: %08x=%08x\n", __func__, nport, val); | |
74 | return val; | |
75 | } | |
76 | ||
77 | static void i82374_write_command(void *opaque, uint32_t nport, uint32_t data) | |
78 | { | |
79 | DPRINTF("%s: %08x=%08x\n", __func__, nport, data); | |
80 | ||
81 | if (data != 0x42) { | |
82 | /* Not Stop S/G command */ | |
83 | BADF("%s: %08x=%08x\n", __func__, nport, data); | |
84 | } | |
85 | } | |
86 | ||
87 | static uint32_t i82374_read_status(void *opaque, uint32_t nport) | |
88 | { | |
89 | uint32_t val = 0; | |
90 | ||
91 | BADF("%s: %08x\n", __func__, nport); | |
92 | ||
93 | DPRINTF("%s: %08x=%08x\n", __func__, nport, val); | |
94 | return val; | |
95 | } | |
96 | ||
97 | static void i82374_write_descriptor(void *opaque, uint32_t nport, uint32_t data) | |
98 | { | |
99 | DPRINTF("%s: %08x=%08x\n", __func__, nport, data); | |
100 | ||
101 | BADF("%s: %08x=%08x\n", __func__, nport, data); | |
102 | } | |
103 | ||
104 | static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport) | |
105 | { | |
106 | uint32_t val = 0; | |
107 | ||
108 | BADF("%s: %08x\n", __func__, nport); | |
109 | ||
110 | DPRINTF("%s: %08x=%08x\n", __func__, nport, val); | |
111 | return val; | |
112 | } | |
113 | ||
f94b64ac JK |
114 | static const MemoryRegionPortio i82374_portio_list[] = { |
115 | { 0x0A, 1, 1, .read = i82374_read_isr, }, | |
116 | { 0x10, 8, 1, .write = i82374_write_command, }, | |
117 | { 0x18, 8, 1, .read = i82374_read_status, }, | |
118 | { 0x20, 0x20, 1, | |
119 | .write = i82374_write_descriptor, .read = i82374_read_descriptor, }, | |
120 | PORTIO_END_OF_LIST(), | |
121 | }; | |
122 | ||
449ae7ec | 123 | static void i82374_realize(DeviceState *dev, Error **errp) |
23b96cdb | 124 | { |
449ae7ec | 125 | I82374State *s = I82374(dev); |
4968a2c6 PMD |
126 | ISABus *isa_bus = isa_bus_from_device(ISA_DEVICE(dev)); |
127 | ||
dc8d6cf2 | 128 | if (isa_bus_get_dma(isa_bus, 0)) { |
4968a2c6 PMD |
129 | error_setg(errp, "DMA already initialized on ISA bus"); |
130 | return; | |
131 | } | |
132 | i8257_dma_init(isa_bus, true); | |
23b96cdb | 133 | |
449ae7ec | 134 | portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s, |
848696bf | 135 | "i82374"); |
449ae7ec HP |
136 | portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj), |
137 | s->iobase); | |
23b96cdb | 138 | |
449ae7ec | 139 | memset(s->commands, 0, sizeof(s->commands)); |
23b96cdb AF |
140 | } |
141 | ||
39bffca2 | 142 | static Property i82374_properties[] = { |
449ae7ec | 143 | DEFINE_PROP_UINT32("iobase", I82374State, iobase, 0x400), |
39bffca2 AL |
144 | DEFINE_PROP_END_OF_LIST() |
145 | }; | |
146 | ||
8f04ee08 AL |
147 | static void i82374_class_init(ObjectClass *klass, void *data) |
148 | { | |
39bffca2 | 149 | DeviceClass *dc = DEVICE_CLASS(klass); |
8f04ee08 | 150 | |
449ae7ec HP |
151 | dc->realize = i82374_realize; |
152 | dc->vmsd = &vmstate_i82374; | |
4f67d30b | 153 | device_class_set_props(dc, i82374_properties); |
8f04ee08 AL |
154 | } |
155 | ||
449ae7ec | 156 | static const TypeInfo i82374_info = { |
eb1440e7 | 157 | .name = TYPE_I82374, |
39bffca2 | 158 | .parent = TYPE_ISA_DEVICE, |
449ae7ec | 159 | .instance_size = sizeof(I82374State), |
8f04ee08 | 160 | .class_init = i82374_class_init, |
23b96cdb AF |
161 | }; |
162 | ||
83f7d43a | 163 | static void i82374_register_types(void) |
23b96cdb | 164 | { |
449ae7ec | 165 | type_register_static(&i82374_info); |
23b96cdb AF |
166 | } |
167 | ||
83f7d43a | 168 | type_init(i82374_register_types) |