qemu/hw/misc/reset-dev.c
<<
>>
Prefs
   1/*
   2 * Tiny device exposing GPIOs to control reset of the full machine.
   3 *
   4 * Copyright (c) 2015 Xilinx Inc
   5 * Written by Edgar E. Iglesias <edgar.iglesias@xilinx.com>
   6 *
   7 * This code is licensed under the GNU GPL.
   8 */
   9
  10#include "qemu/osdep.h"
  11#include "hw/sysbus.h"
  12#include "sysemu/sysemu.h"
  13#include "qemu/log.h"
  14#include "qapi/qmp/qerror.h"
  15#include "hw/qdev.h"
  16
  17#define TYPE_RESET_DEVICE "qemu.reset-device"
  18#define RESET_DEVICE(obj) \
  19        OBJECT_CHECK(ResetDevice, (obj), TYPE_RESET_DEVICE)
  20
  21typedef struct ResetDevice {
  22    DeviceState parent;
  23} ResetDevice;
  24
  25static void reset_handler(void *opaque, int irq, int level)
  26{
  27    if (level) {
  28        qemu_system_reset_request();
  29    }
  30}
  31
  32static void reset_init(Object *obj)
  33{
  34    qdev_init_gpio_in(DEVICE(obj), reset_handler, 16);
  35}
  36
  37static const TypeInfo reset_info = {
  38    .name          = TYPE_RESET_DEVICE,
  39    .parent        = TYPE_DEVICE,
  40    .instance_size = sizeof(ResetDevice),
  41    .instance_init = reset_init,
  42};
  43
  44static void reset_register_types(void)
  45{
  46    type_register_static(&reset_info);
  47}
  48
  49type_init(reset_register_types)
  50