~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/misc/macio/macio.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    MacIOState parent_obj;
53
53
    /*< public >*/
54
54
 
55
 
    qemu_irq irqs[3];
 
55
    qemu_irq irqs[5];
56
56
 
57
57
    MacIONVRAMState nvram;
58
 
    MACIOIDEState ide;
 
58
    MACIOIDEState ide[2];
59
59
} OldWorldMacIOState;
60
60
 
61
61
#define NEWWORLD_MACIO(obj) \
69
69
    MACIOIDEState ide[2];
70
70
} NewWorldMacIOState;
71
71
 
 
72
/*
 
73
 * The mac-io has two interfaces to the ESCC. One is called "escc-legacy",
 
74
 * while the other one is the normal, current ESCC interface.
 
75
 *
 
76
 * The magic below creates memory aliases to spawn the escc-legacy device
 
77
 * purely by rerouting the respective registers to our escc region. This
 
78
 * works because the only difference between the two memory regions is the
 
79
 * register layout, not their semantics.
 
80
 *
 
81
 * Reference: ftp://ftp.software.ibm.com/rs6000/technology/spec/chrp/inwork/CHRP_IORef_1.0.pdf
 
82
 */
 
83
static void macio_escc_legacy_setup(MacIOState *macio_state)
 
84
{
 
85
    MemoryRegion *escc_legacy = g_new(MemoryRegion, 1);
 
86
    MemoryRegion *bar = &macio_state->bar;
 
87
    int i;
 
88
    static const int maps[] = {
 
89
        0x00, 0x00,
 
90
        0x02, 0x20,
 
91
        0x04, 0x10,
 
92
        0x06, 0x30,
 
93
        0x08, 0x40,
 
94
        0x0A, 0x50,
 
95
        0x60, 0x60,
 
96
        0x70, 0x70,
 
97
        0x80, 0x70,
 
98
        0x90, 0x80,
 
99
        0xA0, 0x90,
 
100
        0xB0, 0xA0,
 
101
        0xC0, 0xB0,
 
102
        0xD0, 0xC0,
 
103
        0xE0, 0xD0,
 
104
        0xF0, 0xE0,
 
105
    };
 
106
 
 
107
    memory_region_init(escc_legacy, NULL, "escc-legacy", 256);
 
108
    for (i = 0; i < ARRAY_SIZE(maps); i += 2) {
 
109
        MemoryRegion *port = g_new(MemoryRegion, 1);
 
110
        memory_region_init_alias(port, NULL, "escc-legacy-port",
 
111
                                 macio_state->escc_mem, maps[i+1], 0x2);
 
112
        memory_region_add_subregion(escc_legacy, maps[i], port);
 
113
    }
 
114
 
 
115
    memory_region_add_subregion(bar, 0x12000, escc_legacy);
 
116
}
 
117
 
72
118
static void macio_bar_setup(MacIOState *macio_state)
73
119
{
74
120
    MemoryRegion *bar = &macio_state->bar;
75
121
 
76
122
    if (macio_state->escc_mem) {
77
123
        memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
 
124
        macio_escc_legacy_setup(macio_state);
78
125
    }
79
126
}
80
127
 
100
147
    return 0;
101
148
}
102
149
 
 
150
static int macio_initfn_ide(MacIOState *s, MACIOIDEState *ide, qemu_irq irq0,
 
151
                            qemu_irq irq1, int dmaid)
 
152
{
 
153
    SysBusDevice *sysbus_dev;
 
154
 
 
155
    sysbus_dev = SYS_BUS_DEVICE(ide);
 
156
    sysbus_connect_irq(sysbus_dev, 0, irq0);
 
157
    sysbus_connect_irq(sysbus_dev, 1, irq1);
 
158
    macio_ide_register_dma(ide, s->dbdma, dmaid);
 
159
    return qdev_init(DEVICE(ide));
 
160
}
 
161
 
