From nobody Sun Apr 12 02:49:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1771770862; cv=none; d=zohomail.com; s=zohoarc; b=Zi4XW9sNwyQoNCSi1Mctwek6TKdBr62j+/DakEIDyBsYxA+6y4U2nhNWQCivvLJVTUgQOIimuL6vu8DKlIEAKS/kTLj3m93czJ4Qm0kEP0RYvIr+As4stQitxbiL5cUyHHMHbV35a1KvG4egPICk6c/m2XNvXad+Jpo7/3b7o8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771770862; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NXf3I54LQjbQo5rdjnX8oUBXAUmrFhpR1xfT44HvLzM=; b=BAKj/1Jsk78wzEpSrdceS4wzkikqButeWpdWDcYX0DNEO3hjeb7L89FpIHFjtXQx4TR8UJYXY81XUJ3668KYvRKjAS+Mvd+ErsV3d5ve6xhIpcj8ShZDcJ7G6Tx2N0hGoEFZyOfeHFaFcDqg0kbCsBcbrhfuWKchOLB9+JUfRbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771770862628199.63674995305814; Sun, 22 Feb 2026 06:34:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuASl-00009S-GQ; Sun, 22 Feb 2026 09:29:35 -0500 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 1vuASD-000856-HS for qemu-devel@nongnu.org; Sun, 22 Feb 2026 09:29:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vuASB-0006nX-N3 for qemu-devel@nongnu.org; Sun, 22 Feb 2026 09:29:01 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-fDOGoHU1OwSWoFr9kvKdSA-1; Sun, 22 Feb 2026 09:28:57 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4368060a5e5so3855502f8f.3 for ; Sun, 22 Feb 2026 06:28:57 -0800 (PST) Received: from redhat.com (IGLD-80-230-79-166.inter.net.il. [80.230.79.166]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970c00db8sm11909430f8f.12.2026.02.22.06.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Feb 2026 06:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771770539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NXf3I54LQjbQo5rdjnX8oUBXAUmrFhpR1xfT44HvLzM=; b=XNBPKSU0tq+rPMSN4D8uo5nSruN8Gq8ssxixfT4Smn/CLeOHlghoAPvSTPWnkEaT/3f5H8 UoZy13nNPV+oF4CmVh/mJf3jauLbz+WeJrx36Pd8+RAYinl8cXZg84p5uPwBY0saV472H1 osTaaI0C9QzNN15dcwkMaHY72GkEpXU= X-MC-Unique: fDOGoHU1OwSWoFr9kvKdSA-1 X-Mimecast-MFC-AGG-ID: fDOGoHU1OwSWoFr9kvKdSA_1771770537 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1771770536; x=1772375336; darn=nongnu.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NXf3I54LQjbQo5rdjnX8oUBXAUmrFhpR1xfT44HvLzM=; b=HYTMIdbnyDyHnXm/4eya1QNQHhKZ15tRbrYKfcTyE0+7On1fuBIQr8jyIpU8V/9dkS UypkxVHlcjkH5Tr32po4cX+f4yatIFSDSqMWWVm5wxHl2KISt3wnsF6u4wlxUczvzjOR Y22gA9OKvcKAG5z/Z0qKn00bsm7XyVn7TRd1klogUzCtWMNh5fpPgMRg9YE505MKWvKq /RLSkdsYBGMg9b73TKOuiN9DKFwm31NHdOh2hRbtx+Fh5eOL//3bnorA//IYB109Lv+g ywyYc22fR+NIhEtJtI1dWotEfb1eqhDi61BneonbeOiAKEMgcsQZEuY0L4QYIlE6cBAJ Lb4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771770536; x=1772375336; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NXf3I54LQjbQo5rdjnX8oUBXAUmrFhpR1xfT44HvLzM=; b=G5QVI3JiGjvv/5dCkgeQuXEOCfQzDUbe+mCqTIipRPEb1TcxbrxsBSxrUeCMmOVq18 0ci3D7X6cfAfYkUsCqiKo01756TkZk7gSTmxNNaR4nGDOs0oAD90dIVU6PGr9R3qQt8c YcuqDxaktKW2dm0YtT0H7y2gqdSMH2DS19fJligwmTa7M+63Sj/Se92ATc3Yb0TYqXil 9UBawqwPLE1wEGaoA85Scv0W4KImVY5IpA9UzuB4qotYQGg47kaU2vnMr6tIpdrg5gUY OKSzCCBYlAJQDRGZK0k5mxp3nRSxbJcUfq+519a9yx/P2bCUE5s6YyavsALARWBcOvjk kCaw== X-Gm-Message-State: AOJu0YwtXt3sIFG1WvojEJVGd93buRh5SEBugsKT19g/EoAbpd8kyEuj e3OeufSCLPLdkCnu+RzdSynJWw3/M3RA4uABZ4gn868Qx6AuBw4+WL4YLTLc5RU2NS6Y9RT+3Bk RRQrqEnuMKIoh+0J0nqzY3vnTvf19a+/pCdegUEokMzM88mWLqYUqj143kMzm7kS71ZUy19ZiQR sW/WjIWF7JHJ9uARR6sxBfgQFaRY2Qi2365w== X-Gm-Gg: AZuq6aKJSxXe5Dqliwpe7vP8uBYpy4BbQfmu5ccSdU9fJ/l0iDltcQulUGijzQBqDgN 8l60uUYQ6jKYsvUQidudnBTeJjVyQ+t+YyUbyNe4YXjPER+A0DuvA6mGptSORdtuDb8XjeI/eBd orFi7vxz3ix73gxuisNgoICI4a+ofo8wSZi6WXG/PBLowOQjbu08VREP/BB6wt6Fa0mjiYpJ+SP HuY4a5UpBAbp/rHVNxzFR52MZfHmFzC4w6UUxdgyCEaR8ANSn/BCtw+oV5QSBfJ0qaFTAo17M2r /KPF1/tdkWOpy8lUUrHGKTuYv251CE4tUEx+QeLei0pm9ezmFMnKp7gGnsLvcOeHiioLZFx4C+F x/VSGA4NpoJCshwgtg2Dn1uhesYh7a1xWX4E+OBswln0sPQ== X-Received: by 2002:a05:6000:402b:b0:430:f5ed:83e3 with SMTP id ffacd0b85a97d-4396f150730mr10758321f8f.6.1771770536202; Sun, 22 Feb 2026 06:28:56 -0800 (PST) X-Received: by 2002:a05:6000:402b:b0:430:f5ed:83e3 with SMTP id ffacd0b85a97d-4396f150730mr10758274f8f.6.1771770535531; Sun, 22 Feb 2026 06:28:55 -0800 (PST) Date: Sun, 22 Feb 2026 09:28:53 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ira Weiny , Dongjoo Seo , Davidlohr Bueso , Jonathan Cameron , Fan Ni Subject: [PULL 16/33] hw/cxl: Refactor component register initialization Message-ID: <5729c01a600d62c19202936481b06e84a14236ba.1771770471.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.798, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.79, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1771770864010158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ira Weiny CXL 3.2 8.2.4 Table 8-22 defines which capabilities are mandatory, not permitted, or optional for each type of device. cxl_component_register_init_common() uses a rather odd 'fall through' mechanism to define each component register set. This assumes that any device or capability being added builds on the previous devices capabilities. This is not true as there are mutually exclusive capabilities defined. For example, downstream ports can not have snoop but it can have Back Invalidate capable decoders. Refactor this code to make it easier to add individual capabilities as defined by a device type. Any capability which is not specified by the type is left NULL'ed out which complies with the packed nature of the register array. Update all spec references to 3.2. No functional changes should be seen with this patch. Signed-off-by: Ira Weiny Tested-by: Dongjoo Seo [rebased, no RAS for HBs, r3.2 references] Signed-off-by: Davidlohr Bueso Signed-off-by: Jonathan Cameron Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Message-Id: <20260204170936.43959-3-Jonathan.Cameron@huawei.com> --- hw/cxl/cxl-component-utils.c | 75 +++++++++++----------------------- include/hw/cxl/cxl_component.h | 33 ++++++++++----- 2 files changed, 46 insertions(+), 62 deletions(-) diff --git a/hw/cxl/cxl-component-utils.c b/hw/cxl/cxl-component-utils.c index 473895948b..91770f103a 100644 --- a/hw/cxl/cxl-component-utils.c +++ b/hw/cxl/cxl-component-utils.c @@ -284,32 +284,6 @@ void cxl_component_register_init_common(uint32_t *reg_= state, { int caps =3D 0; =20 - /* - * In CXL 2.0 the capabilities required for each CXL component are such - * that, with the ordering chosen here, a single number can be used to - * define which capabilities should be provided. - */ - switch (type) { - case CXL2_DOWNSTREAM_PORT: - case CXL2_DEVICE: - /* RAS, Link */ - caps =3D 2; - break; - case CXL2_UPSTREAM_PORT: - case CXL2_TYPE3_DEVICE: - case CXL2_LOGICAL_DEVICE: - /* + HDM */ - caps =3D 3; - break; - case CXL2_ROOT_PORT: - case CXL2_RC: - /* + Extended Security, + Snoop */ - caps =3D 5; - break; - default: - abort(); - } - memset(reg_state, 0, CXL2_COMPONENT_CM_REGION_SIZE); =20 /* CXL Capability Header Register */ @@ -317,11 +291,12 @@ void cxl_component_register_init_common(uint32_t *reg= _state, ARRAY_FIELD_DP32(reg_state, CXL_CAPABILITY_HEADER, VERSION, CXL_CAPABILITY_VERSION); ARRAY_FIELD_DP32(reg_state, CXL_CAPABILITY_HEADER, CACHE_MEM_VERSION, = 1); - ARRAY_FIELD_DP32(reg_state, CXL_CAPABILITY_HEADER, ARRAY_SIZE, caps); =20 #define init_cap_reg(reg, id, version) = \ do { = \ - int which =3D R_CXL_##reg##_CAPABILITY_HEADER; = \ + int which =3D CXL_##reg##_CAP_HDR_IDX; = \ + if (CXL_##reg##_CAP_HDR_IDX > caps) = \ + caps =3D CXL_##reg##_CAP_HDR_IDX; = \ reg_state[which] =3D FIELD_DP32(reg_state[which], = \ CXL_##reg##_CAPABILITY_HEADER, ID, i= d); \ reg_state[which] =3D = \ @@ -332,37 +307,35 @@ void cxl_component_register_init_common(uint32_t *reg= _state, CXL_##reg##_REGISTERS_OFFSET); = \ } while (0) =20 + /* CXL r3.2 8.2.4 Table 8-22 */ switch (type) { - case CXL2_DEVICE: + case CXL2_ROOT_PORT: + case CXL2_RC: + /* + Extended Security, + Snoop */ + init_cap_reg(EXTSEC, 6, 1); + init_cap_reg(SNOOP, 8, 1); + /* fallthrough */ + case CXL2_UPSTREAM_PORT: case CXL2_TYPE3_DEVICE: case CXL2_LOGICAL_DEVICE: - case CXL2_ROOT_PORT: - case CXL2_UPSTREAM_PORT: + /* + HDM */ + init_cap_reg(HDM, 5, 1); + hdm_init_common(reg_state, write_msk, type); + /* fallthrough */ case CXL2_DOWNSTREAM_PORT: - init_cap_reg(RAS, 2, CXL_RAS_CAPABILITY_VERSION); - ras_init_common(reg_state, write_msk); + case CXL2_DEVICE: + /* RAS, Link */ + if (type !=3D CXL2_RC) { + init_cap_reg(RAS, 2, 2); + ras_init_common(reg_state, write_msk); + } + init_cap_reg(LINK, 4, 2); break; default: - break; + abort(); } =20 - init_cap_reg(LINK, 4, CXL_LINK_CAPABILITY_VERSION); - - if (caps < 3) { - return; - } - - if (type !=3D CXL2_ROOT_PORT) { - init_cap_reg(HDM, 5, CXL_HDM_CAPABILITY_VERSION); - hdm_init_common(reg_state, write_msk, type); - } - if (caps < 5) { - return; - } - - init_cap_reg(EXTSEC, 6, CXL_EXTSEC_CAP_VERSION); - init_cap_reg(SNOOP, 8, CXL_SNOOP_CAP_VERSION); - + ARRAY_FIELD_DP32(reg_state, CXL_CAPABILITY_HEADER, ARRAY_SIZE, caps); #undef init_cap_reg } =20 diff --git a/include/hw/cxl/cxl_component.h b/include/hw/cxl/cxl_component.h index b0f2aa7914..1f167d3ef7 100644 --- a/include/hw/cxl/cxl_component.h +++ b/include/hw/cxl/cxl_component.h @@ -32,10 +32,20 @@ enum reg_type { }; =20 /* - * Capability registers are defined at the top of the CXL.cache/mem region= and - * are packed. For our purposes we will always define the caps in the same - * order. - * CXL r3.1 Table 8-22: CXL_CAPABILITY_ID Assignment for details. + * CXL r3.2 - 8.2.4 Table 8-22 and 8-23 + * + * Capability registers are defined at the top of the CXL.cache/mem region. + * They are defined to be packed and at variable offsets. However, NULL + * capabilities can be added to the packed array. To facilitate easier ac= cess + * within the QEMU code, define these at specified offsets. Then NULL out= any + * capabilities for devices which don't (or can't) have a particular capab= ility + * (see cxl_component_register_init_common). NULL capabilities are to be + * ignored by software. + * + * 'offsets' are based on index's which can then be used to report the arr= ay + * size in CXL Capability Header Register (index/offset 0). + * + * See CXL r3.2 Table 8-25 for an example of allowing a 'NULL' header. */ =20 /* CXL r3.1 Section 8.2.4.1: CXL Capability Header Register */ @@ -46,16 +56,17 @@ REG32(CXL_CAPABILITY_HEADER, 0) FIELD(CXL_CAPABILITY_HEADER, CACHE_MEM_VERSION, 20, 4) FIELD(CXL_CAPABILITY_HEADER, ARRAY_SIZE, 24, 8) =20 -#define CXLx_CAPABILITY_HEADER(type, offset) \ - REG32(CXL_##type##_CAPABILITY_HEADER, offset) \ +#define CXLx_CAPABILITY_HEADER(type, idx) \ + enum { CXL_##type##_CAP_HDR_IDX =3D idx }; \ + REG32(CXL_##type##_CAPABILITY_HEADER, (idx * 0x4)) \ FIELD(CXL_##type##_CAPABILITY_HEADER, ID, 0, 16) \ FIELD(CXL_##type##_CAPABILITY_HEADER, VERSION, 16, 4) \ FIELD(CXL_##type##_CAPABILITY_HEADER, PTR, 20, 12) -CXLx_CAPABILITY_HEADER(RAS, 0x4) -CXLx_CAPABILITY_HEADER(LINK, 0x8) -CXLx_CAPABILITY_HEADER(HDM, 0xc) -CXLx_CAPABILITY_HEADER(EXTSEC, 0x10) -CXLx_CAPABILITY_HEADER(SNOOP, 0x14) +CXLx_CAPABILITY_HEADER(RAS, 1) +CXLx_CAPABILITY_HEADER(LINK, 2) +CXLx_CAPABILITY_HEADER(HDM, 3) +CXLx_CAPABILITY_HEADER(EXTSEC, 4) +CXLx_CAPABILITY_HEADER(SNOOP, 5) =20 /* * Capability structures contain the actual registers that the CXL compone= nt --=20 MST