qemu/hw/core/empty_slot.c
<<
>>
Prefs
   1/*
   2 * QEMU Empty Slot
   3 *
   4 * The empty_slot device emulates known to a bus but not connected devices.
   5 *
   6 * Copyright (c) 2010 Artyom Tarasenko
   7 *
   8 * This code is licensed under the GNU GPL v2 or (at your option) any later
   9 * version.
  10 */
  11
  12#include "qemu/osdep.h"
  13#include "hw/hw.h"
  14#include "hw/sysbus.h"
  15#include "qemu/module.h"
  16#include "hw/empty_slot.h"
  17
  18//#define DEBUG_EMPTY_SLOT
  19
  20#ifdef DEBUG_EMPTY_SLOT
  21#define DPRINTF(fmt, ...)                                       \
  22    do { printf("empty_slot: " fmt , ## __VA_ARGS__); } while (0)
  23#else
  24#define DPRINTF(fmt, ...) do {} while (0)
  25#endif
  26
  27#define TYPE_EMPTY_SLOT "empty_slot"
  28#define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
  29
  30typedef struct EmptySlot {
  31    SysBusDevice parent_obj;
  32
  33    MemoryRegion iomem;
  34    uint64_t size;
  35} EmptySlot;
  36
  37static uint64_t empty_slot_read(void *opaque, hwaddr addr,
  38                                unsigned size)
  39{
  40    DPRINTF("read from " TARGET_FMT_plx "\n", addr);
  41    return 0;
  42}
  43
  44static void empty_slot_write(void *opaque, hwaddr addr,
  45                             uint64_t val, unsigned size)
  46{
  47    DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
  48}
  49
  50static const MemoryRegionOps empty_slot_ops = {
  51    .read = empty_slot_read,
  52    .write = empty_slot_write,
  53    .endianness = DEVICE_NATIVE_ENDIAN,
  54};
  55
  56void empty_slot_init(hwaddr addr, uint64_t slot_size)
  57{
  58    if (slot_size > 0) {
  59        /* Only empty slots larger than 0 byte need handling. */
  60        DeviceState *dev;
  61        SysBusDevice *s;
  62        EmptySlot *e;
  63
  64        dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
  65        s = SYS_BUS_DEVICE(dev);
  66        e = EMPTY_SLOT(dev);
  67        e->size = slot_size;
  68
  69        qdev_init_nofail(dev);
  70
  71        sysbus_mmio_map(s, 0, addr);
  72    }
  73}
  74
  75static void empty_slot_realize(DeviceState *dev, Error **errp)
  76{
  77    EmptySlot *s = EMPTY_SLOT(dev);
  78
  79    memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
  80                          "empty-slot", s->size);
  81    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
  82}
  83
  84static void empty_slot_class_init(ObjectClass *klass, void *data)
  85{
  86    DeviceClass *dc = DEVICE_CLASS(klass);
  87
  88    dc->realize = empty_slot_realize;
  89}
  90
  91static const TypeInfo empty_slot_info = {
  92    .name          = TYPE_EMPTY_SLOT,
  93    .parent        = TYPE_SYS_BUS_DEVICE,
  94    .instance_size = sizeof(EmptySlot),
  95    .class_init    = empty_slot_class_init,
  96};
  97
  98static void empty_slot_register_types(void)
  99{
 100    type_register_static(&empty_slot_info);
 101}
 102
 103type_init(empty_slot_register_types)
 104