Revision de00982e

b/hw/xen_platform.c
32 32
#include "xen_common.h"
33 33
#include "net.h"
34 34
#include "xen_backend.h"
35
#include "rwhandler.h"
36 35
#include "trace.h"
36
#include "exec-memory.h"
37 37

  
38 38
#include <xenguest.h>
39 39

  
......
51 51

  
52 52
typedef struct PCIXenPlatformState {
53 53
    PCIDevice  pci_dev;
54
    MemoryRegion fixed_io;
55
    MemoryRegion bar;
56
    MemoryRegion mmio_bar;
54 57
    uint8_t flags; /* used only for version_id == 2 */
55 58
    int drivers_blacklisted;
56 59
    uint16_t driver_product_version;
......
221 224
    platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, 0);
222 225
}
223 226

  
227
const MemoryRegionPortio xen_platform_ioport[] = {
228
    { 0, 16, 4, .write = platform_fixed_ioport_writel, },
229
    { 0, 16, 2, .write = platform_fixed_ioport_writew, },
230
    { 0, 16, 1, .write = platform_fixed_ioport_writeb, },
231
    { 0, 16, 2, .read = platform_fixed_ioport_readw, },
232
    { 0, 16, 1, .read = platform_fixed_ioport_readb, },
233
    PORTIO_END_OF_LIST()
234
};
235

  
236
static const MemoryRegionOps platform_fixed_io_ops = {
237
    .old_portio = xen_platform_ioport,
238
    .endianness = DEVICE_NATIVE_ENDIAN,
239
};
240

  
224 241
static void platform_fixed_ioport_init(PCIXenPlatformState* s)
225 242
{
226
    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 4, platform_fixed_ioport_writel, s);
227
    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 2, platform_fixed_ioport_writew, s);
228
    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 1, platform_fixed_ioport_writeb, s);
229
    register_ioport_read(XEN_PLATFORM_IOPORT, 16, 2, platform_fixed_ioport_readw, s);
230
    register_ioport_read(XEN_PLATFORM_IOPORT, 16, 1, platform_fixed_ioport_readb, s);
243
    memory_region_init_io(&s->fixed_io, &platform_fixed_io_ops, s,
244
                          "xen-fixed", 16);
245
    memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT,
246
                                &s->fixed_io);
231 247
}
232 248

  
233 249
/* Xen Platform PCI Device */
234 250

  
235 251
static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
236 252
{
237
    addr &= 0xff;
238

  
239 253
    if (addr == 0) {
240 254
        return platform_fixed_ioport_readb(opaque, XEN_PLATFORM_IOPORT);
241 255
    } else {
......
247 261
{
248 262
    PCIXenPlatformState *s = opaque;
249 263

  
250
    addr &= 0xff;
251
    val  &= 0xff;
252

  
253 264
    switch (addr) {
254 265
    case 0: /* Platform flags */
255 266
        platform_fixed_ioport_writeb(opaque, XEN_PLATFORM_IOPORT, val);
......
262 273
    }
263 274
}
264 275

  
265
static void platform_ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type)
266
{
267
    PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, pci_dev);
276
static MemoryRegionPortio xen_pci_portio[] = {
277
    { 0, 0x100, 1, .read = xen_platform_ioport_readb, },
278
    { 0, 0x100, 1, .write = xen_platform_ioport_writeb, },
279
    PORTIO_END_OF_LIST()
280
};
281

  
282
static const MemoryRegionOps xen_pci_io_ops = {
283
    .old_portio = xen_pci_portio,
284
};
268 285

  
269
    register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d);
270
    register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d);
286
static void platform_ioport_bar_setup(PCIXenPlatformState *d)
287
{
288
    memory_region_init_io(&d->bar, &xen_pci_io_ops, d, "xen-pci", 0x100);
271 289
}
272 290

  
273
static uint32_t platform_mmio_read(ReadWriteHandler *handler, pcibus_t addr, int len)
291
static uint64_t platform_mmio_read(void *opaque, target_phys_addr_t addr,
292
                                   unsigned size)
274 293
{
275 294
    DPRINTF("Warning: attempted read from physical address "
276 295
            "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr);
......
278 297
    return 0;
279 298
}
280 299

  
281
static void platform_mmio_write(ReadWriteHandler *handler, pcibus_t addr,
282
                                uint32_t val, int len)
300
static void platform_mmio_write(void *opaque, target_phys_addr_t addr,
301
                                uint64_t val, unsigned size)
283 302
{
284
    DPRINTF("Warning: attempted write of 0x%x to physical "
303
    DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical "
285 304
            "address 0x" TARGET_FMT_plx " in xen platform mmio space\n",
286 305
            val, addr);
287 306
}
288 307

  
289
static ReadWriteHandler platform_mmio_handler = {
308
static const MemoryRegionOps platform_mmio_handler = {
290 309
    .read = &platform_mmio_read,
291 310
    .write = &platform_mmio_write,
311
    .endianness = DEVICE_NATIVE_ENDIAN,
292 312
};
293 313

  
294
static void platform_mmio_map(PCIDevice *d, int region_num,
295
                              pcibus_t addr, pcibus_t size, int type)
314
static void platform_mmio_setup(PCIXenPlatformState *d)
296 315
{
297
    int mmio_io_addr;
298

  
299
    mmio_io_addr = cpu_register_io_memory_simple(&platform_mmio_handler,
300
                                                 DEVICE_NATIVE_ENDIAN);
301

  
302
    cpu_register_physical_memory(addr, size, mmio_io_addr);
316
    memory_region_init_io(&d->mmio_bar, &platform_mmio_handler, d,
317
                          "xen-mmio", 0x1000000);
303 318
}
304 319

  
305 320
static int xen_platform_post_load(void *opaque, int version_id)
......
337 352

  
338 353
    pci_conf[PCI_INTERRUPT_PIN] = 1;
339 354

  
340
    pci_register_bar(&d->pci_dev, 0, 0x100,
341
            PCI_BASE_ADDRESS_SPACE_IO, platform_ioport_map);
355
    platform_ioport_bar_setup(d);
356
    pci_register_bar_region(&d->pci_dev, 0,
357
                            PCI_BASE_ADDRESS_SPACE_IO, &d->bar);
342 358

  
343 359
    /* reserve 16MB mmio address for share memory*/
344
    pci_register_bar(&d->pci_dev, 1, 0x1000000,
345
            PCI_BASE_ADDRESS_MEM_PREFETCH, platform_mmio_map);
360
    platform_mmio_setup(d);
361
    pci_register_bar_region(&d->pci_dev, 1,
362
                            PCI_BASE_ADDRESS_MEM_PREFETCH, &d->mmio_bar);
346 363

  
347 364
    platform_fixed_ioport_init(d);
348 365

  

Also available in: Unified diff