~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/apb_pci.c

  • Committer: Bazaar Package Importer
  • Author(s): Riku Voipio, Josh Triplett, Riku Voipio
  • Date: 2009-07-29 13:28:05 UTC
  • mfrom: (1.4.1 upstream)
  • mto: (12.1.1 sid) (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090729132805-cau7rfexh7dawyb8
Tags: 0.10.50+git20090729-1
[ Josh Triplett ]
* Remove myself from Uploaders.

[ Riku Voipio ]
* new upstream RC version
* nuke all linux-user patches (applied upstream)
  06_exit_segfault
  12_signal_powerpc_support
  21_net_soopts
  30_syscall_ipc
  32_syscall_sysctl
  35_syscall_sockaddr
  48_signal_terminate
  55_unmux_socketcall
* nuke all other applied-upstream patches
  01_nostrip (better version upstream)
  07_i386_exec_name (can be reintroduced in debian/rules)
  50_linuxbios_isa_bios_ram (shouldn't be needed anymore)
  51_linuxbios_piix_ram_size (applied)
  56_dhcp (crap)
  60_ppc_ld (reintroduce if needed)
  64_ppc_asm_constraints (ditto)
  66_tls_ld.patch (ditto)
  81_compile_dtb.patch (applied upstream)
  82_qemu-img_decimal (ditto)
* move to git
* simplify build rules
* Correct my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
   Ultrasparc PCI host is called the PCI Bus Module (PBM).  The APB is
27
27
   the secondary PCI bridge.  */
28
28
 
29
 
#include "hw.h"
 
29
#include "sysbus.h"
30
30
#include "pci.h"
31
31
 
32
32
/* debug APB */
33
33
//#define DEBUG_APB
34
34
 
35
35
#ifdef DEBUG_APB
36
 
#define APB_DPRINTF(fmt, args...) \
37
 
do { printf("APB: " fmt , ##args); } while (0)
 
36
#define APB_DPRINTF(fmt, ...) \
 
37
do { printf("APB: " fmt , ## __VA_ARGS__); } while (0)
38
38
#else
39
 
#define APB_DPRINTF(fmt, args...)
 
39
#define APB_DPRINTF(fmt, ...)
40
40
#endif
41
41
 
42
42
typedef target_phys_addr_t pci_addr_t;
43
43
#include "pci_host.h"
44
44
 
45
 
typedef PCIHostState APBState;
 
45
typedef struct APBState {
 
46
    SysBusDevice busdev;
 
47
    PCIHostState host_state;
 
48
} APBState;
46
49
 
47
50
static void pci_apb_config_writel (void *opaque, target_phys_addr_t addr,
48
51
                                         uint32_t val)
54
57
#endif
55
58
    APB_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr,
56
59
                val);
57
 
    s->config_reg = val;
 
60
    s->host_state.config_reg = val;
58
61
}
59
62
 
60
63
static uint32_t pci_apb_config_readl (void *opaque,
63
66
    APBState *s = opaque;
64
67
    uint32_t val;
65
68
 
66
 
    val = s->config_reg;
 
69
    val = s->host_state.config_reg;
67
70
#ifdef TARGET_WORDS_BIGENDIAN
68
71
    val = bswap32(val);
69
72
#endif
148
151
static void pci_apb_iowriteb (void *opaque, target_phys_addr_t addr,
149
152
                                  uint32_t val)
150
153
{
151
 
    cpu_outb(NULL, addr & 0xffff, val);
 
154
    cpu_outb(NULL, addr & IOPORTS_MASK, val);
152
155
}
153
156
 
154
157
static void pci_apb_iowritew (void *opaque, target_phys_addr_t addr,
155
158
                                  uint32_t val)
156
159
{
157
 
    cpu_outw(NULL, addr & 0xffff, val);
 
160
    cpu_outw(NULL, addr & IOPORTS_MASK, val);
158
161
}
159
162
 
160
163
static void pci_apb_iowritel (void *opaque, target_phys_addr_t addr,
161
164
                                uint32_t val)
162
165
{
163
 
    cpu_outl(NULL, addr & 0xffff, val);
 
166
    cpu_outl(NULL, addr & IOPORTS_MASK, val);
164
167
}
165
168
 
166
169
static uint32_t pci_apb_ioreadb (void *opaque, target_phys_addr_t addr)
167
170
{
168
171
    uint32_t val;
169
172
 
170
 
    val = cpu_inb(NULL, addr & 0xffff);
 
173
    val = cpu_inb(NULL, addr & IOPORTS_MASK);
171
174
    return val;
172
175
}
173
176
 
175
178
{
176
179
    uint32_t val;
177
180
 
178
 
    val = cpu_inw(NULL, addr & 0xffff);
 
181
    val = cpu_inw(NULL, addr & IOPORTS_MASK);
179
182
    return val;
180
183
}
181
184
 
183
186
{
184
187
    uint32_t val;
185
188
 
186
 
    val = cpu_inl(NULL, addr & 0xffff);
 
189
    val = cpu_inl(NULL, addr & IOPORTS_MASK);
187
190
    return val;
188
191
}
189
192
 
225
228
                     target_phys_addr_t mem_base,
226
229
                     qemu_irq *pic, PCIBus **bus2, PCIBus **bus3)
227
230
{
 
231
    DeviceState *dev;
 
232
    SysBusDevice *s;
 
233
    APBState *d;
 
234
 
 
235
    /* Ultrasparc PBM main bus */
 
236
    dev = qdev_create(NULL, "pbm");
 
237
    qdev_init(dev);
 
238
    s = sysbus_from_qdev(dev);
 
239
    /* apb_config */
 
240
    sysbus_mmio_map(s, 0, special_base + 0x2000ULL);
 
241
    /* pci_ioport */
 
242
    sysbus_mmio_map(s, 1, special_base + 0x2000000ULL);
 
243
    /* mem_config: XXX size should be 4G-prom */
 
244
    sysbus_mmio_map(s, 2, special_base + 0x1000000ULL);
 
245
    /* mem_data */
 
246
    sysbus_mmio_map(s, 3, mem_base);
 
247
    d = FROM_SYSBUS(APBState, s);
 
248
    d->host_state.bus = pci_register_bus(NULL, "pci",
 
249
                                         pci_apb_set_irq, pci_pbm_map_irq, pic,
 
250
                                         0, 32);
 
251
    pci_create_simple(d->host_state.bus, 0, "pbm");
 
252
    /* APB secondary busses */
 
253
    *bus2 = pci_bridge_init(d->host_state.bus, 8, PCI_VENDOR_ID_SUN,
 
254
                            PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
 
255
                            "Advanced PCI Bus secondary bridge 1");
 
256
    *bus3 = pci_bridge_init(d->host_state.bus, 9, PCI_VENDOR_ID_SUN,
 
257
                            PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
 
258
                            "Advanced PCI Bus secondary bridge 2");
 
259
 
 
260
    return d->host_state.bus;
 
261
}
 
262
 
 
263
static void pci_pbm_init_device(SysBusDevice *dev)
 
264
{
 
265
 
228
266
    APBState *s;
229
 
    PCIDevice *d;
230
267
    int pci_mem_config, pci_mem_data, apb_config, pci_ioport;
231
268
 
232
 
    s = qemu_mallocz(sizeof(APBState));
233
 
    /* Ultrasparc PBM main bus */
234
 
    s->bus = pci_register_bus(pci_apb_set_irq, pci_pbm_map_irq, pic, 0, 32);
235
 
 
236
 
    pci_mem_config = cpu_register_io_memory(0, pci_apb_config_read,
237
 
                                            pci_apb_config_write, s);
238
 
    apb_config = cpu_register_io_memory(0, apb_config_read,
 
269
    s = FROM_SYSBUS(APBState, dev);
 
270
    /* apb_config */
 
271
    apb_config = cpu_register_io_memory(apb_config_read,
239
272
                                        apb_config_write, s);
240
 
    pci_mem_data = cpu_register_io_memory(0, pci_apb_read,
241
 
                                          pci_apb_write, s);
242
 
    pci_ioport = cpu_register_io_memory(0, pci_apb_ioread,
 
273
    sysbus_init_mmio(dev, 0x40ULL, apb_config);
 
274
    /* pci_ioport */
 
275
    pci_ioport = cpu_register_io_memory(pci_apb_ioread,
243
276
                                          pci_apb_iowrite, s);
244
 
 
245
 
    cpu_register_physical_memory(special_base + 0x2000ULL, 0x40, apb_config);
246
 
    cpu_register_physical_memory(special_base + 0x1000000ULL, 0x10,
247
 
                                 pci_mem_config);
248
 
    cpu_register_physical_memory(special_base + 0x2000000ULL, 0x10000,
249
 
                                 pci_ioport);
250
 
    cpu_register_physical_memory(mem_base, 0x10000000,
251
 
                                 pci_mem_data); // XXX size should be 4G-prom
252
 
 
253
 
    d = pci_register_device(s->bus, "Advanced PCI Bus", sizeof(PCIDevice),
254
 
                            0, NULL, NULL);
 
277
    sysbus_init_mmio(dev, 0x10000ULL, pci_ioport);
 
278
    /* mem_config  */
 
279
    pci_mem_config = cpu_register_io_memory(pci_apb_config_read,
 
280
                                            pci_apb_config_write, s);
 
281
    sysbus_init_mmio(dev, 0x10ULL, pci_mem_config);
 
282
    /* mem_data */
 
283
    pci_mem_data = cpu_register_io_memory(pci_apb_read,
 
284
                                          pci_apb_write, &s->host_state);
 
285
    sysbus_init_mmio(dev, 0x10000000ULL, pci_mem_data);
 
286
}
 
287
 
 
288
static void pbm_pci_host_init(PCIDevice *d)
 
289
{
255
290
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_SUN);
256
291
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_SUN_SABRE);
257
292
    d->config[0x04] = 0x06; // command = bus master, pci mem
262
297
    d->config[0x09] = 0x00; // programming i/f
263
298
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
264
299
    d->config[0x0D] = 0x10; // latency_timer
265
 
    d->config[0x0E] = 0x00; // header_type
266
 
 
267
 
    /* APB secondary busses */
268
 
    *bus2 = pci_bridge_init(s->bus, 8, PCI_VENDOR_ID_SUN,
269
 
                            PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
270
 
                            "Advanced PCI Bus secondary bridge 1");
271
 
    *bus3 = pci_bridge_init(s->bus, 9, PCI_VENDOR_ID_SUN,
272
 
                            PCI_DEVICE_ID_SUN_SIMBA, pci_apb_map_irq,
273
 
                            "Advanced PCI Bus secondary bridge 2");
274
 
    return s->bus;
275
 
}
 
300
    d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
 
301
}
 
302
 
 
303
static PCIDeviceInfo pbm_pci_host_info = {
 
304
    .qdev.name = "pbm",
 
305
    .qdev.size = sizeof(PCIDevice),
 
306
    .init      = pbm_pci_host_init,
 
307
};
 
308
 
 
309
static void pbm_register_devices(void)
 
310
{
 
311
    sysbus_register_dev("pbm", sizeof(APBState), pci_pbm_init_device);
 
312
    pci_qdev_register(&pbm_pci_host_info);
 
313
}
 
314
 
 
315
device_init(pbm_register_devices)