103
162
static int macio_oldworld_initfn(PCIDevice *d)
104
163
{
105
164
    MacIOState *s = MACIO(d);
106
165
    OldWorldMacIOState *os = OLDWORLD_MACIO(d);
107
166
    SysBusDevice *sysbus_dev;
 
167
    int i;
 
168
    int cur_irq = 0;
108
169
    int ret = macio_common_initfn(d);
109
170
    if (ret < 0) {
110
171
        return ret;
111
172
    }
112
173
 
113
174
    sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
114
 
    sysbus_connect_irq(sysbus_dev, 0, os->irqs[0]);
 
175
    sysbus_connect_irq(sysbus_dev, 0, os->irqs[cur_irq++]);
115
176
 
116
177
    ret = qdev_init(DEVICE(&os->nvram));
117
178
    if (ret < 0) {
127
188
        memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
128
189
    }
129
190
 
130
 
    sysbus_dev = SYS_BUS_DEVICE(&os->ide);
131
 
    sysbus_connect_irq(sysbus_dev, 0, os->irqs[1]);
132
 
    sysbus_connect_irq(sysbus_dev, 1, os->irqs[2]);
133
 
    macio_ide_register_dma(&os->ide, s->dbdma, 0x16);
134
 
    ret = qdev_init(DEVICE(&os->ide));
135
 
    if (ret < 0) {
136
 
        return ret;
 
191
    /* IDE buses */
 
192
    for (i = 0; i < ARRAY_SIZE(os->ide); i++) {
 
193
        qemu_irq irq0 = os->irqs[cur_irq++];
 
194
        qemu_irq irq1 = os->irqs[cur_irq++];
 
195
 
 
196
        ret = macio_initfn_ide(s, &os->ide[i], irq0, irq1, 0x16 + (i * 4));
 
197
        if (ret < 0) {
 
198
            return ret;
 
199
        }
137
200
    }
138
201
 
139
202
    return 0;
140
203
}
141
204
 
 
205
static void macio_init_ide(MacIOState *s, MACIOIDEState *ide, int index)
 
206
{
 
207
    gchar *name;
 
208
 
 
209
    object_initialize(ide, TYPE_MACIO_IDE);
 
210
    qdev_set_parent_bus(DEVICE(ide), sysbus_get_default());
 
211
    memory_region_add_subregion(&s->bar, 0x1f000 + ((index + 1) * 0x1000),
 
212
                                &ide->mem);
 
213
    name = g_strdup_printf("ide[%i]", index);
 
214
    object_property_add_child(OBJECT(s), name, OBJECT(ide), NULL);
 
215
    g_free(name);
 
216
}
 
217
 
142
218
static void macio_oldworld_init(Object *obj)
143
219
{
144
220
    MacIOState *s = MACIO(obj);
145
221
    OldWorldMacIOState *os = OLDWORLD_MACIO(obj);
146
222
    DeviceState *dev;
 
223
    int i;
147
224
 
148
225
    qdev_init_gpio_out(DEVICE(obj), os->irqs, ARRAY_SIZE(os->irqs));
149
226
 
152
229
    qdev_prop_set_uint32(dev, "size", 0x2000);
153
230
    qdev_prop_set_uint32(dev, "it_shift", 4);
154
231
 
155
 
    object_initialize(&os->ide, TYPE_MACIO_IDE);
156
 
    qdev_set_parent_bus(DEVICE(&os->ide), sysbus_get_default());
157
 
    memory_region_add_subregion(&s->bar, 0x1f000 + (1 * 0x1000), &os->ide.mem);
158
 
    object_property_add_child(obj, "ide", OBJECT(&os->ide), NULL);
159
 
}
 
232
    for (i = 0; i < 2; i++) {
 
233
        macio_init_ide(s, &os->ide[i], i);
 
234
    }
 
235
}
 
236
 
 
237
static void timer_write(void *opaque, hwaddr addr, uint64_t value,
 
238
                       unsigned size)
 
239
{
 
240
}
 
241
 
 
242
static uint64_t timer_read(void *opaque, hwaddr addr, unsigned size)
 
243
{
 
244
    uint32_t value = 0;
 
245
 
 
246
    switch (addr) {
 
247
    case 0x38:
 
248
        value = qemu_get_clock_ns(vm_clock);
 
249
        break;
 
250
    case 0x3c:
 
251
        value = qemu_get_clock_ns(vm_clock) >> 32;
 
252
        break;
 
253
    }
 
254
 
 
255
    return value;
 
256
}
 
257
 
 
258
static const MemoryRegionOps timer_ops = {
 
259
    .read = timer_read,
 
260
    .write = timer_write,
 
261
    .endianness = DEVICE_NATIVE_ENDIAN,
 
262
};
160
263
 
