From patchwork Thu Apr 2 11:13:55 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: 1265528 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48tL7q6P4jz9sQt for ; Thu, 2 Apr 2020 22:15:03 +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=ZDHYNqdL; 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 48tL7q4yS4zDrPP for ; Thu, 2 Apr 2020 22:15:03 +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::543; helo=mail-pg1-x543.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=ZDHYNqdL; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 48tL6w66J2zDrPB for ; Thu, 2 Apr 2020 22:14:16 +1100 (AEDT) Received: by mail-pg1-x543.google.com with SMTP id t24so1692750pgj.7 for ; Thu, 02 Apr 2020 04:14:16 -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=2s1ozYhIp9baQFczpoApQCpbvYJnsK5RUBSf3rih/Cg=; b=ZDHYNqdLFjWDOvk51BpYDIXiSNf7IqFGEd7HVsZE4BEqTSW4A298/FLEbbLz9ou/Fd ROfTVjU4zNyD5Z54QyqBnZmR0anTwC5Ip4ywnWKNFhTODoI3zxgF10WZe7qYJmOaoSje UshpmkepInkDomskVmq74KprYxhp8rHHZpfNl/Eq9Ic9W5l14f0+2j6DUE/pgGfibR1r ZxXpmMUO3S/rC5VBT3qah9RleWfDX1ptSqlotXTGaJVQQl+OtkujMTrQS0mZTgip7Hw6 WS6XCPx1iyyYVPiZ6X3uCzH0fjAMDK1C+nswz2zs2/JIYlTs94TfG96EJxatwi9BZpCt 5Nxw== 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=2s1ozYhIp9baQFczpoApQCpbvYJnsK5RUBSf3rih/Cg=; b=G4FFbfqEOaEqgKp22XIq6g7rT93kP1DpobM7oowsV+zhog5m8RUmVYHC35JRbnF4oI /NNxYRsBiC3iPoriC9bOrkxMx36Xjc57J6nNvrwoQ5LZQs8IKijeLDVg39WTxGOumaqY 5mEOWPCCum2y3ayQDpe/5o9t9SYgrlmoRDF03NNc0x24+D/m/30JJ5meZC7MQLQuKvtf AcHuVobRqwX3CPHFWjyIcPaVhZWXeadOuGBCQH6bojXWiYQosaa0JLHB2fwGYB8ur4Qt KWsptagHgNT+7CmT1Gd3HE2NSL2AhyUWL2KNOoFfbU17vbUOtwY0Ydk3/dwdUSfd+inO rhKg== X-Gm-Message-State: AGi0PubcATeo6ZnJCYKiyS13JIOt1OzLWuM5tPJoYOya4y/guOZpuOpi p8rTZHn9mTaXE/5IuR/yFwAexhvfbyk= X-Google-Smtp-Source: APiQypKG8jWoKUkyAqB+cvmUk+KrbdSubMW2nay6ChN6GNLWSiiYdrfkmW5dk3HMgFTWTYCcPrI09g== X-Received: by 2002:a62:3241:: with SMTP id y62mr2449933pfy.326.1585826053478; Thu, 02 Apr 2020 04:14:13 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 04:14:13 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Thu, 2 Apr 2020 22:13:55 +1100 Message-Id: <20200402111356.1413-3-oohall@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200402111356.1413-1-oohall@gmail.com> References: <20200402111356.1413-1-oohall@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 3/4] hdata/memory: Add support for memory-buffer mmio 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" HDAT now allows associating a set of MMIO address ranges with an MSAREA. This is to allow for exporting the MMIO register space associated with a memory-buffer chip to the hypervisor so we can wire up access to that for PRD. The DT format is similar to the old centaur memory-buffer@ nodes that we had on P8 OpenPower systems. The biggest difference is that the HDAT format allows for multiple memory ranges on each "chip" and each of these ranges may have a different register size. Cc: Klaus Heinrich Kiwi Signed-off-by: Oliver O'Halloran --- hdata/memory.c | 139 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 125 insertions(+), 14 deletions(-) mode change 100644 => 100755 hdata/memory.c diff --git a/hdata/memory.c b/hdata/memory.c old mode 100644 new mode 100755 index 6d060f7f04cf..7ce92750278f --- a/hdata/memory.c +++ b/hdata/memory.c @@ -55,10 +55,17 @@ struct HDIF_ms_area_address_range { #define PHYS_ATTR_STATUS_NOT_SAVED 0x08 #define PHYS_ATTR_STATUS_MEM_INVALID 0xff +/* Memory Controller ID for Nimbus P9 systems */ #define MS_CONTROLLER_MCBIST_ID(id) GETFIELD(PPC_BITMASK32(0, 1), id) #define MS_CONTROLLER_MCS_ID(id) GETFIELD(PPC_BITMASK32(4, 7), id) #define MS_CONTROLLER_MCA_ID(id) GETFIELD(PPC_BITMASK32(8, 15), id) +/* Memory Controller ID for P9 AXONE systems */ +#define MS_CONTROLLER_MC_ID(id) GETFIELD(PPC_BITMASK32(0, 1), id) +#define MS_CONTROLLER_MI_ID(id) GETFIELD(PPC_BITMASK32(4, 7), id) +#define MS_CONTROLLER_MCC_ID(id) GETFIELD(PPC_BITMASK32(8, 15), id) +#define MS_CONTROLLER_OMI_ID(id) GETFIELD(PPC_BITMASK32(16, 31), id) + struct HDIF_ms_area_id { __be16 id; #define MS_PTYPE_RISER_CARD 0x8000 @@ -73,6 +80,20 @@ struct HDIF_ms_area_id { __be16 share_id; } __packed; + +// FIXME: it should be 9, current HDATs are broken +#define MSAREA_IDATA_MMIO_IDX 8 +struct HDIF_ms_area_ocmb_mmio { + __be64 range_start; + __be64 range_end; + __be32 controller_id; + __be32 proc_chip_id; + __be64 hbrt_id; +#define OCMB_SCOM_8BYTE_ACCESS PPC_BIT(0) +#define OCMB_SCOM_4BYTE_ACCESS PPC_BIT(1) + __be64 flags; +} __packed; + static void append_chip_id(struct dt_node *mem, u32 id) { struct dt_property *prop; @@ -366,7 +387,7 @@ static void vpd_parse_spd(struct dt_node *dimm, const char *spd, u32 size) dt_add_property_cells(dimm, "manufacturer-id", be16_to_cpu(*vendor)); } -static void add_mca_dimm_info(struct dt_node *mca, +static void add_dimm_info(struct dt_node *parent, const struct HDIF_common_hdr *msarea) { unsigned int i, size; @@ -394,11 +415,11 @@ static void add_mca_dimm_info(struct dt_node *mca, continue; /* Use Resource ID to add dimm node */ - dimm = dt_find_by_name_addr(mca, "dimm", + dimm = dt_find_by_name_addr(parent, "dimm", be16_to_cpu(fru_id->rsrc_id)); if (dimm) continue; - dimm= dt_new_addr(mca, "dimm", be16_to_cpu(fru_id->rsrc_id)); + dimm= dt_new_addr(parent, "dimm", be16_to_cpu(fru_id->rsrc_id)); assert(dimm); dt_add_property_cells(dimm, "reg", be16_to_cpu(fru_id->rsrc_id)); @@ -439,21 +460,13 @@ static inline void dt_add_mem_reg_property(struct dt_node *node, u64 addr) dt_add_property_cells(node, "reg", addr); } -static void add_memory_controller(const struct HDIF_common_hdr *msarea, +static void add_memory_controller_p9n(const struct HDIF_common_hdr *msarea, const struct HDIF_ms_area_address_range *arange) { - uint32_t chip_id, version; + uint32_t chip_id; uint32_t controller_id, mcbist_id, mcs_id, mca_id; struct dt_node *xscom, *mcbist, *mcs, *mca; - /* - * Memory hierarchy may change between processor version. Presently - * it's only creating memory hierarchy for P9 (Nimbus) and P9P (Axone). - */ - version = PVR_TYPE(mfspr(SPR_PVR)); - if (version != PVR_TYPE_P9 && version != PVR_TYPE_P9P) - return; - chip_id = pcid_to_chip_id(be32_to_cpu(arange->chip)); controller_id = be32_to_cpu(arange->controller_id); xscom = find_xscom_for_chip(chip_id); @@ -489,7 +502,103 @@ static void add_memory_controller(const struct HDIF_common_hdr *msarea, dt_add_mem_reg_property(mca, mca_id); } - add_mca_dimm_info(mca, msarea); + add_dimm_info(mca, msarea); +} + +static void add_memory_buffer_mmio(const struct HDIF_common_hdr *msarea) +{ + const struct HDIF_ms_area_ocmb_mmio *mmio; + uint64_t min_addr = ~0ull, hbrt_id = 0; + const struct HDIF_array_hdr *array; + unsigned int i, count, ranges = 0; + struct dt_node *membuf; + uint64_t *reg, *flags; + + if (be32_to_cpu(msarea->version) < 0x50) { + prlog(PR_WARNING, "MS AREA: Inconsistent MSAREA version %x for P9P system", + be32_to_cpu(msarea->version)); + return; + } + + array = HDIF_get_iarray(msarea, MSAREA_IDATA_MMIO_IDX, &count); + if (!array || count <= 0) { + prerror("MS AREA: No OCMB MMIO array at MS Area %p\n", msarea); + return; + } + + reg = zalloc(count * 2 * sizeof(*reg)); + flags = zalloc(count * sizeof(*flags)); + + /* grab the hbrt id from the first range. */ + HDIF_iarray_for_each(array, i, mmio) { + hbrt_id = be64_to_cpu(mmio->hbrt_id); + break; + } + + prlog(PR_DEBUG, "Adding memory buffer MMIO ranges for %"PRIx64"\n", + hbrt_id); + + HDIF_iarray_for_each(array, i, mmio) { + uint64_t start, end; + + if (hbrt_id != be64_to_cpu(mmio->hbrt_id)) { + prerror("HBRT ID mismatch!\n"); + continue; + } + + start = cleanup_addr(be64_to_cpu(mmio->range_start)); + end = cleanup_addr(be64_to_cpu(mmio->range_end)); + if (start < min_addr) + min_addr = start; + + prlog(PR_DEBUG, " %"PRIx64" - [%016"PRIx64"-%016"PRIx64")\n", + hbrt_id, start, end); + + reg[2 * ranges ] = cpu_to_be64(start); + reg[2 * ranges + 1] = cpu_to_be64(end - start + 1); + flags[ranges] = mmio->flags; /* both are BE */ + ranges++; + } + + membuf = dt_find_by_name_addr(dt_root, "memory-buffer", min_addr); + if (membuf) { + prerror("attempted to duplicate %s\n", membuf->name); + goto out; + } + + membuf = dt_new_addr(dt_root, "memory-buffer", min_addr); + assert(membuf); + + dt_add_property_string(membuf, "compatible", "ibm,explorer"); + dt_add_property_cells(membuf, "ibm,chip-id", hbrt_id); + + /* + * FIXME: We should probably be sorting the address ranges based + * on the starting address. + */ + dt_add_property(membuf, "reg", reg, sizeof(*reg) * 2 * ranges); + dt_add_property(membuf, "flags", flags, sizeof(*flags) * ranges); + +out: + free(flags); + free(reg); +} + +static void add_memory_controller(const struct HDIF_common_hdr *msarea, + const struct HDIF_ms_area_address_range *arange) +{ + const uint32_t version = PVR_TYPE(mfspr(SPR_PVR)); + /* + * Memory hierarchy may change between processor version. Presently + * it's only creating memory hierarchy for P9 (Nimbus) and P9P (Axone). + */ + + if (version == PVR_TYPE_P9) + return add_memory_controller_p9n(msarea, arange); + else if (version == PVR_TYPE_P9P) + return; //return add_memory_controller_p9p(msarea, arange); + else + return; } static void get_msareas(struct dt_node *root, @@ -569,6 +678,8 @@ static void get_msareas(struct dt_node *root, /* Add RAM Area VPD */ vpd_add_ram_area(msarea); + add_memory_buffer_mmio(msarea); + /* This offset is from the arr, not the header! */ arange = (void *)arr + be32_to_cpu(arr->offset); for (j = 0; j < be32_to_cpu(arr->ecnt); j++) {