From nobody Tue Nov 18 07:47:45 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1608065436; cv=none; d=zohomail.com; s=zohoarc; b=AtiEsmU2YLUMsUx/B5YhkGMNcW/s1Tn+Hjc/Pz3E2+iTm1beu4HP1PKl3IrqCktgUZl6dyrZo6jqBMk7hlv9ipcbj91ZDpvZIMEpXueEoNXh+kRkwkX8+UOIeYa8mm5+gA4b/ETGUYTfA3vrLx1+zWUkNrjZpQupGpyJLME7Sag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608065436; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kTxTim682ljfYYKd8J2TduaxSL6fXhY4Rs/+T6KM4/M=; b=jf6LHzBuQ4GQp2LIJVpVUob9nEShb9pz7qG981S/JnyXvhJIk8I6esubKoC77dzLjfVBtYoN4W2W/Jn2j1NnGmOR8pZw4lFqCPJnW7PV0tLw4pwtQRabY0v2pJ+DI9wjQyVgAMQjpVVAnnq/8pmTfTuXU6YNWRj0WBPEnX/lJI0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16080654364109.231069017370373; Tue, 15 Dec 2020 12:50:36 -0800 (PST) Received: from localhost ([::1]:45190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpBW5-0004Yw-2J for importer@patchew.org; Tue, 15 Dec 2020 09:41:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9uA-0003pM-Us for qemu-devel@nongnu.org; Tue, 15 Dec 2020 07:58:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:44794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9u9-0007Rb-6B for qemu-devel@nongnu.org; Tue, 15 Dec 2020 07:58:14 -0500 From: Huacai Chen Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH V18 1/5] hw/intc: Rework Loongson LIOINTC Date: Tue, 15 Dec 2020 20:57:12 +0800 Message-Id: <20201215125716.477023-2-chenhuacai@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201215125716.477023-1-chenhuacai@kernel.org> References: <20201215125716.477023-1-chenhuacai@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.145.29.99; envelope-from=chenhuacai@kernel.org; helo=mail.kernel.org X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 15 Dec 2020 09:20:38 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Huacai Chen , qemu-devel@nongnu.org, Jiaxun Yang , Aleksandar Markovic , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" As suggested by Philippe Mathieu-Daud=C3=A9, rework Loongson's liointc: 1, Move macro definitions to loongson_liointc.h; 2, Remove magic values and use macros instead; 3, Replace dead D() code by trace events. Suggested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Huacai Chen --- hw/intc/loongson_liointc.c | 36 +++++++++++++----------------- include/hw/intc/loongson_liointc.h | 22 ++++++++++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 include/hw/intc/loongson_liointc.h diff --git a/hw/intc/loongson_liointc.c b/hw/intc/loongson_liointc.c index fbbfb57ee9..e636bb1cfb 100644 --- a/hw/intc/loongson_liointc.c +++ b/hw/intc/loongson_liointc.c @@ -1,6 +1,7 @@ /* * QEMU Loongson Local I/O interrupt controler. * + * Copyright (c) 2020 Huacai Chen * Copyright (c) 2020 Jiaxun Yang * * This program is free software: you can redistribute it and/or modify @@ -19,13 +20,11 @@ */ =20 #include "qemu/osdep.h" -#include "hw/sysbus.h" #include "qemu/module.h" +#include "qemu/log.h" #include "hw/irq.h" #include "hw/qdev-properties.h" -#include "qom/object.h" - -#define D(x) +#include "hw/intc/loongson_liointc.h" =20 #define NUM_IRQS 32 =20 @@ -40,13 +39,10 @@ #define R_IEN 0x24 #define R_IEN_SET 0x28 #define R_IEN_CLR 0x2c -#define R_PERCORE_ISR(x) (0x40 + 0x8 * x) +#define R_ISR_SIZE 0x8 +#define R_START 0x40 #define R_END 0x64 =20 -#define TYPE_LOONGSON_LIOINTC "loongson.liointc" -DECLARE_INSTANCE_CHECKER(struct loongson_liointc, LOONGSON_LIOINTC, - TYPE_LOONGSON_LIOINTC) - struct loongson_liointc { SysBusDevice parent_obj; =20 @@ -123,14 +119,13 @@ liointc_read(void *opaque, hwaddr addr, unsigned int = size) goto out; } =20 - /* Rest is 4 byte */ + /* Rest are 4 bytes */ if (size !=3D 4 || (addr % 4)) { goto out; } =20 - if (addr >=3D R_PERCORE_ISR(0) && - addr < R_PERCORE_ISR(NUM_CORES)) { - int core =3D (addr - R_PERCORE_ISR(0)) / 8; + if (addr >=3D R_START && addr < R_END) { + int core =3D (addr - R_START) / R_ISR_SIZE; r =3D p->per_core_isr[core]; goto out; } @@ -147,7 +142,8 @@ liointc_read(void *opaque, hwaddr addr, unsigned int si= ze) } =20 out: - D(qemu_log("%s: size=3D%d addr=3D%lx val=3D%x\n", __func__, size, addr= , r)); + qemu_log_mask(CPU_LOG_INT, "%s: size=3D%d addr=3D%lx val=3D%x\n", + __func__, size, addr, r); return r; } =20 @@ -158,7 +154,8 @@ liointc_write(void *opaque, hwaddr addr, struct loongson_liointc *p =3D opaque; uint32_t value =3D val64; =20 - D(qemu_log("%s: size=3D%d, addr=3D%lx val=3D%x\n", __func__, size, add= r, value)); + qemu_log_mask(CPU_LOG_INT, "%s: size=3D%d, addr=3D%lx val=3D%x\n", + __func__, size, addr, value); =20 /* Mapper is 1 byte */ if (size =3D=3D 1 && addr < R_MAPPER_END) { @@ -166,14 +163,13 @@ liointc_write(void *opaque, hwaddr addr, goto out; } =20 - /* Rest is 4 byte */ + /* Rest are 4 bytes */ if (size !=3D 4 || (addr % 4)) { goto out; } =20 - if (addr >=3D R_PERCORE_ISR(0) && - addr < R_PERCORE_ISR(NUM_CORES)) { - int core =3D (addr - R_PERCORE_ISR(0)) / 8; + if (addr >=3D R_START && addr < R_END) { + int core =3D (addr - R_START) / R_ISR_SIZE; p->per_core_isr[core] =3D value; goto out; } @@ -224,7 +220,7 @@ static void loongson_liointc_init(Object *obj) } =20 memory_region_init_io(&p->mmio, obj, &pic_ops, p, - "loongson.liointc", R_END); + TYPE_LOONGSON_LIOINTC, R_END); sysbus_init_mmio(SYS_BUS_DEVICE(obj), &p->mmio); } =20 diff --git a/include/hw/intc/loongson_liointc.h b/include/hw/intc/loongson_= liointc.h new file mode 100644 index 0000000000..848e65eb35 --- /dev/null +++ b/include/hw/intc/loongson_liointc.h @@ -0,0 +1,22 @@ +/* + * This file is subject to the terms and conditions of the GNU General Pub= lic + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * Copyright (c) 2020 Huacai Chen + * Copyright (c) 2020 Jiaxun Yang + * + */ + +#ifndef LOONGSON_LIOINTC_H +#define LOONGSON_LIOINTC_H + +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_LOONGSON_LIOINTC "loongson.liointc" +DECLARE_INSTANCE_CHECKER(struct loongson_liointc, LOONGSON_LIOINTC, + TYPE_LOONGSON_LIOINTC) + +#endif /* LOONGSON_LIOINTC_H */ --=20 2.27.0