From patchwork Fri Dec 6 17:03:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 298223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40D7B2C00A8 for ; Sat, 7 Dec 2013 06:23:58 +1100 (EST) Received: from localhost ([::1]:33079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vp0xR-0004C9-JQ for incoming@patchwork.ozlabs.org; Fri, 06 Dec 2013 14:21:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoyqM-0004ZU-Iq for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:05:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoyqE-0004Sc-KL for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:05:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoyqE-0004SG-DZ for qemu-devel@nongnu.org; Fri, 06 Dec 2013 12:05:26 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB6H5MLK029081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Dec 2013 12:05:22 -0500 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rB6H57Px002796; Fri, 6 Dec 2013 12:05:17 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 6 Dec 2013 18:03:09 +0100 Message-Id: <1386349395-5710-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1386349395-5710-1-git-send-email-imammedo@redhat.com> References: <1386349395-5710-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com, marcel.a@redhat.com, blauwirbel@gmail.com, alex.williamson@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 1/7] define hotplug interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Provide generic hotplug interface for devices. Intended for replacing hotplug mechanism used by PCI/PCIE/SHPC code. Signed-off-by: Igor Mammedov --- it's scsi-bus like interface, but abstracted from bus altogether since all current users care about in hotplug handlers, it's hotplug device and hotplugged device and bus only serves as a means to get access to hotplug device and it's callbacks. --- hw/core/Makefile.objs | 1 + hw/core/hotplug.c | 25 ++++++++++++++++++++++++ include/hw/hotplug.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 hw/core/hotplug.c create mode 100644 include/hw/hotplug.h diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index 950146c..47f6555 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -10,4 +10,5 @@ common-obj-$(CONFIG_SOFTMMU) += sysbus.o common-obj-$(CONFIG_SOFTMMU) += null-machine.o common-obj-$(CONFIG_SOFTMMU) += loader.o common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o +common-obj-$(CONFIG_SOFTMMU) += hotplug.o diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c new file mode 100644 index 0000000..3e84d9c --- /dev/null +++ b/hw/core/hotplug.c @@ -0,0 +1,25 @@ +/* + * Hotplug device interface. + * + * Copyright (c) 2013 Red Hat Inc. + * + * Authors: + * Igor Mammedov , + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "hw/hotplug.h" + +static const TypeInfo hotplug_device_info = { + .name = TYPE_HOTPLUG_DEVICE, + .parent = TYPE_INTERFACE, + .class_size = sizeof(HotplugDeviceClass), +}; + +static void hotplug_device_register_types(void) +{ + type_register_static(&hotplug_device_info); +} + +type_init(hotplug_device_register_types) diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h new file mode 100644 index 0000000..cfa79bb --- /dev/null +++ b/include/hw/hotplug.h @@ -0,0 +1,50 @@ +/* + * Hotplug device interface. + * + * Copyright (c) 2013 Red Hat Inc. + * + * Authors: + * Igor Mammedov , + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef HOTPLUG_H +#define HOTPLUG_H + +#include "hw/qdev-core.h" + +#define TYPE_HOTPLUG_DEVICE "hotplug-device" + +#define HOTPLUG_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(HotplugDeviceClass, (klass), TYPE_HOTPLUG_DEVICE) +#define HOTPLUG_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(HotplugDeviceClass, (obj), TYPE_HOTPLUG_DEVICE) + +/** + * hotplug_fn: + * @hotplug_dev: a device performing hotplug/uplug action + * @hotplugged_dev: a device that has been hotplugged + * @errp: returns an error if this function fails + */ +typedef void (*hotplug_fn)(DeviceState *hotplug_dev, + DeviceState *hotplugged_dev, Error **errp); + +/** + * HotplugDeviceClass: + * + * Interface to be implemented by a device performing + * hardware hotplug/unplug functions. + * + * @parent: Opaque parent interface. + * @hotplug: hotplug callback. + * @hot_unplug: hot unplug callback. + */ +typedef struct HotplugDeviceClass { + InterfaceClass parent; + + hotplug_fn hotplug; + hotplug_fn hot_unplug; +} HotplugDeviceClass; + +#endif