161
264
static int macio_newworld_initfn(PCIDevice *d)
162
265
{
163
266
    MacIOState *s = MACIO(d);
164
267
    NewWorldMacIOState *ns = NEWWORLD_MACIO(d);
165
268
    SysBusDevice *sysbus_dev;
 
269
    MemoryRegion *timer_memory = g_new(MemoryRegion, 1);
 
270
    int i;
 
271
    int cur_irq = 0;
166
272
    int ret = macio_common_initfn(d);
167
273
    if (ret < 0) {
168
274
        return ret;
169
275
    }
170
276
 
171
277
    sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
172
 
    sysbus_connect_irq(sysbus_dev, 0, ns->irqs[0]);
 
278
    sysbus_connect_irq(sysbus_dev, 0, ns->irqs[cur_irq++]);
173
279
 
174
280
    if (s->pic_mem) {
175
281
        /* OpenPIC */
176
282
        memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
177
283
    }
178
284
 
179
 
    sysbus_dev = SYS_BUS_DEVICE(&ns->ide[0]);
180
 
    sysbus_connect_irq(sysbus_dev, 0, ns->irqs[1]);
181
 
    sysbus_connect_irq(sysbus_dev, 1, ns->irqs[2]);
182
 
    macio_ide_register_dma(&ns->ide[0], s->dbdma, 0x16);
183
 
    ret = qdev_init(DEVICE(&ns->ide[0]));
184
 
    if (ret < 0) {
185
 
        return ret;
186
 
    }
187
 
 
188
 
    sysbus_dev = SYS_BUS_DEVICE(&ns->ide[1]);
189
 
    sysbus_connect_irq(sysbus_dev, 0, ns->irqs[3]);
190
 
    sysbus_connect_irq(sysbus_dev, 1, ns->irqs[4]);
191
 
    macio_ide_register_dma(&ns->ide[1], s->dbdma, 0x1a);
192
 
    ret = qdev_init(DEVICE(&ns->ide[1]));
193
 
    if (ret < 0) {
194
 
        return ret;
195
 
    }
 
285
    /* IDE buses */
 
286
    for (i = 0; i < ARRAY_SIZE(ns->ide); i++) {
 
287
        qemu_irq irq0 = ns->irqs[cur_irq++];
 
288
        qemu_irq irq1 = ns->irqs[cur_irq++];
 
289
 
 
290
        ret = macio_initfn_ide(s, &ns->ide[i], irq0, irq1, 0x16 + (i * 4));
 
291
        if (ret < 0) {
 
292
            return ret;
 
293
        }
 
294
    }
 
295
 
 
296
    /* Timer */
 
297
    memory_region_init_io(timer_memory, OBJECT(s), &timer_ops, NULL, "timer",
 
298
                          0x1000);
 
299
    memory_region_add_subregion(&s->bar, 0x15000, timer_memory);
196
300
 
197
301
    return 0;
198
302
}
202
306
    MacIOState *s = MACIO(obj);
203
307
    NewWorldMacIOState *ns = NEWWORLD_MACIO(obj);
204
308
    int i;
205
 
    gchar *name;
206
309
 
207
310
    qdev_init_gpio_out(DEVICE(obj), ns->irqs, ARRAY_SIZE(ns->irqs));
208
311
 
209
312
    for (i = 0; i < 2; i++) {
210
 
        object_initialize(&ns->ide[i], TYPE_MACIO_IDE);
211
 
        qdev_set_parent_bus(DEVICE(&ns->ide[i]), sysbus_get_default());
212
 
        memory_region_add_subregion(&s->bar, 0x1f000 + ((i + 1) * 0x1000),
213
 
                                    &ns->ide[i].mem);
214
 
        name = g_strdup_printf("ide[%i]", i);
215
 
        object_property_add_child(obj, name, OBJECT(&ns->ide[i]), NULL);
216
 
        g_free(name);
 
313
        macio_init_ide(s, &ns->ide[i], i);
217
314
    }
218
315
}
219
316
 
222
319
    MacIOState *s = MACIO(obj);
223
320
    MemoryRegion *dbdma_mem;
224
321
 
225
 
    memory_region_init(&s->bar, "macio", 0x80000);
 
322
    memory_region_init(&s->bar, NULL, "macio", 0x80000);
226
323
 
227
324
    object_initialize(&s->cuda, TYPE_CUDA);
228
325
    qdev_set_parent_bus(DEVICE(&s->cuda), sysbus_get_default());