From patchwork Sun Sep 11 14:54:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 668478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sXDnW5yzgz9sBr for ; Mon, 12 Sep 2016 01:07:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tjc2oVGo; dkim-atps=neutral Received: from localhost ([::1]:37961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bj6Lt-00064g-GS for incoming@patchwork.ozlabs.org; Sun, 11 Sep 2016 11:07:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bj6An-0005Vj-HH for qemu-devel@nongnu.org; Sun, 11 Sep 2016 10:55:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bj6Ai-0004Ry-HH for qemu-devel@nongnu.org; Sun, 11 Sep 2016 10:55:56 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bj6Ai-0004Rp-91 for qemu-devel@nongnu.org; Sun, 11 Sep 2016 10:55:52 -0400 Received: by mail-pa0-f65.google.com with SMTP id ph5so378149pab.1 for ; Sun, 11 Sep 2016 07:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+11z/zbxwyXxlNspvLfgqVmMbyRcREjYe0sJxXJP3Cg=; b=tjc2oVGo2LYv1QQssT5rhm8iQcrAVH33XMC/JtQotX3sivVOywmgNqVfMK24c1rOBi TWpwzXysC/xmTs5Mfhr9CMbCtl3eUztC/2VdCqfC9mKPDom+tqjHre7NnVB6Mvf2meix /CLHcZkrT1Ud3GnFX6HzTIZLVXe34tQlGNPjN0muUcOVSoyxQdJmTWgatusBfuOrv3SD 3DD3nMQhdKMZmxFlCUH4t1aQX+TFgZPfghUhUtAyb0hzJKndekVstjN7vjwd6hcII/B7 /jQor/Fvq6mRMAB6tes0+y7qRn3s347yvljhQb8Gx0Z4VLwDqZtlr1no7ndMHu0gnchu MSQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+11z/zbxwyXxlNspvLfgqVmMbyRcREjYe0sJxXJP3Cg=; b=ZrszgWPPGh1oaHp9AciPilpCuwLj7nlIwWkSCk3vUeAi0e3rPmi/Vwr7IBRK7/2y5j mCGOL59LWgL3QklbEjfnH2jKn8XW5gZ2SiPM3faupt7QJzfhr7mwXgkPUEeFGdpyA+0X 5I7wB2x6C5as/6jlKbYKgB2d715WkC1jL2P7OgnfZwJN0XonEa5MPfUL/ByLsOb5cac4 +sIVD1a8KQQlmZxpzC5yEZ1wz/wf82hkK4IuLGbZRcAfr2nuPvl13J90bxfZ1wIORyBC QcyV/mVz6uMAHpQjidSmWlEm6QkelcRRwqHESNLDi75ZiEpXodwyc9mFdtFy4EWgCzVv Z4JQ== X-Gm-Message-State: AE9vXwPrZhUyiCYNhv8M+ovr1GtIHfjL7/7DuPsTBEA7lCuJ2ggUd5gXgwvPec1xKGKBTw== X-Received: by 10.66.218.39 with SMTP id pd7mr1213569pac.9.1473605691599; Sun, 11 Sep 2016 07:54:51 -0700 (PDT) Received: from localhost ([2601:646:8581:937e:2561:c199:6f8f:8bc8]) by smtp.gmail.com with ESMTPSA id d200sm18183663pfd.3.2016.09.11.07.54.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Sep 2016 07:54:51 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 11 Sep 2016 07:54:50 -0700 Message-Id: <251a4110c1289188a85031324fbe9b1db7aedbd5.1473579576.git.alistair@alistair23.me> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.65 Subject: [Qemu-devel] [PATCH v7 5/8] irq: Add a new irq device that allows the ORing of lines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair23@gmail.com, konstanty@ieee.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alistair Francis --- As the migration framework is not included in user mode this needs to be a new file. V7: - Use the standard QEMU init/realise functions V6: - Make the OR IRQ device a TYPE_DEVICE - Add vmstate hw/core/Makefile.objs | 1 + hw/core/or-irq.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/or-irq.h | 46 ++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 hw/core/or-irq.c create mode 100644 include/hw/or-irq.h diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index cfd4840..b47241b 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -16,4 +16,5 @@ 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) += register.o +common-obj-$(CONFIG_SOFTMMU) += or-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o diff --git a/hw/core/or-irq.c b/hw/core/or-irq.c new file mode 100644 index 0000000..840b1b6 --- /dev/null +++ b/hw/core/or-irq.c @@ -0,0 +1,117 @@ +/* + * QEMU IRQ/GPIO common code. + * + * Copyright (c) 2016 Alistair Francis . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/or-irq.h" + +qemu_irq *qemu_get_or_irqs(DeviceState *dev) +{ + qemu_or_irq *s = OR_IRQ(dev); + + return s->in_irqs; +} + +static void or_irq_handler(void *opaque, int n, int level) +{ + qemu_or_irq *s = OR_IRQ(opaque); + int or_level = 0; + int i; + + s->levels[n] = level; + + for (i = 0; i < s->num_lines; i++) { + or_level |= s->levels[i]; + } + + qemu_set_irq(s->out_irq, or_level); +} + +static void or_irq_reset(DeviceState *dev) +{ + qemu_or_irq *s = OR_IRQ(dev); + int i; + + for (i = 0; i < MAX_OR_LINES; i++) { + s->levels[i] = false; + } + + /* Trigger an update of the out irqs. We just set the level to 0 */ + or_irq_handler(s, 0, 0); +} + +static void or_irq_realize(DeviceState *dev, Error **errp) +{ + qemu_or_irq *s = OR_IRQ(dev); + + assert(s->num_lines < MAX_OR_LINES); + + s->in_irqs = qemu_allocate_irqs(or_irq_handler, s, s->num_lines); +} + +static void or_irq_init(Object *obj) +{ + qemu_or_irq *s = OR_IRQ(obj); + + qdev_init_gpio_out(DEVICE(obj), &s->out_irq, 1); +} + +static const VMStateDescription vmstate_or_irq = { + .name = TYPE_OR_IRQ, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_BOOL_ARRAY(levels, qemu_or_irq, MAX_OR_LINES), + VMSTATE_END_OF_LIST(), + } +}; + +static Property or_irq_properties[] = { + DEFINE_PROP_UINT16("num-lines", qemu_or_irq, num_lines, 1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void or_irq_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->reset = or_irq_reset; + dc->props = or_irq_properties; + dc->realize = or_irq_realize; + dc->vmsd = &vmstate_or_irq; +} + +static const TypeInfo or_irq_type_info = { + .name = TYPE_OR_IRQ, + .parent = TYPE_DEVICE, + .instance_size = sizeof(qemu_or_irq), + .instance_init = or_irq_init, + .class_init = or_irq_class_init, +}; + +static void or_irq_register_types(void) +{ + type_register_static(&or_irq_type_info); +} + +type_init(or_irq_register_types) diff --git a/include/hw/or-irq.h b/include/hw/or-irq.h new file mode 100644 index 0000000..19455ee --- /dev/null +++ b/include/hw/or-irq.h @@ -0,0 +1,46 @@ +/* + * QEMU IRQ/GPIO common code. + * + * Copyright (c) 2016 Alistair Francis . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_OR_IRQ "or-irq" + +#define MAX_OR_LINES 16 + +typedef struct OrIRQState qemu_or_irq; + +#define OR_IRQ(obj) OBJECT_CHECK(qemu_or_irq, (obj), TYPE_OR_IRQ) + +struct OrIRQState { + DeviceState parent_obj; + + qemu_irq out_irq; + qemu_irq *in_irqs; + bool levels[MAX_OR_LINES]; + uint16_t num_lines; +}; + +qemu_irq *qemu_get_or_irqs(DeviceState *dev);