New patch
1
This series fixes some runtime overhead when handling interrupts in AHCIState.
2
It then extracts the SysBus implementation into a dedicated file for separation
3
of concerns.
1
4
5
v4:
6
* Port away from qemu_allocate_irq() while at it
7
8
v3:
9
* Remove extra PCI include in ahci-internal.h
10
* Extract SysBus implementation into dedicated file
11
12
Supersedes: 20241205114453.1848-1-shentey@gmail.com
13
14
Bernhard Beschow (2):
15
hw/ide/ahci: Decouple from PCI
16
hw/ide/ahci: Extract TYPE_SYSBUS_AHCI into dedicated file
17
18
hw/ide/ahci-internal.h | 1 -
19
include/hw/ide/ahci-pci.h | 2 +
20
include/hw/ide/ahci.h | 2 -
21
hw/ide/ahci-sysbus.c | 91 ++++++++++++++++++++++++++++++++
22
hw/ide/ahci.c | 106 ++------------------------------------
23
hw/ide/ich.c | 19 +++++--
24
hw/arm/Kconfig | 10 ++--
25
hw/ide/Kconfig | 4 ++
26
hw/ide/meson.build | 1 +
27
9 files changed, 122 insertions(+), 114 deletions(-)
28
create mode 100644 hw/ide/ahci-sysbus.c
29
30
--
31
2.47.1
32
diff view generated by jsdifflib
...
...
9
reflected in Kconfig.
9
reflected in Kconfig.
10
10
11
Reported-by: Peter Xu <peterx@redhat.com>
11
Reported-by: Peter Xu <peterx@redhat.com>
12
Inspired-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12
Inspired-by: Philippe Mathieu-Daudé <philmd@linaro.org>
13
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
13
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
14
15
--
16
Supersedes: 20241121100152.65476-1-philmd@linaro.org
17
---
14
---
18
include/hw/ide/ahci.h | 2 --
15
hw/ide/ahci-internal.h | 1 -
19
hw/ide/ahci.c | 39 ++++-----------------------------------
16
include/hw/ide/ahci-pci.h | 2 ++
20
hw/ide/ich.c | 17 ++++++++++++++++-
17
include/hw/ide/ahci.h | 2 --
21
3 files changed, 20 insertions(+), 38 deletions(-)
18
hw/ide/ahci.c | 39 ++++-----------------------------------
22
19
hw/ide/ich.c | 19 +++++++++++++++----
20
5 files changed, 21 insertions(+), 42 deletions(-)
21
22
diff --git a/hw/ide/ahci-internal.h b/hw/ide/ahci-internal.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/ide/ahci-internal.h
25
+++ b/hw/ide/ahci-internal.h
26
@@ -XXX,XX +XXX,XX @@
27
#define HW_IDE_AHCI_INTERNAL_H
28
29
#include "hw/ide/ahci.h"
30
-#include "hw/pci/pci_device.h"
31
#include "ide-internal.h"
32
33
#define AHCI_MEM_BAR_SIZE 0x1000
34
diff --git a/include/hw/ide/ahci-pci.h b/include/hw/ide/ahci-pci.h
35
index XXXXXXX..XXXXXXX 100644
36
--- a/include/hw/ide/ahci-pci.h
37
+++ b/include/hw/ide/ahci-pci.h
38
@@ -XXX,XX +XXX,XX @@
39
#include "qom/object.h"
40
#include "hw/ide/ahci.h"
41
#include "hw/pci/pci_device.h"
42
+#include "hw/irq.h"
43
44
#define TYPE_ICH9_AHCI "ich9-ahci"
45
OBJECT_DECLARE_SIMPLE_TYPE(AHCIPCIState, ICH9_AHCI)
46
@@ -XXX,XX +XXX,XX @@ struct AHCIPCIState {
47
PCIDevice parent_obj;
48
49
AHCIState ahci;
50
+ IRQState irq;
51
};
52
53
#endif
23
diff --git a/include/hw/ide/ahci.h b/include/hw/ide/ahci.h
54
diff --git a/include/hw/ide/ahci.h b/include/hw/ide/ahci.h
24
index XXXXXXX..XXXXXXX 100644
55
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/ide/ahci.h
56
--- a/include/hw/ide/ahci.h
26
+++ b/include/hw/ide/ahci.h
57
+++ b/include/hw/ide/ahci.h
27
@@ -XXX,XX +XXX,XX @@ typedef struct AHCIControlRegs {
58
@@ -XXX,XX +XXX,XX @@ typedef struct AHCIControlRegs {
...
...
114
"ahci", AHCI_MEM_BAR_SIZE);
145
"ahci", AHCI_MEM_BAR_SIZE);
115
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
146
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
116
index XXXXXXX..XXXXXXX 100644
147
index XXXXXXX..XXXXXXX 100644
117
--- a/hw/ide/ich.c
148
--- a/hw/ide/ich.c
118
+++ b/hw/ide/ich.c
149
+++ b/hw/ide/ich.c
150
@@ -XXX,XX +XXX,XX @@
151
*/
152
153
#include "qemu/osdep.h"
154
-#include "hw/irq.h"
155
#include "hw/pci/msi.h"
156
#include "hw/pci/pci.h"
157
#include "migration/vmstate.h"
119
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ich9_ahci = {
158
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ich9_ahci = {
120
},
159
},
121
};
160
};
122
161
123
+static void pci_ich9_ahci_update_irq(void *opaque, int irq_num, int level)
162
+static void pci_ich9_ahci_update_irq(void *opaque, int irq_num, int level)
124
+{
163
+{
125
+ PCIDevice *pci_dev = opaque;
164
+ PCIDevice *pci_dev = opaque;
126
+
127
+ assert(irq_num == 0);
128
+
165
+
129
+ if (msi_enabled(pci_dev)) {
166
+ if (msi_enabled(pci_dev)) {
130
+ if (level) {
167
+ if (level) {
131
+ msi_notify(pci_dev, 0);
168
+ msi_notify(pci_dev, 0);
132
+ }
169
+ }
...
...
136
+}
173
+}
137
+
174
+
138
static void pci_ich9_reset(DeviceState *dev)
175
static void pci_ich9_reset(DeviceState *dev)
139
{
176
{
140
AHCIPCIState *d = ICH9_AHCI(dev);
177
AHCIPCIState *d = ICH9_AHCI(dev);
178
@@ -XXX,XX +XXX,XX @@ static void pci_ich9_ahci_init(Object *obj)
179
{
180
AHCIPCIState *d = ICH9_AHCI(obj);
181
182
+ qemu_init_irq(&d->irq, pci_ich9_ahci_update_irq, d, 0);
183
ahci_init(&d->ahci, DEVICE(obj));
184
+ d->ahci.irq = &d->irq;
185
}
186
187
static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)
141
@@ -XXX,XX +XXX,XX @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)
188
@@ -XXX,XX +XXX,XX @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)
142
/* XXX Software should program this register */
189
/* XXX Software should program this register */
143
dev->config[0x90] = 1 << 6; /* Address Map Register - AHCI mode */
190
dev->config[0x90] = 1 << 6; /* Address Map Register - AHCI mode */
144
191
145
- d->ahci.irq = pci_allocate_irq(dev);
192
- d->ahci.irq = pci_allocate_irq(dev);
146
+ d->ahci.irq = qemu_allocate_irq(pci_ich9_ahci_update_irq, d, 0);
193
-
147
148
pci_register_bar(dev, ICH9_IDP_BAR, PCI_BASE_ADDRESS_SPACE_IO,
194
pci_register_bar(dev, ICH9_IDP_BAR, PCI_BASE_ADDRESS_SPACE_IO,
149
&d->ahci.idp);
195
&d->ahci.idp);
196
pci_register_bar(dev, ICH9_MEM_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY,
197
@@ -XXX,XX +XXX,XX @@ static void pci_ich9_uninit(PCIDevice *dev)
198
199
msi_uninit(dev);
200
ahci_uninit(&d->ahci);
201
- qemu_free_irq(d->ahci.irq);
202
}
203
204
static void ich_ahci_class_init(ObjectClass *klass, void *data)
150
--
205
--
151
2.47.1
206
2.47.1
152
207
153
208
diff view generated by jsdifflib
New patch
1
Implement in dedicated file, just like TYPE_ICH9_AHCI.
1
2
3
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
4
---
5
hw/ide/ahci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++++++
6
hw/ide/ahci.c | 67 --------------------------------
7
hw/arm/Kconfig | 10 ++---
8
hw/ide/Kconfig | 4 ++
9
hw/ide/meson.build | 1 +
10
5 files changed, 101 insertions(+), 72 deletions(-)
11
create mode 100644 hw/ide/ahci-sysbus.c
12
13
diff --git a/hw/ide/ahci-sysbus.c b/hw/ide/ahci-sysbus.c
14
new file mode 100644
15
index XXXXXXX..XXXXXXX
16
--- /dev/null
17
+++ b/hw/ide/ahci-sysbus.c
18
@@ -XXX,XX +XXX,XX @@
19
+/*
20
+ * QEMU AHCI Emulation (MMIO-mapped devices)
21
+ *
22
+ * Copyright (c) 2010 qiaochong@loongson.cn
23
+ * Copyright (c) 2010 Roland Elek <elek.roland@gmail.com>
24
+ * Copyright (c) 2010 Sebastian Herbszt <herbszt@gmx.de>
25
+ * Copyright (c) 2010 Alexander Graf <agraf@suse.de>
26
+ *
27
+ * This library is free software; you can redistribute it and/or
28
+ * modify it under the terms of the GNU Lesser General Public
29
+ * License as published by the Free Software Foundation; either
30
+ * version 2.1 of the License, or (at your option) any later version.
31
+ *
32
+ * This library is distributed in the hope that it will be useful,
33
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35
+ * Lesser General Public License for more details.
36
+ *
37
+ * You should have received a copy of the GNU Lesser General Public
38
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
39
+ *
40
+ */
41
+
42
+#include "qemu/osdep.h"
43
+#include "exec/address-spaces.h"
44
+#include "hw/qdev-properties.h"
45
+#include "migration/vmstate.h"
46
+
47
+#include "hw/ide/ahci-sysbus.h"
48
+#include "ahci-internal.h"
49
+
50
+static const VMStateDescription vmstate_sysbus_ahci = {
51
+ .name = "sysbus-ahci",
52
+ .fields = (const VMStateField[]) {
53
+ VMSTATE_AHCI(ahci, SysbusAHCIState),
54
+ VMSTATE_END_OF_LIST()
55
+ },
56
+};
57
+
58
+static void sysbus_ahci_reset(DeviceState *dev)
59
+{
60
+ SysbusAHCIState *s = SYSBUS_AHCI(dev);
61
+
62
+ ahci_reset(&s->ahci);
63
+}
64
+
65
+static void sysbus_ahci_init(Object *obj)
66
+{
67
+ SysbusAHCIState *s = SYSBUS_AHCI(obj);
68
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
69
+
70
+ ahci_init(&s->ahci, DEVICE(obj));
71
+
72
+ sysbus_init_mmio(sbd, &s->ahci.mem);
73
+ sysbus_init_irq(sbd, &s->ahci.irq);
74
+}
75
+
76
+static void sysbus_ahci_realize(DeviceState *dev, Error **errp)
77
+{
78
+ SysbusAHCIState *s = SYSBUS_AHCI(dev);
79
+
80
+ ahci_realize(&s->ahci, dev, &address_space_memory);
81
+}
82
+
83
+static Property sysbus_ahci_properties[] = {
84
+ DEFINE_PROP_UINT32("num-ports", SysbusAHCIState, ahci.ports, 1),
85
+ DEFINE_PROP_END_OF_LIST(),
86
+};
87
+
88
+static void sysbus_ahci_class_init(ObjectClass *klass, void *data)
89
+{
90
+ DeviceClass *dc = DEVICE_CLASS(klass);
91
+
92
+ dc->realize = sysbus_ahci_realize;
93
+ dc->vmsd = &vmstate_sysbus_ahci;
94
+ device_class_set_props(dc, sysbus_ahci_properties);
95
+ device_class_set_legacy_reset(dc, sysbus_ahci_reset);
96
+ set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
97
+}
98
+
99
+static const TypeInfo sysbus_ahci_types[] = {
100
+ {
101
+ .name = TYPE_SYSBUS_AHCI,
102
+ .parent = TYPE_SYS_BUS_DEVICE,
103
+ .instance_size = sizeof(SysbusAHCIState),
104
+ .instance_init = sysbus_ahci_init,
105
+ .class_init = sysbus_ahci_class_init,
106
+ },
107
+};
108
+
109
+DEFINE_TYPES(sysbus_ahci_types)
110
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/hw/ide/ahci.c
113
+++ b/hw/ide/ahci.c
114
@@ -XXX,XX +XXX,XX @@
115
116
#include "qemu/osdep.h"
117
#include "hw/irq.h"
118
-#include "hw/qdev-properties.h"
119
#include "migration/vmstate.h"
120
121
#include "qemu/error-report.h"
122
#include "qemu/log.h"
123
#include "qemu/main-loop.h"
124
-#include "qemu/module.h"
125
#include "sysemu/block-backend.h"
126
#include "sysemu/dma.h"
127
-#include "hw/ide/ahci-sysbus.h"
128
#include "ahci-internal.h"
129
#include "ide-internal.h"
130
131
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_ahci = {
132
},
133
};
134
135
-static const VMStateDescription vmstate_sysbus_ahci = {
136
- .name = "sysbus-ahci",
137
- .fields = (const VMStateField[]) {
138
- VMSTATE_AHCI(ahci, SysbusAHCIState),
139
- VMSTATE_END_OF_LIST()
140
- },
141
-};
142
-
143
-static void sysbus_ahci_reset(DeviceState *dev)
144
-{
145
- SysbusAHCIState *s = SYSBUS_AHCI(dev);
146
-
147
- ahci_reset(&s->ahci);
148
-}
149
-
150
-static void sysbus_ahci_init(Object *obj)
151
-{
152
- SysbusAHCIState *s = SYSBUS_AHCI(obj);
153
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
154
-
155
- ahci_init(&s->ahci, DEVICE(obj));
156
-
157
- sysbus_init_mmio(sbd, &s->ahci.mem);
158
- sysbus_init_irq(sbd, &s->ahci.irq);
159
-}
160
-
161
-static void sysbus_ahci_realize(DeviceState *dev, Error **errp)
162
-{
163
- SysbusAHCIState *s = SYSBUS_AHCI(dev);
164
-
165
- ahci_realize(&s->ahci, dev, &address_space_memory);
166
-}
167
-
168
-static Property sysbus_ahci_properties[] = {
169
- DEFINE_PROP_UINT32("num-ports", SysbusAHCIState, ahci.ports, 1),
170
- DEFINE_PROP_END_OF_LIST(),
171
-};
172
-
173
-static void sysbus_ahci_class_init(ObjectClass *klass, void *data)
174
-{
175
- DeviceClass *dc = DEVICE_CLASS(klass);
176
-
177
- dc->realize = sysbus_ahci_realize;
178
- dc->vmsd = &vmstate_sysbus_ahci;
179
- device_class_set_props(dc, sysbus_ahci_properties);
180
- device_class_set_legacy_reset(dc, sysbus_ahci_reset);
181
- set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
182
-}
183
-
184
-static const TypeInfo sysbus_ahci_info = {
185
- .name = TYPE_SYSBUS_AHCI,
186
- .parent = TYPE_SYS_BUS_DEVICE,
187
- .instance_size = sizeof(SysbusAHCIState),
188
- .instance_init = sysbus_ahci_init,
189
- .class_init = sysbus_ahci_class_init,
190
-};
191
-
192
-static void sysbus_ahci_register_types(void)
193
-{
194
- type_register_static(&sysbus_ahci_info);
195
-}
196
-
197
-type_init(sysbus_ahci_register_types)
198
-
199
void ahci_ide_create_devs(AHCIState *ahci, DriveInfo **hd)
200
{
201
int i;
202
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
203
index XXXXXXX..XXXXXXX 100644
204
--- a/hw/arm/Kconfig
205
+++ b/hw/arm/Kconfig
206
@@ -XXX,XX +XXX,XX @@ config HIGHBANK
207
depends on TCG && ARM
208
select A9MPCORE
209
select A15MPCORE
210
- select AHCI
211
+ select AHCI_SYSBUS
212
select ARM_TIMER # sp804
213
select ARM_V7M
214
select PL011 if !HAVE_RUST # UART
215
@@ -XXX,XX +XXX,XX @@ config SBSA_REF
216
depends on TCG && AARCH64
217
imply PCI_DEVICES
218
select DEVICE_TREE
219
- select AHCI
220
+ select AHCI_SYSBUS
221
select ARM_SMMUV3
222
select GPIO_KEY
223
select PCI_EXPRESS
224
@@ -XXX,XX +XXX,XX @@ config ARM_V7M
225
226
config ALLWINNER_A10
227
bool
228
- select AHCI
229
+ select AHCI_SYSBUS
230
select ALLWINNER_A10_PIT
231
select ALLWINNER_A10_PIC
232
select ALLWINNER_A10_CCM
233
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
234
config ALLWINNER_R40
235
bool
236
default y if TCG && ARM
237
- select AHCI
238
+ select AHCI_SYSBUS
239
select ALLWINNER_SRAMC
240
select ALLWINNER_A10_PIT
241
select ALLWINNER_WDT
242
@@ -XXX,XX +XXX,XX @@ config XLNX_ZYNQMP_ARM
243
bool
244
default y if PIXMAN
245
depends on TCG && AARCH64
246
- select AHCI
247
+ select AHCI_SYSBUS
248
select ARM_GIC
249
select CADENCE
250
select CPU_CLUSTER
251
diff --git a/hw/ide/Kconfig b/hw/ide/Kconfig
252
index XXXXXXX..XXXXXXX 100644
253
--- a/hw/ide/Kconfig
254
+++ b/hw/ide/Kconfig
255
@@ -XXX,XX +XXX,XX @@ config AHCI_ICH9
256
depends on PCI
257
select AHCI
258
259
+config AHCI_SYSBUS
260
+ bool
261
+ select AHCI
262
+
263
config IDE_SII3112
264
bool
265
select IDE_PCI
266
diff --git a/hw/ide/meson.build b/hw/ide/meson.build
267
index XXXXXXX..XXXXXXX 100644
268
--- a/hw/ide/meson.build
269
+++ b/hw/ide/meson.build
270
@@ -XXX,XX +XXX,XX @@
271
system_ss.add(when: 'CONFIG_AHCI', if_true: files('ahci.c'))
272
system_ss.add(when: 'CONFIG_AHCI_ICH9', if_true: files('ich.c'))
273
+system_ss.add(when: 'CONFIG_AHCI_SYSBUS', if_true: files('ahci-sysbus.c'))
274
system_ss.add(when: 'CONFIG_ALLWINNER_A10', if_true: files('ahci-allwinner.c'))
275
system_ss.add(when: 'CONFIG_IDE_BUS', if_true: files('ide-bus.c'))
276
system_ss.add(when: 'CONFIG_IDE_CF', if_true: files('cf.c'))
277
--
278
2.47.1
diff view generated by jsdifflib