root / hw / ide / isa.c @ e7b9bc3e
History | View | Annotate | Download (3.6 kB)
1 | ec82026c | Gerd Hoffmann | /*
|
---|---|---|---|
2 | ec82026c | Gerd Hoffmann | * QEMU IDE Emulation: ISA Bus support.
|
3 | ec82026c | Gerd Hoffmann | *
|
4 | ec82026c | Gerd Hoffmann | * Copyright (c) 2003 Fabrice Bellard
|
5 | ec82026c | Gerd Hoffmann | * Copyright (c) 2006 Openedhand Ltd.
|
6 | ec82026c | Gerd Hoffmann | *
|
7 | ec82026c | Gerd Hoffmann | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | ec82026c | Gerd Hoffmann | * of this software and associated documentation files (the "Software"), to deal
|
9 | ec82026c | Gerd Hoffmann | * in the Software without restriction, including without limitation the rights
|
10 | ec82026c | Gerd Hoffmann | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | ec82026c | Gerd Hoffmann | * copies of the Software, and to permit persons to whom the Software is
|
12 | ec82026c | Gerd Hoffmann | * furnished to do so, subject to the following conditions:
|
13 | ec82026c | Gerd Hoffmann | *
|
14 | ec82026c | Gerd Hoffmann | * The above copyright notice and this permission notice shall be included in
|
15 | ec82026c | Gerd Hoffmann | * all copies or substantial portions of the Software.
|
16 | ec82026c | Gerd Hoffmann | *
|
17 | ec82026c | Gerd Hoffmann | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | ec82026c | Gerd Hoffmann | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | ec82026c | Gerd Hoffmann | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | ec82026c | Gerd Hoffmann | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | ec82026c | Gerd Hoffmann | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | ec82026c | Gerd Hoffmann | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | ec82026c | Gerd Hoffmann | * THE SOFTWARE.
|
24 | ec82026c | Gerd Hoffmann | */
|
25 | 59f2a787 | Gerd Hoffmann | #include <hw/hw.h> |
26 | 59f2a787 | Gerd Hoffmann | #include <hw/pc.h> |
27 | dea21e97 | Gerd Hoffmann | #include <hw/isa.h> |
28 | ec82026c | Gerd Hoffmann | #include "block.h" |
29 | ec82026c | Gerd Hoffmann | #include "block_int.h" |
30 | ec82026c | Gerd Hoffmann | #include "dma.h" |
31 | 59f2a787 | Gerd Hoffmann | |
32 | 59f2a787 | Gerd Hoffmann | #include <hw/ide/internal.h> |
33 | ec82026c | Gerd Hoffmann | |
34 | ec82026c | Gerd Hoffmann | /***********************************************************/
|
35 | ec82026c | Gerd Hoffmann | /* ISA IDE definitions */
|
36 | ec82026c | Gerd Hoffmann | |
37 | cebbe6d4 | Gerd Hoffmann | typedef struct ISAIDEState { |
38 | dea21e97 | Gerd Hoffmann | ISADevice dev; |
39 | 1f850f10 | Gerd Hoffmann | IDEBus bus; |
40 | dea21e97 | Gerd Hoffmann | uint32_t iobase; |
41 | dea21e97 | Gerd Hoffmann | uint32_t iobase2; |
42 | dea21e97 | Gerd Hoffmann | uint32_t isairq; |
43 | dea21e97 | Gerd Hoffmann | qemu_irq irq; |
44 | cebbe6d4 | Gerd Hoffmann | } ISAIDEState; |
45 | cebbe6d4 | Gerd Hoffmann | |
46 | 4a643563 | Blue Swirl | static void isa_ide_reset(DeviceState *d) |
47 | 4a643563 | Blue Swirl | { |
48 | 4a643563 | Blue Swirl | ISAIDEState *s = container_of(d, ISAIDEState, dev.qdev); |
49 | 4a643563 | Blue Swirl | |
50 | 4a643563 | Blue Swirl | ide_bus_reset(&s->bus); |
51 | 4a643563 | Blue Swirl | } |
52 | 4a643563 | Blue Swirl | |
53 | 200ab5e2 | Juan Quintela | static const VMStateDescription vmstate_ide_isa = { |
54 | 200ab5e2 | Juan Quintela | .name = "isa-ide",
|
55 | 200ab5e2 | Juan Quintela | .version_id = 3,
|
56 | 200ab5e2 | Juan Quintela | .minimum_version_id = 0,
|
57 | 200ab5e2 | Juan Quintela | .minimum_version_id_old = 0,
|
58 | 200ab5e2 | Juan Quintela | .fields = (VMStateField []) { |
59 | 200ab5e2 | Juan Quintela | VMSTATE_IDE_BUS(bus, ISAIDEState), |
60 | 200ab5e2 | Juan Quintela | VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState), |
61 | 200ab5e2 | Juan Quintela | VMSTATE_END_OF_LIST() |
62 | 200ab5e2 | Juan Quintela | } |
63 | 200ab5e2 | Juan Quintela | }; |
64 | cebbe6d4 | Gerd Hoffmann | |
65 | dea21e97 | Gerd Hoffmann | static int isa_ide_initfn(ISADevice *dev) |
66 | ec82026c | Gerd Hoffmann | { |
67 | dea21e97 | Gerd Hoffmann | ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev); |
68 | dea21e97 | Gerd Hoffmann | |
69 | 3835510f | Gleb Natapov | ide_bus_new(&s->bus, &s->dev.qdev, 0);
|
70 | 1f850f10 | Gerd Hoffmann | ide_init_ioport(&s->bus, s->iobase, s->iobase2); |
71 | dea21e97 | Gerd Hoffmann | isa_init_irq(dev, &s->irq, s->isairq); |
72 | dee41d58 | Gleb Natapov | isa_init_ioport_range(dev, s->iobase, 8);
|
73 | dee41d58 | Gleb Natapov | isa_init_ioport(dev, s->iobase2); |
74 | 57234ee4 | Markus Armbruster | ide_init2(&s->bus, s->irq); |
75 | 0be71e32 | Alex Williamson | vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
|
76 | dea21e97 | Gerd Hoffmann | return 0; |
77 | dea21e97 | Gerd Hoffmann | }; |
78 | dea21e97 | Gerd Hoffmann | |
79 | 57c88866 | Markus Armbruster | ISADevice *isa_ide_init(int iobase, int iobase2, int isairq, |
80 | 57c88866 | Markus Armbruster | DriveInfo *hd0, DriveInfo *hd1) |
81 | dea21e97 | Gerd Hoffmann | { |
82 | dea21e97 | Gerd Hoffmann | ISADevice *dev; |
83 | cebbe6d4 | Gerd Hoffmann | ISAIDEState *s; |
84 | ec82026c | Gerd Hoffmann | |
85 | dea21e97 | Gerd Hoffmann | dev = isa_create("isa-ide");
|
86 | dea21e97 | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "iobase", iobase);
|
87 | dea21e97 | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
|
88 | dea21e97 | Gerd Hoffmann | qdev_prop_set_uint32(&dev->qdev, "irq", isairq);
|
89 | 5c17ca25 | Markus Armbruster | if (qdev_init(&dev->qdev) < 0) |
90 | 57c88866 | Markus Armbruster | return NULL; |
91 | ec82026c | Gerd Hoffmann | |
92 | dea21e97 | Gerd Hoffmann | s = DO_UPCAST(ISAIDEState, dev, dev); |
93 | dea21e97 | Gerd Hoffmann | if (hd0)
|
94 | 1f850f10 | Gerd Hoffmann | ide_create_drive(&s->bus, 0, hd0);
|
95 | dea21e97 | Gerd Hoffmann | if (hd1)
|
96 | 1f850f10 | Gerd Hoffmann | ide_create_drive(&s->bus, 1, hd1);
|
97 | 57c88866 | Markus Armbruster | return dev;
|
98 | dea21e97 | Gerd Hoffmann | } |
99 | dea21e97 | Gerd Hoffmann | |
100 | dea21e97 | Gerd Hoffmann | static ISADeviceInfo isa_ide_info = {
|
101 | dea21e97 | Gerd Hoffmann | .qdev.name = "isa-ide",
|
102 | 779206de | Gleb Natapov | .qdev.fw_name = "ide",
|
103 | dea21e97 | Gerd Hoffmann | .qdev.size = sizeof(ISAIDEState),
|
104 | dea21e97 | Gerd Hoffmann | .init = isa_ide_initfn, |
105 | 4a643563 | Blue Swirl | .qdev.reset = isa_ide_reset, |
106 | dea21e97 | Gerd Hoffmann | .qdev.props = (Property[]) { |
107 | dea21e97 | Gerd Hoffmann | DEFINE_PROP_HEX32("iobase", ISAIDEState, iobase, 0x1f0), |
108 | dea21e97 | Gerd Hoffmann | DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6), |
109 | dea21e97 | Gerd Hoffmann | DEFINE_PROP_UINT32("irq", ISAIDEState, isairq, 14), |
110 | dea21e97 | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
111 | dea21e97 | Gerd Hoffmann | }, |
112 | dea21e97 | Gerd Hoffmann | }; |
113 | dea21e97 | Gerd Hoffmann | |
114 | dea21e97 | Gerd Hoffmann | static void isa_ide_register_devices(void) |
115 | dea21e97 | Gerd Hoffmann | { |
116 | dea21e97 | Gerd Hoffmann | isa_qdev_register(&isa_ide_info); |
117 | ec82026c | Gerd Hoffmann | } |
118 | dea21e97 | Gerd Hoffmann | |
119 | dea21e97 | Gerd Hoffmann | device_init(isa_ide_register_devices) |