~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to hw/piix_pci.c

  • Committer: ths
  • Date: 2007-06-17 15:32:30 UTC
  • Revision ID: git-v1:ffb04fcf089865952592f1f8855c2848d4514a89
Allow relative paths for the interpreter prefix in linux-user emulation.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2984 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * QEMU i440FX/PIIX3 PCI Bridge Emulation
3
3
 *
4
4
 * Copyright (c) 2006 Fabrice Bellard
5
 
 *
 
5
 * 
6
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
 * of this software and associated documentation files (the "Software"), to deal
8
8
 * in the Software without restriction, including without limitation the rights
22
22
 * THE SOFTWARE.
23
23
 */
24
24
 
25
 
#include "hw.h"
26
 
#include "pc.h"
27
 
#include "pci.h"
28
 
 
 
25
#include "vl.h"
29
26
typedef uint32_t pci_addr_t;
30
27
#include "pci_host.h"
31
28
 
55
52
    return (irq_num + slot_addend) & 3;
56
53
}
57
54
 
58
 
static target_phys_addr_t isa_page_descs[384 / 4];
 
55
static uint32_t isa_page_descs[384 / 4];
59
56
static uint8_t smm_enabled;
60
 
static int pci_irq_levels[4];
61
57
 
62
58
static void update_pam(PCIDevice *d, uint32_t start, uint32_t end, int r)
63
59
{
67
63
    switch(r) {
68
64
    case 3:
69
65
        /* RAM */
70
 
        cpu_register_physical_memory(start, end - start,
 
66
        cpu_register_physical_memory(start, end - start, 
71
67
                                     start);
72
68
        break;
73
69
    case 1:
74
70
        /* ROM (XXX: not quite correct) */
75
 
        cpu_register_physical_memory(start, end - start,
 
71
        cpu_register_physical_memory(start, end - start, 
76
72
                                     start | IO_MEM_ROM);
77
73
        break;
78
74
    case 2:
79
75
    case 0:
80
76
        /* XXX: should distinguish read/write cases */
81
77
        for(addr = start; addr < end; addr += 4096) {
82
 
            cpu_register_physical_memory(addr, 4096,
 
78
            cpu_register_physical_memory(addr, 4096, 
83
79
                                         isa_page_descs[(addr - 0xa0000) >> 12]);
84
80
        }
85
81
        break;
101
97
        cpu_register_physical_memory(0xa0000, 0x20000, 0xa0000);
102
98
    } else {
103
99
        for(addr = 0xa0000; addr < 0xc0000; addr += 4096) {
104
 
            cpu_register_physical_memory(addr, 4096,
 
100
            cpu_register_physical_memory(addr, 4096, 
105
101
                                         isa_page_descs[(addr - 0xa0000) >> 12]);
106
102
        }
107
103
    }
128
124
    }
129
125
}
130
126
 
131
 
static void i440fx_write_config(PCIDevice *d,
 
127
static void i440fx_write_config(PCIDevice *d, 
132
128
                                uint32_t address, uint32_t val, int len)
133
129
{
134
130
    /* XXX: implement SMRAM.D_LOCK */
140
136
static void i440fx_save(QEMUFile* f, void *opaque)
141
137
{
142
138
    PCIDevice *d = opaque;
143
 
    int i;
144
 
 
145
139
    pci_device_save(d, f);
146
140
    qemu_put_8s(f, &smm_enabled);
147
 
 
148
 
    for (i = 0; i < 4; i++)
149
 
        qemu_put_be32(f, pci_irq_levels[i]);
150
141
}
151
142
 
152
143
static int i440fx_load(QEMUFile* f, void *opaque, int version_id)
153
144
{
154
145
    PCIDevice *d = opaque;
155
 
    int ret, i;
 
146
    int ret;
156
147
 
157
 
    if (version_id > 2)
 
148
    if (version_id != 1)
158
149
        return -EINVAL;
159
150
    ret = pci_device_load(d, f);
160
151
    if (ret < 0)
161
152
        return ret;
162
153
    i440fx_update_memory_mappings(d);
163
154
    qemu_get_8s(f, &smm_enabled);
164
 
 
165
 
    if (version_id >= 2)
166
 
        for (i = 0; i < 4; i++)
167
 
            pci_irq_levels[i] = qemu_get_be32(f);
168
 
 
169
155
    return 0;
170
156
}
171
157
 
189
175
    register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
190
176
    register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
191
177
 
192
 
    d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
 
178
    d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0, 
193
179
                            NULL, i440fx_write_config);
194
180
 
195
181
    d->config[0x00] = 0x86; // vendor_id
203
189
 
204
190
    d->config[0x72] = 0x02; /* SMRAM */
205
191
 
206
 
    register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d);
 
192
    register_savevm("I440FX", 0, 1, i440fx_save, i440fx_load, d);
207
193
    *pi440fx_state = d;
208
194
    return b;
209
195
}
210
196
 
211
197
/* PIIX3 PCI to ISA bridge */
212
198
 
213
 
static PCIDevice *piix3_dev;
 
199
PCIDevice *piix3_dev;
214
200
PCIDevice *piix4_dev;
215
201
 
216
202
/* just used for simpler irq handling. */
217
203
#define PCI_IRQ_WORDS   ((PCI_DEVICES_MAX + 31) / 32)
218
204
 
 
205
static int pci_irq_levels[4];
 
206
 
219
207
static void piix3_set_irq(qemu_irq *pic, int irq_num, int level)
220
208
{
221
209
    int i, pic_irq, pic_level;
249
237
    pci_conf[0x4e] = 0x03;
250
238
    pci_conf[0x4f] = 0x00;
251
239
    pci_conf[0x60] = 0x80;
252
 
    pci_conf[0x61] = 0x80;
253
 
    pci_conf[0x62] = 0x80;
254
 
    pci_conf[0x63] = 0x80;
255
240
    pci_conf[0x69] = 0x02;
256
241
    pci_conf[0x70] = 0x80;
257
242
    pci_conf[0x76] = 0x0c;
325
310
    return pci_device_load(d, f);
326
311
}
327
312
 
 
313
int piix_init(PCIBus *bus, int devfn)
 
314
{
 
315
    PCIDevice *d;
 
316
    uint8_t *pci_conf;
 
317
 
 
318
    d = pci_register_device(bus, "PIIX", sizeof(PCIDevice),
 
319
                                    devfn, NULL, NULL);
 
320
    register_savevm("PIIX", 0, 2, piix_save, piix_load, d);
 
321
 
 
322
    piix3_dev = d;
 
323
    pci_conf = d->config;
 
324
 
 
325
    pci_conf[0x00] = 0x86; // Intel
 
326
    pci_conf[0x01] = 0x80;
 
327
    pci_conf[0x02] = 0x2E; // 82371FB PIIX PCI-to-ISA bridge
 
328
    pci_conf[0x03] = 0x12;
 
329
    pci_conf[0x08] = 0x02; // Step A1
 
330
    pci_conf[0x0a] = 0x01; // class_sub = PCI_ISA
 
331
    pci_conf[0x0b] = 0x06; // class_base = PCI_bridge
 
332
    pci_conf[0x0e] = 0x80; // header_type = PCI_multifunction, generic
 
333
 
 
334
    piix3_reset(d);
 
335
    return d->devfn;
 
336
}
 
337
 
328
338
int piix3_init(PCIBus *bus, int devfn)
329
339
{
330
340
    PCIDevice *d;