From patchwork Sat Sep 24 19:20:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 674342 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 3shKrL33p4z9s9Y for ; Sun, 25 Sep 2016 05:22:58 +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=HmXhAu7v; dkim-atps=neutral Received: from localhost ([::1]:35287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnsXI-0006x7-0z for incoming@patchwork.ozlabs.org; Sat, 24 Sep 2016 15:22:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnsVm-0005LA-R3 for qemu-devel@nongnu.org; Sat, 24 Sep 2016 15:21:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnsVg-0001xW-Mt for qemu-devel@nongnu.org; Sat, 24 Sep 2016 15:21:21 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:33982) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnsVg-0001wK-F5 for qemu-devel@nongnu.org; Sat, 24 Sep 2016 15:21:16 -0400 Received: by mail-pa0-f65.google.com with SMTP id i5so3450857pad.1 for ; Sat, 24 Sep 2016 12:21:16 -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=9XqRLRs7gLv7qyHLCFxIjQ8cmEc92eGMYOd3/FmfxF4=; b=HmXhAu7vJ2hY9uXZLFr0tBm4HtJ7JwYG5zMQcOID7bVLqt+UlLpazXW1hPE83A0egZ z3RsRQ0pPKDS9dvQL8ygHrgtsqoRnRODRjEzF4qNzYUhpt505FE+FA9SfdP7gh/DhKXU 5k9nmyaNyZi0sDipH2NnKlsiksAWmHRdsbk3U+PcTvErtRmVzLc5JmcsDOjUhhoCiS5a ecB4Wo7pOd/OXtZjFPg9g9rnmnNbChbXl80r93IQBbL/KEEzVXFbPD95zQG1X3VvwwBV Fxj9Hm8pW9R4Vb36bQO91jKdoUMNkfTaHwBVksDED96rptuQT3MurhWy9GkLLnm0I3Go pzqQ== 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=9XqRLRs7gLv7qyHLCFxIjQ8cmEc92eGMYOd3/FmfxF4=; b=R7UhdHf27K5z4sQjFVS3t63bm5lyiRIdQ9eh3Zw7gkzQWAcl9lNyWDUlWOebi2ML3a lPXtgXOWixoQO7lVPofFTYdKwlk1x3hs5oO8fE/5Y0dAJ9WCHkLKsJaeYUVvaL0FGskP 7d3rR4ocCdkPtJZC/AFV4pffqJbFm181NvvyWqsJ44Xv/ppU0+GA9nULhvyRlp3UPZXD 3PzsRkF2Iy0OHTMnUzUIDjgzI5iYE9dQPKhU2x4h6ameXrElYGUWy1WO2YFafh02Uu4R n/Uf2BzJ8R0gnhu3G7s/c9kPtAmd48Yj8SdCxu0zqQTab3f9eOTbkLEqmyS2aAjzyK9r tfRw== X-Gm-Message-State: AE9vXwNXgsU9z6l0YsAJenczwwzIUO7aCXQpT8HinteTLeMwzTpJTm82GjDfV4iC9vpR1w== X-Received: by 10.66.227.4 with SMTP id rw4mr24008049pac.119.1474744815675; Sat, 24 Sep 2016 12:20:15 -0700 (PDT) Received: from localhost ([2601:646:8581:937e:696f:1ffa:ab17:d7de]) by smtp.gmail.com with ESMTPSA id m5sm20197516paw.40.2016.09.24.12.20.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Sep 2016 12:20:15 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sat, 24 Sep 2016 12:20:14 -0700 Message-Id: <52e5d361e3b5a0ea8554aca73ee65ae2b586112e.1474742262.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 v8 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 Reviewed-by: Peter Maydell --- As the migration framework is not included in user mode this needs to be a new file. V8: - Use the standard qdev_init_gpio_in() function 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 | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/or-irq.h | 44 +++++++++++++++++++++ 3 files changed, 152 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..1ac090d --- /dev/null +++ b/hw/core/or-irq.c @@ -0,0 +1,107 @@ +/* + * 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" + +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; + } +} + +static void or_irq_realize(DeviceState *dev, Error **errp) +{ + qemu_or_irq *s = OR_IRQ(dev); + + assert(s->num_lines < MAX_OR_LINES); + + qdev_init_gpio_in(dev, or_irq_handler, 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..d400a81 --- /dev/null +++ b/include/hw/or-irq.h @@ -0,0 +1,44 @@ +/* + * 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; +};