From patchwork Tue Nov 27 06:21:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1003619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 433twY1ftyz9s3Z for ; Tue, 27 Nov 2018 17:21:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IIiZ95RB"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 433twX5V5JzDqcf for ; Tue, 27 Nov 2018 17:21:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IIiZ95RB"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IIiZ95RB"; dkim-atps=neutral Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 433twP26fkzDqcR for ; Tue, 27 Nov 2018 17:21:40 +1100 (AEDT) Received: by mail-pg1-x542.google.com with SMTP id w7so7351931pgp.13 for ; Mon, 26 Nov 2018 22:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UHB+ygDmhElbXnchsxlnsG4gqRyRhy/Z1BmCDfgBsko=; b=IIiZ95RBqSpq8x1AhemcJp1Srvp7DycyAApDlZy0G28Sjy4kAuncpML6RGqlSIkUSx 0Ch79RRZqgJw30abEgfyKkGKCKYVA2QIVCisLkLrfp5b4tzV0R5hctXImpV2nHgffpbc wsSJxznG4InxUS2AYwbxGZEzHeSe5xvs1if9UKnT2U/unUSp0ZRIigi7/RojRcQT251s pLoQv6rlR0OryrzLQm15JBzImvyCbQFHmniiJfnsyA8u/hSwmmEXtVU44E29Z6OXEpHF 5RfrSXYib9nWvuZzjqaF/IwZ8vy1StJVyVtSFXyG+KavY843FveWnDOxTRi0vyh6nYLm ADvQ== 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; bh=UHB+ygDmhElbXnchsxlnsG4gqRyRhy/Z1BmCDfgBsko=; b=SP3dTx1y6yusHRyomBd5sZmKvwJGC0wi4mlH9ZcDCi/Iny+VHYzkWfPckTqK7htVhK Wp6rgAdz+mIDIVa0eBQRv703D5601J0dFpR5FfPuE2AZ6G1xkVEsNPbSJNiLo7RuJUgA 0Ew7vKRL211TqFjtX8l6yysaZ5xJCopg4jSB38nf5LM19IAnPU+pKq7gHHTZsCZtE2vJ byBWjWeGm05mObTB/c4dqk9/m7QUe31YWM1poaemqBNveLVEB40bt8FWYVPW2zicwlPv E1DCU+HcOrOPXX0OHFum1U+omu9uhmnX+jC3dSCZvJzD+NDvHdMmU9a+D8Od0wbmcUqL 6Mug== X-Gm-Message-State: AGRZ1gIXUEV73ETDiGutPK/eSCe1KIdT/veVsDE2JztqaAgpFiy5OVDP XjLwYwKEk1ZsD5G/Kq3QEAxmTn5x X-Google-Smtp-Source: AJdET5dlu8ifEMySjkmrkZfIpCVAVC70w/02iVPTrrhNdnE6X7GFC90L/qNrUoHv7sJUleQ488jpVQ== X-Received: by 2002:a62:ce0e:: with SMTP id y14mr32745663pfg.100.1543299698917; Mon, 26 Nov 2018 22:21:38 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r83sm4371741pfc.115.2018.11.26.22.21.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Nov 2018 22:21:38 -0800 (PST) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 27 Nov 2018 17:21:16 +1100 Message-Id: <20181127062119.15775-1-oohall@gmail.com> X-Mailer: git-send-email 2.17.2 Subject: [Skiboot] [PATCH 1/4] phb4: Rework BDFN filtering in phb4_set_pe() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" General cleanup. For a function that does nothing more than a mask-and-compare the current implementation is way more convoluted than it has any right to be. Signed-off-by: Oliver O'Halloran Reviewed-by: Andrew Donnellan --- hw/phb4.c | 58 ++++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/hw/phb4.c b/hw/phb4.c index c0797647c124..b26f57277f04 100644 --- a/hw/phb4.c +++ b/hw/phb4.c @@ -2164,8 +2164,7 @@ static int64_t phb4_set_pe(struct phb *phb, uint8_t action) { struct phb4 *p = phb_to_phb4(phb); - uint64_t mask, val, tmp, idx; - int32_t all = 0; + uint64_t mask, idx; uint16_t *rte; /* Sanity check */ @@ -2179,55 +2178,32 @@ static int64_t phb4_set_pe(struct phb *phb, fcompare > OPAL_COMPARE_RID_FUNCTION_NUMBER) return OPAL_PARAMETER; + /* match everything by default */ + mask = 0; + /* Figure out the RID range */ - if (bcompare == OpalPciBusAny) { - mask = 0x0; - val = 0x0; - all = 0x1; - } else { - tmp = ((0x1 << (bcompare + 1)) - 1) << (15 - bcompare); - mask = tmp; - val = bdfn & tmp; - } + if (bcompare != OpalPciBusAny) + mask = ((0x1 << (bcompare + 1)) - 1) << (15 - bcompare); - if (dcompare == OPAL_IGNORE_RID_DEVICE_NUMBER) - all = (all << 1) | 0x1; - else { + if (dcompare == OPAL_COMPARE_RID_DEVICE_NUMBER) mask |= 0xf8; - val |= (bdfn & 0xf8); - } - if (fcompare == OPAL_IGNORE_RID_FUNCTION_NUMBER) - all = (all << 1) | 0x1; - else { + if (fcompare == OPAL_COMPARE_RID_FUNCTION_NUMBER) mask |= 0x7; - val |= (bdfn & 0x7); - } + + if (action == OPAL_UNMAP_PE) + pe_number = PHB4_RESERVED_PE_NUM(p); /* Map or unmap the RTT range */ - if (all == 0x7) { - if (action == OPAL_MAP_PE) { - for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++) - p->rte_cache[idx] = pe_number; - } else { - for (idx = 0; idx < ARRAY_SIZE(p->rte_cache); idx++) - p->rte_cache[idx] = PHB4_RESERVED_PE_NUM(p); - } - memcpy((void *)p->tbl_rtt, p->rte_cache, RTT_TABLE_SIZE); - } else { - rte = (uint16_t *)p->tbl_rtt; - for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++, rte++) { - if ((idx & mask) != val) - continue; - if (action == OPAL_MAP_PE) - p->rte_cache[idx] = pe_number; - else - p->rte_cache[idx] = PHB4_RESERVED_PE_NUM(p); - *rte = p->rte_cache[idx]; + rte = (uint16_t *)p->tbl_rtt; + for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++) { + if ((idx & mask) == (bdfn & mask)) { + p->rte_cache[idx] = pe_number; + rte[idx] = pe_number; } } - /* Invalidate the entire RTC */ + /* Invalidate the RID Translation Cache (RTC) inside the PHB */ out_be64(p->regs + PHB_RTC_INVALIDATE, PHB_RTC_INVALIDATE_ALL); return OPAL_SUCCESS;