From patchwork Wed May 8 17:45:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795498 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp903886wrc; Wed, 8 May 2024 10:48:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWPpoYxT0+zWiwTrS20JiEfZp3mWDilxzGHPDRBcYV0GqR9nD+iwLKBiw+tM/BFTOJw4abx/6EOSufxYv4hRxhM X-Google-Smtp-Source: AGHT+IGZp0LbVLqAsRD4Ov2K0VwKl//uJYpE8d6makQqOn2uEsgYhQ7AfNOa911EHlhMJjK2/+qG X-Received: by 2002:a05:6808:1490:b0:3c5:f62a:435 with SMTP id 5614622812f47-3c9853086eamr3839361b6e.48.1715190521142; Wed, 08 May 2024 10:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715190521; cv=none; d=google.com; s=arc-20160816; b=Phd3RyrWablgH7CYwOu/2gan58cGIYz6RKWmhXsx4JFLBtrKScCYlU147C0/9S0TdC ttz7LRGin9i5v3jGt1vhMXivsxjWuwMhQPXa5fwaoQ8VR1fEvYvMp9bPx+udVnCmTZ/W zRT38VCf5LABuOESq/6Cn/XF29vmfkaUuCxgcNi0i1kOKheeDU/fMqnGt59Fv9BY9omh 4Ndeozzk/HRYK1wLWQihHneOZ3p3ANxUXMydro9f6/adgodPHJZsIc07sOU4g/Fhltkv AojON99YYFY/UdRf10ho5DXwWzPZkbSPJEJtc97ziGXHOAjX4Dp8QOCILP6ohvmKhc+4 3lhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=npbkiNQNqy3L7L6w2vAeVZgTjq5H6cLzlHY7iLgQ/Nk=; fh=jiKM5Jsg5IywfmBhne3oNkoWpsaS5OqwqtJOUwmjFpk=; b=JJtFnMjsMzirmXVSG+H3yPMinqIcWnB3nAGT65FAUThxys7+wMLZY9394Ncq4zTtgY RHHY3jjzGVo+jEscfjWjYQ+MYzogT/adVUJx+4igTyXnrsAPmaGodtRf+Ob16J4iigtd Is+EeeVzuhFWevw+AvUnPfHqYzaT7w8/fSuDyNPCywu2/ZIFRTF7PSmXqBpzCq20myUA yKdPZ+asvPaN5btc2gaCCRnja0Zv+qfVRs7vvHHqvGkklZ+22dH8X220GP1HodrzrY3B S4AetnvMS2EKmHXUoAjqpO30DRoXUtOBmBX5eO6jeRRyssFeJzDwJ+MGHCR0U6SOqf8c Vspw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vf4MDnqi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 4-20020a0562140cc400b006a0b26a9b30si15654025qvx.568.2024.05.08.10.48.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 May 2024 10:48:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vf4MDnqi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4lOJ-00051b-8A; Wed, 08 May 2024 13:47:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4lO8-0004YE-HH for qemu-devel@nongnu.org; Wed, 08 May 2024 13:47:34 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s4lO6-0000sL-71 for qemu-devel@nongnu.org; Wed, 08 May 2024 13:47:32 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a59b178b75bso2868666b.0 for ; Wed, 08 May 2024 10:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715190448; x=1715795248; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=npbkiNQNqy3L7L6w2vAeVZgTjq5H6cLzlHY7iLgQ/Nk=; b=Vf4MDnqiuD/OX7m1MgNqEBWtopf3rTQrC8DLgzqREzt7lytBWJ8SvwLGXBQwZHUzzC LB5gHaqCMuKIF/ZoEniSC0L5ULTJCzZ+njzS96uPsE2AttFdnCxNq/V/5LpBIX+bKUxX gEr4rXrLVRCE4TjO9CmlhOwIcCF6belCcD0dfUlJC73AmyCIUCsepVVrvtxwx3qSHxOG PyzM9f/7UrA27pMG7eBW9mndU/RhH2Uy1WbNlDu/YuRE+iEYOW7bY04KAOlOmdlONM5g 0dPfGjnqRwP5wvxVKMhLNxNcHt4aKsQy52WsPLV7MO2Fp/noFTxCOrPCVdtnTMOZFvOt d4fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715190448; x=1715795248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=npbkiNQNqy3L7L6w2vAeVZgTjq5H6cLzlHY7iLgQ/Nk=; b=gBfd/IpDA+e7JURf/TqL32yPe9XimjApeEYoGxxUbyWwsYmsCPfxN4/YHQTS7qcv+I BBikx8RLUz7HWD4t0FTjLtMyO/ZgAeFgsPm8c92vxmeaTtGo/SVqXbli5YP/AdoB9OGK cP+WkUv+9YdOHYbx1Z0qCiJVINVtP18O+v6el6E3Lb1TFvXbr3rCIrPiXzoi1uZHrMAQ O41Q6hkn7tFVgZdlYZCMt29Q+nbX4ua8gb7AXLr11sb1Daur/Ekxal4wavGC24oBvUVJ hTHis4hvcYrjvhlgUVcEwAyElBBMhx6LDsR9EtIt4QJ/VY/hVI9OQC+Xl45Pw//gx83H bqPw== X-Gm-Message-State: AOJu0Yz6DbSZK1PXhFXkkAnRvYCiCGivmDFCHPx7UkrYaM3zQRlp0JCA /8VXbdwjGDWfbevGgnJEx3ZnMUNk9gkwF7NEHfwLcCqd8FUOANCUcsS/Dio31VI2Y2DJeb4TV/O s X-Received: by 2002:a17:907:60e:b0:a59:a431:a8ce with SMTP id a640c23a62f3a-a59fb94a3fdmr233568166b.2.1715190448072; Wed, 08 May 2024 10:47:28 -0700 (PDT) Received: from m1x-phil.lan (sar95-h02-176-184-10-250.dsl.sta.abo.bbox.fr. [176.184.10.250]) by smtp.gmail.com with ESMTPSA id c3-20020a170906528300b00a4e5866448bsm7833784ejm.155.2024.05.08.10.47.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 May 2024 10:47:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 25/26] hw/intc/loongson_ipi: Implement IOCSR address space for MIPS Date: Wed, 8 May 2024 19:45:09 +0200 Message-ID: <20240508174510.60470-26-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240508174510.60470-1-philmd@linaro.org> References: <20240508174510.60470-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=philmd@linaro.org; helo=mail-ej1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jiaxun Yang Implement IOCSR address space get functions for MIPS/Loongson CPUs. For MIPS/Loongson without IOCSR (i.e. Loongson-3A1000), get_cpu_iocsr_as will return as null, and send_ipi_data will fail with MEMTX_DECODE_ERROR, which matches expected behavior on hardware. Signed-off-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20240508-loongson3-ipi-v1-3-1a7b67704664@flygoat.com> Signed-off-by: Philippe Mathieu-Daudé --- hw/intc/loongson_ipi.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c index 8c888da3b2..93cc50a37a 100644 --- a/hw/intc/loongson_ipi.c +++ b/hw/intc/loongson_ipi.c @@ -15,7 +15,12 @@ #include "qemu/log.h" #include "exec/address-spaces.h" #include "migration/vmstate.h" +#ifdef TARGET_LOONGARCH64 #include "target/loongarch/cpu.h" +#endif +#ifdef TARGET_MIPS +#include "target/mips/cpu.h" +#endif #include "trace.h" static MemTxResult loongson_ipi_readl(void *opaque, hwaddr addr, @@ -56,18 +61,35 @@ static MemTxResult loongson_ipi_readl(void *opaque, hwaddr addr, return MEMTX_OK; } -static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr, +static AddressSpace *get_cpu_iocsr_as(CPUState *cpu) +{ +#ifdef TARGET_LOONGARCH64 + return LOONGARCH_CPU(cpu)->env.address_space_iocsr; +#endif +#ifdef TARGET_MIPS + if (ase_lcsr_available(&MIPS_CPU(cpu)->env)) { + return &MIPS_CPU(cpu)->env.iocsr.as; + } +#endif + return NULL; +} + +static MemTxResult send_ipi_data(CPUState *cpu, uint64_t val, hwaddr addr, MemTxAttrs attrs) { int i, mask = 0, data = 0; + AddressSpace *iocsr_as = get_cpu_iocsr_as(cpu); + + if (!iocsr_as) { + return MEMTX_DECODE_ERROR; + } /* * bit 27-30 is mask for byte writing, * if the mask is 0, we need not to do anything. */ if ((val >> 27) & 0xf) { - data = address_space_ldl(env->address_space_iocsr, addr, - attrs, NULL); + data = address_space_ldl(iocsr_as, addr, attrs, NULL); for (i = 0; i < 4; i++) { /* get mask for byte writing */ if (val & (0x1 << (27 + i))) { @@ -78,8 +100,9 @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr, data &= mask; data |= (val >> 32) & ~mask; - address_space_stl(env->address_space_iocsr, addr, - data, attrs, NULL); + address_space_stl(iocsr_as, addr, data, attrs, NULL); + + return MEMTX_OK; } static int archid_cmp(const void *a, const void *b) @@ -130,8 +153,7 @@ static MemTxResult mail_send(uint64_t val, MemTxAttrs attrs) /* override requester_id */ addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c); attrs.requester_id = cs->cpu_index; - send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); - return MEMTX_OK; + return send_ipi_data(cs, val, addr, attrs); } static MemTxResult any_send(uint64_t val, MemTxAttrs attrs) @@ -149,8 +171,7 @@ static MemTxResult any_send(uint64_t val, MemTxAttrs attrs) /* override requester_id */ addr = val & 0xffff; attrs.requester_id = cs->cpu_index; - send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); - return MEMTX_OK; + return send_ipi_data(cs, val, addr, attrs); } static MemTxResult loongson_ipi_writel(void *opaque, hwaddr addr, uint64_t val,