From patchwork Thu Apr 2 11:13:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1265529 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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48tL8D6Vv5z9sQt for ; Thu, 2 Apr 2020 22:15:24 +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.a=rsa-sha256 header.s=20161025 header.b=mPvQEB+z; 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 48tL8D4cTGzDr41 for ; Thu, 2 Apr 2020 22:15:24 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.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.a=rsa-sha256 header.s=20161025 header.b=mPvQEB+z; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48tL6w5lwBzDrP8 for ; Thu, 2 Apr 2020 22:14:14 +1100 (AEDT) Received: by mail-pg1-x541.google.com with SMTP id b1so1689093pgm.8 for ; Thu, 02 Apr 2020 04:14:14 -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:mime-version :content-transfer-encoding; bh=rV1GfEk4e330KjqtzDc/lBSjkyBiW+kRvMfoUalXgPg=; b=mPvQEB+zxJWtNpWNkn0gyXrywj7o1ZCro6f5rpjQ+GLoKD7bEmu1AfCP61vZK5DT0b fbOq7Uuvxwkct0MBLBOFNLxiDojr2E+axTZXrqiDeDDbMOFCliCF7PzNnlcE/VPkf+Xm 1rLqRn7voRbHroCrib9QfCrRapLP1j/246l2Lqh9W9AHzrG5wg7vA8gH4K6dTGxeWFh7 tO0LT9IZTp8ox3W9sw9md56A8MZaIcNezrLEpeOrsb7qFBhRKfFfX27+GgcIgTxdFEsJ ECgUItMX78bMhJWhiicqeTfrJ6CaXurQfLXl4pMgtzSbgOaCoKYXMWQpuWqEkKG8f9aV 9ZzQ== 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:mime-version :content-transfer-encoding; bh=rV1GfEk4e330KjqtzDc/lBSjkyBiW+kRvMfoUalXgPg=; b=KiXHRw0C4o5jm6En5vt3+ywS3zPnr92s7cbWG5JOu3HEYpEYzTyfCNXLsyKpcBdape +X6BhNbHBpLBJzVN/vczluvxVG69zHEhaVmsON+tQ8IFGwDMIIv6bFJz63K3CU8mR96V 5CX9scvKkgGCbEy9bsw3YPSvaGUZPCL2ixW/vfmT18CPs1AYWR0STPaN5fENvLcbAjKe cfxyltljb5D9Yu/SWCIa4pu6Vlgnq5aHqMqFYW9U/D50xkASkQMkFwK8oo3EWoFZtWCp RvwUJ0RC5JDcuj6WoLJn0q8PFNRgSM1TSicoKrAedCFbYV+4yXq8o28QFG2P5dgN8CzR fbsw== X-Gm-Message-State: AGi0PuaDuItwDZDMqTNQMdDWF5dbyIj74OLVD88ZrZEQ/PzOrmS1ppbO QrmD5mJFFdmrR2rHXRZm2ZyJoGRwCKg= X-Google-Smtp-Source: APiQypKn1IBN+02/RLC9AB590iCYRIq9d0HR2Lx4ZflD1Z0PzRqfYBvIOgcXYTe+OEYN0Wonp3diPg== X-Received: by 2002:aa7:83c5:: with SMTP id j5mr2718520pfn.100.1585826048691; Thu, 02 Apr 2020 04:14:08 -0700 (PDT) Received: from 192-168-1-12.tpgi.com.au ([193.119.57.62]) by smtp.gmail.com with ESMTPSA id x70sm3239688pgd.37.2020.04.02.04.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 04:14:08 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Thu, 2 Apr 2020 22:13:53 +1100 Message-Id: <20200402111356.1413-1-oohall@gmail.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Subject: [Skiboot] [PATCH 1/4] hw/xscom: Add scom infrastructure 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: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently the top nibble of the "part ID" is used to determine the type of a xscom_read() / xscom_write() call. This was mainly done for the benefit of PRD on P8 which would do "targeted" SCOMs to EX (core) chiplets and rely on skiboot to do find the actual scom address. Similarly, PRD also relied on this to access the SCOMs of centaur chips which are accessed via FSI on P8. On P9 PRD moved to only doing non-targeted scoms where it would only ever supply a "part ID" which was the fabric ID of the chip to be SCOMed. The centaur support was also unnecessary since OPAL didn't support any P9 systems with Centaurs. However, on future systems we will have to support memory buffer chips again so we need to expand the SCOM support to accomodate them. To do this, allow skiboot components to register a SCOM read and write() function for chip ID. This will allow us to ensure the P8 EX chiplet and Centaur SCOM code is only ever used on P8, freeing up the Part ID address space for other uses. Signed-off-by: Oliver O'Halloran --- hw/xscom.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ include/xscom.h | 12 ++++++++ 2 files changed, 87 insertions(+) diff --git a/hw/xscom.c b/hw/xscom.c index 88e22da76424..32c813e572a6 100644 --- a/hw/xscom.c +++ b/hw/xscom.c @@ -580,11 +580,75 @@ void _xscom_unlock(void) unlock(&xscom_lock); } +/* sorted by the scom controller's partid */ +static LIST_HEAD(scom_list); + +int64_t scom_register(struct scom_controller *new) +{ + struct scom_controller *cur; + + list_for_each(&scom_list, cur, link) { + if (cur->part_id == new->part_id) { + prerror("Attempted to add duplicate scom, partid %x\n", + new->part_id); + return OPAL_BUSY; + } + + if (cur->part_id > new->part_id) { + list_add_before(&scom_list, &new->link, &cur->link); + return 0; + } + } + + /* if we never find a larger partid then this is the largest */ + list_add_tail(&scom_list, &new->link); + + return 0; +} + +static struct scom_controller *scom_find(uint32_t partid) +{ + struct scom_controller *cur; + + list_for_each(&scom_list, cur, link) + if (partid == cur->part_id) + return cur; + + return NULL; +} + +static int64_t scom_read(struct scom_controller *scom, uint32_t partid, + uint64_t pcbaddr, uint64_t *val) +{ + int64_t rc = scom->read(scom, partid, pcbaddr, val); + + if (rc) { + prerror("%s: to %x off: %llx rc = %lld\n", + __func__, partid, pcbaddr, rc); + } + + return rc; +} + +static int64_t scom_write(struct scom_controller *scom, uint32_t partid, + uint64_t pcbaddr, uint64_t val) +{ + int64_t rc = scom->write(scom, partid, pcbaddr, val); + + if (rc) { + prerror("%s: to %x off: %llx rc = %lld\n", + __func__, partid, pcbaddr, rc); + } + + return rc; +} + /* * External API */ int _xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val, bool take_lock) { + struct scom_controller *scom; uint32_t gcid; int rc; @@ -611,6 +675,11 @@ int _xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val, bool take_loc return OPAL_UNSUPPORTED; break; default: + /* is it one of our hacks? */ + scom = scom_find(partid); + if (scom) + return scom_read(scom, partid, pcb_addr, val); + /** * @fwts-label XSCOMReadInvalidPartID * @fwts-advice xscom_read was called with an invalid partid. @@ -652,6 +721,7 @@ opal_call(OPAL_XSCOM_READ, opal_xscom_read, 3); int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_lock) { + struct scom_controller *scom; uint32_t gcid; int rc; @@ -666,6 +736,11 @@ int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_loc gcid = xscom_decode_chiplet(partid, &pcb_addr); break; default: + /* is it one of our hacks? */ + scom = scom_find(partid); + if (scom) + return scom_write(scom, partid, pcb_addr, val); + /** * @fwts-label XSCOMWriteInvalidPartID * @fwts-advice xscom_write was called with an invalid partid. diff --git a/include/xscom.h b/include/xscom.h index 110aa8d62981..bd8bb89ac2ab 100644 --- a/include/xscom.h +++ b/include/xscom.h @@ -197,4 +197,16 @@ extern bool xscom_ok(void); extern int64_t xscom_read_cfam_chipid(uint32_t partid, uint32_t *chip_id); extern int64_t xscom_trigger_xstop(void); + +struct scom_controller { + uint32_t part_id; + void *private; + int64_t (*read)(struct scom_controller *, uint32_t chip, uint64_t reg, uint64_t *val); + int64_t (*write)(struct scom_controller *, uint32_t chip, uint64_t reg, uint64_t val); + + struct list_node link; +}; + +int64_t scom_register(struct scom_controller *new); + #endif /* __XSCOM_H */