From patchwork Wed Oct 10 20:37:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10635241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1CEC16B1 for ; Wed, 10 Oct 2018 20:43:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DED8252D5 for ; Wed, 10 Oct 2018 20:43:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4149E28979; Wed, 10 Oct 2018 20:43:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB057252D5 for ; Wed, 10 Oct 2018 20:43:34 +0000 (UTC) Received: from localhost ([::1]:59060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gALKQ-0006xb-1N for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Oct 2018 16:43:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gALFe-0002uO-KF for qemu-devel@nongnu.org; Wed, 10 Oct 2018 16:38:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gALFd-0002Zv-2D for qemu-devel@nongnu.org; Wed, 10 Oct 2018 16:38:38 -0400 Received: from mail-yw1-xc42.google.com ([2607:f8b0:4864:20::c42]:41277) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gALFY-0002SI-OX; Wed, 10 Oct 2018 16:38:32 -0400 Received: by mail-yw1-xc42.google.com with SMTP id 135-v6so2716223ywo.8; Wed, 10 Oct 2018 13:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OO5omZne/mpRB5n5xRTpKEr+jlwMxC9ACMNSJpaNgDo=; b=dUdyBBK9XM+xY7mmR5WhrY43fUHl8hYxWZj83dB8aiEcPKHIhce3smHouFQSDZ/VjT V6SZtEvIdSe1R+nM49L25pAhe79tcrOQ8XUZNwFowsDZIAf9/CtWoikVOOYwn1wxShNm iRvijtDSLrkcbPY45YELY/89OYgP1u9VDDQytcAGhBgjUEC/dkcDeeZ56NXv3LL2V+rF Ilt7gtdlwZuxbip6oQYcd98O5ciK70yplEaRctwC5lRahaXWDBzlpGBkd5VQVFFIT10A 4hktgNZcbh9I8tJDnrw44FsaDu5AjeQs4awoOv7zc0v6LIf2KFHC8RxnM9pzEGM3h+lK XyQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OO5omZne/mpRB5n5xRTpKEr+jlwMxC9ACMNSJpaNgDo=; b=QRN3OJyJcInx9OpQw7EdxyDtzFjjg0wVdF0xbFMckDZ7SfRKHVIVQY2TxDr26C6x4/ Toz0hUREawTr1u9Z9dEqX90Hdqp8P1UMASNrxc2AL6J2g6IJmjq62AzgakJhz/ETzJrT iWwBb6qopJQeKrHJTpmQEjr1SX1m8ndKnysnH8/83RF+DA9Rc9/Lt7E3Je9ATCYIOyvs infrb/a29vCIL1rDCYAlEvIls3j2Ctxc9iilWMHY9N8cfeYUqWW0pR3P6fA9DQHYeZT5 n3mto05WxP/hThdjdQxe1GZ1Eq81bFdmdTOGMHajfq+tpCLCmn6/Al6pwscUidYn2g7/ JpZg== X-Gm-Message-State: ABuFfoiLt2wPzG3nZdmpNZpXRpPHEymWkljS7vY/N9FY4lLdL0kT0ha6 8g4PoJpgB5CXFKrSJOmrmMLN9+mD X-Google-Smtp-Source: ACcGV60B3t7e8HLYcqzOelAojh9SDsqlvUKUNQBIvp+mZ7jYPz2C7Wsl9Ef/0AdmvY6OcL/hFfBxbw== X-Received: by 2002:a0d:ec0e:: with SMTP id v14-v6mr19955778ywe.384.1539203912012; Wed, 10 Oct 2018 13:38:32 -0700 (PDT) Received: from quinoa.localdomain ([216.85.170.153]) by smtp.gmail.com with ESMTPSA id u131-v6sm15170728ywf.13.2018.10.10.13.38.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 13:38:31 -0700 (PDT) From: Aaron Lindsay To: qemu-arm@nongnu.org, Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite Date: Wed, 10 Oct 2018 16:37:30 -0400 Message-Id: <20181010203735.27918-10-aclindsa@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181010203735.27918-1-aclindsa@gmail.com> References: <20181010203735.27918-1-aclindsa@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c42 Subject: [Qemu-devel] [PATCH v6 09/14] target/arm: Add array for supported PMU events, generate PMCEID[01] 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: Aaron Lindsay , Michael Spradling , qemu-devel@nongnu.org, Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit doesn't add any supported events, but provides the framework for adding them. We store the pm_event structs in a simple array, and provide the mapping from the event numbers to array indexes in the supported_event_map array. Because the value of PMCEID[01] depends upon which events are supported at runtime, generate it dynamically. Signed-off-by: Aaron Lindsay --- target/arm/cpu.c | 20 +++++++++++++------- target/arm/cpu.h | 10 ++++++++++ target/arm/cpu64.c | 2 -- target/arm/helper.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index f69addb961..7f39f25f51 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -948,9 +948,19 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) if (!cpu->has_pmu) { unset_feature(env, ARM_FEATURE_PMU); cpu->id_aa64dfr0 &= ~0xf00; - } else if (!kvm_enabled()) { - arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); - arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); + } + if (arm_feature(env, ARM_FEATURE_PMU)) { + uint64_t pmceid = get_pmceid(&cpu->env); + cpu->pmceid0 = pmceid & 0xffffffff; + cpu->pmceid1 = (pmceid >> 32) & 0xffffffff; + + if (!kvm_enabled()) { + arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); + arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); + } + } else { + cpu->pmceid0 = 0x00000000; + cpu->pmceid1 = 0x00000000; } if (!arm_feature(env, ARM_FEATURE_EL2)) { @@ -1583,8 +1593,6 @@ static void cortex_a7_initfn(Object *obj) cpu->id_pfr0 = 0x00001131; cpu->id_pfr1 = 0x00011011; cpu->id_dfr0 = 0x02010555; - cpu->pmceid0 = 0x00000000; - cpu->pmceid1 = 0x00000000; cpu->id_afr0 = 0x00000000; cpu->id_mmfr0 = 0x10101105; cpu->id_mmfr1 = 0x40000000; @@ -1626,8 +1634,6 @@ static void cortex_a15_initfn(Object *obj) cpu->id_pfr0 = 0x00001131; cpu->id_pfr1 = 0x00011011; cpu->id_dfr0 = 0x02010555; - cpu->pmceid0 = 0x0000000; - cpu->pmceid1 = 0x00000000; cpu->id_afr0 = 0x00000000; cpu->id_mmfr0 = 0x10201105; cpu->id_mmfr1 = 0x20000000; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index d9cd8dd92c..cc026f0b75 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -975,6 +975,16 @@ void pmu_op_finish(CPUARMState *env); void pmu_pre_el_change(ARMCPU *cpu, void *ignored); void pmu_post_el_change(ARMCPU *cpu, void *ignored); +/* + * get_pmceid + * @env: CPUARMState + * + * Return the PMCEID[01] register values corresponding to the counters which + * are supported given the current configuration (0 is low 32, 1 is high 32 + * bits) + */ +uint64_t get_pmceid(CPUARMState *env); + /* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants * for both old and new bit meanings. Code which tests against those diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index db71504cb5..440d874c17 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -143,8 +143,6 @@ static void aarch64_a57_initfn(Object *obj) cpu->id_isar6 = 0; cpu->id_aa64pfr0 = 0x00002222; cpu->id_aa64dfr0 = 0x10305106; - cpu->pmceid0 = 0x00000000; - cpu->pmceid1 = 0x00000000; cpu->id_aa64isar0 = 0x00011120; cpu->id_aa64mmfr0 = 0x00001124; cpu->dbgdidr = 0x3516d000; diff --git a/target/arm/helper.c b/target/arm/helper.c index f3c00c3db0..375b6dcda5 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -976,6 +976,48 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env) return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); } +typedef struct pm_event { + uint16_t number; /* PMEVTYPER.evtCount is 16 bits wide */ + /* If the event is supported on this CPU (used to generate PMCEID[01]) */ + bool (*supported)(CPUARMState *); + /* + * Retrieve the current count of the underlying event. The programmed + * counters hold a difference from the return value from this function + */ + uint64_t (*get_count)(CPUARMState *); +} pm_event; + +static const pm_event pm_events[] = { +}; +#define MAX_EVENT_ID 0x0 +#define UNSUPPORTED_EVENT UINT16_MAX +static uint16_t supported_event_map[MAX_EVENT_ID + 1]; + +/* + * Called upon initialization to build PMCEID0 (low 32 bits) and PMCEID1 (high + * 32). We also use it to build a map of ARM event numbers to indices in + * our pm_events array. + */ +uint64_t get_pmceid(CPUARMState *env) +{ + uint64_t pmceid = 0; + unsigned int i; + + for (i = 0; i <= MAX_EVENT_ID; i++) { + supported_event_map[i] = UNSUPPORTED_EVENT; + } + + for (i = 0; i < ARRAY_SIZE(pm_events); i++) { + const pm_event *cnt = &pm_events[i]; + assert(cnt->number <= MAX_EVENT_ID); + if (cnt->supported(env)) { + pmceid |= (1 << cnt->number); + supported_event_map[cnt->number] = i; + } + } + return pmceid; +} + static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri, bool isread) {