From nobody Fri Dec 19 20:13:15 2025 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1744358411; cv=none; d=zohomail.com; s=zohoarc; b=Kv0PUcrUx9bv6+9eFqnaHIwX11txs0CkX0ClMHqMpRaf6xGE2KKgioZigeVOT+3VxFFZKkc8xozDilRgWiR0pnEzQj5rb5yt/dS+f6suSo3D+oBt18VauxWV7j1gciKipGniPESLHT80zj9dhPyXWOuT6UmEyrgM4iVdW3ZB+9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744358411; h=Content-Transfer-Encoding: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=pW3ktPWxZ3GftuE1xtPzSwx/ntzRqF0mx0dzBHfFB40=; b=bFAr4doBCQyljVWdkj23XJv78CwEfBshAkjOaxUg+ms8wBiiXRoJa5pjd8IGI6gkwP+Bp9arhMoat/IuvsDZvQ46+Ad02REsVIzk7u39adoTWlwl4XI/63rRj4oNaP1CV9mVFd+LdKRWgbaj7+PDXCF5ieCxOkEppGnTmNZAv7U= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744358411042624.7941959040331; Fri, 11 Apr 2025 01:00:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u39IB-0002AN-AB; Fri, 11 Apr 2025 03:59:15 -0400 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 1u39I8-00028A-Pe for qemu-devel@nongnu.org; Fri, 11 Apr 2025 03:59:12 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u39I6-0003rP-Rf for qemu-devel@nongnu.org; Fri, 11 Apr 2025 03:59:12 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-736c277331eso2667343b3a.1 for ; Fri, 11 Apr 2025 00:59:10 -0700 (PDT) Received: from wheely.local0.net ([220.253.99.94]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73bd233554asm851687b3a.180.2025.04.11.00.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Apr 2025 00:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744358349; x=1744963149; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pW3ktPWxZ3GftuE1xtPzSwx/ntzRqF0mx0dzBHfFB40=; b=CZ1A+8h4sBqlDdEggoCg+6P6NwNb54P+tNha+iuc6Xd14p0YgH2gIeS3iNa0PtVx+v GPhfBljCkEHAsV+8IKtFBKgiwByrJ7Tnb14GOtIdLciPh1xGyVyHPDzT5LUqE1X1KUHO yCKZuWHl57Ta7Qg49HNez7VkXl6e2RfUgx546sVQMTJk55YMkOrQsMRtnFDlmxCxq+Xt hZ9NVi/F7XJPifnKrVWd6sijUZPq7bKL1lvBSGCZJ9TjIpCD0uV8UzAYcw4MdtRB/+Ak yI6vvMdNrN7BJl3sJGHFtmMKXgJdYsQMBH5wewpkFkgWg9Yc9zBxgmPnXlXCkwHrMkCG FM1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744358349; x=1744963149; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pW3ktPWxZ3GftuE1xtPzSwx/ntzRqF0mx0dzBHfFB40=; b=tsr//i8repCNs3cGHIDMDiGPCar+uzAyJBd/wM09UO2YStJsjxMzR2tQOi9g+Ni5Ld Flx/cfiziegzwTsNp/5QizrpeX+4MFA9Nw+jb3cYgn5pSnFCb2T4wp+3StAyOvqvBwEj 0SBU+cIadFQw0qPwXLcU/qmer5wckG/konKajfPEv/a0B/z2FQiGUU3i7vf6Oz7sxqcd LQTxm4KhCe2a3Wf8zjvdw9VtILdk3ndXmo2jjQhlqQJwmDQmdjZ8GtKyRM0ARZE57dpD 592s0QPDYBB/FhFRTb6wGkx5fa8JHbvoIRMMZURO7d27TFueGA+RPUhtr3q38g6dysq3 kPAg== X-Gm-Message-State: AOJu0YwO0gZvVuwA0u4AijZIwRIQ5Etr8nFCvEWrTw58SOnSCW1kqrhJ ulrX10A3vLRycIMPNVbvifBBJM28IrlyVCp5cuw0hz33V9rbGMJnYSNbKg== X-Gm-Gg: ASbGncvKy5pgvN5y25eC7dsz+MdFMyZUE5mdeR8JUXSCW7gVDG4Uz3uSiXeCuHYH87I eEpGL6C8qM1YIhOE2W4Zrw+a0BO23CXNTWVwXrud6gQrkJ8UVwcrstcOygOPdJqevgBREP5QnFb 9ToWlik+FSMTZsKhpreJoavayd8vEHilTZNji1hZdYAfEkGwKo2hGbZXUFbK5u9IBmLLPFQSZkT 7uvCHDf9X2VFs1usrFH4vHdqs/TLUgFkU1/fpkR1/nQoijEzeqoFBP3wNr7gmqKA3bVSZIXygRM yzzQLkoHMzlkkaSrOVMGtn98a6+y3mOLW5dkwaJbNPK+ X-Google-Smtp-Source: AGHT+IGe8PaniikNDMyJPhg50DEA+DDeMQu3i5vDDgiFRIsx0ALrlf6Eu4QIkvc8XnAuqNoCcoWSdA== X-Received: by 2002:a05:6a00:98b:b0:736:5969:2b6f with SMTP id d2e1a72fcca58-73bd0c23517mr2875750b3a.6.1744358349087; Fri, 11 Apr 2025 00:59:09 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Paolo Bonzini , "Michael S. Tsirkin" , Marcel Apfelbaum , Fabiano Rosas , Laurent Vivier , Phil Dennis-Jordan , Bernhard Beschow Subject: [PATCH v3 2/8] hw/usb/xhci: Rename and move HCD register region constants to header Date: Fri, 11 Apr 2025 17:58:44 +1000 Message-ID: <20250411075851.206995-3-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250411075851.206995-1-npiggin@gmail.com> References: <20250411075851.206995-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::434; envelope-from=npiggin@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @gmail.com) X-ZM-MESSAGEID: 1744358413955019100 Content-Type: text/plain; charset="utf-8" This also adds some missing constants rather than open-coding offsets and sizes. Signed-off-by: Nicholas Piggin --- hw/usb/hcd-xhci.h | 16 ++++++++++++++++ hw/usb/hcd-xhci.c | 48 ++++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h index ee364efd0ab..20059fcf66c 100644 --- a/hw/usb/hcd-xhci.h +++ b/hw/usb/hcd-xhci.h @@ -115,6 +115,22 @@ typedef enum TRBCCode { CC_SPLIT_TRANSACTION_ERROR } TRBCCode; =20 +/* Register regions */ +#define XHCI_REGS_LENGTH_CAP 0x40 +#define XHCI_REGS_LENGTH_OPER 0x400 +#define XHCI_REGS_LENGTH_PORT (XHCI_PORT_PR_SZ * XHCI_MAXPORTS) +#define XHCI_REGS_LENGTH_RUNTIME ((XHCI_MAXINTRS + 1) * XHCI_INTR_IR_S= Z) +/* XXX: Should doorbell length be *4 rather than *32? */ +#define XHCI_REGS_LENGTH_DOORBELL ((XHCI_MAXSLOTS + 1) * 0x20) + +#define XHCI_REGS_OFFSET_CAP 0 +#define XHCI_REGS_OFFSET_OPER (XHCI_REGS_OFFSET_CAP + \ + XHCI_REGS_LENGTH_CAP) +#define XHCI_REGS_OFFSET_PORT (XHCI_REGS_OFFSET_OPER + \ + XHCI_REGS_LENGTH_OPER) +#define XHCI_REGS_OFFSET_RUNTIME 0x1000 +#define XHCI_REGS_OFFSET_DOORBELL 0x2000 + /* Register definitions */ #define XHCI_HCCAP_REG_CAPLENGTH 0x00 #define XHCI_HCCAP_REG_HCIVERSION 0x02 diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index b57db309b8d..7470db38561 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -46,22 +46,14 @@ #define COMMAND_LIMIT 256 #define TRANSFER_LIMIT 256 =20 -#define LEN_CAP 0x40 -#define LEN_OPER (0x400 + XHCI_PORT_PR_SZ * XHCI_MAXPORTS) -#define LEN_RUNTIME ((XHCI_MAXINTRS + 1) * XHCI_INTR_IR_SZ) -#define LEN_DOORBELL ((XHCI_MAXSLOTS + 1) * 0x20) - -#define OFF_OPER LEN_CAP -#define OFF_RUNTIME 0x1000 -#define OFF_DOORBELL 0x2000 - -#if (OFF_OPER + LEN_OPER) > OFF_RUNTIME -#error Increase OFF_RUNTIME +#if (XHCI_REGS_OFFSET_PORT + XHCI_REGS_LENGTH_PORT) > XHCI_REGS_OFFSET_RUN= TIME +#error Increase XHCI_REGS_OFFSET_RUNTIME #endif -#if (OFF_RUNTIME + LEN_RUNTIME) > OFF_DOORBELL -#error Increase OFF_DOORBELL +#if (XHCI_REGS_OFFSET_RUNTIME + XHCI_REGS_LENGTH_RUNTIME) > \ + XHCI_REGS_OFFSET_DOORBELL +#error Increase XHCI_REGS_OFFSET_DOORBELL #endif -#if (OFF_DOORBELL + LEN_DOORBELL) > XHCI_LEN_REGS +#if (XHCI_REGS_OFFSET_DOORBELL + XHCI_REGS_LENGTH_DOORBELL) > XHCI_LEN_REGS # error Increase XHCI_LEN_REGS #endif =20 @@ -2583,7 +2575,7 @@ static uint64_t xhci_cap_read(void *ptr, hwaddr reg, = unsigned size) =20 switch (reg) { case XHCI_HCCAP_REG_CAPLENGTH: /* Covers HCIVERSION and CAPLENGTH */ - ret =3D 0x01000000 | LEN_CAP; + ret =3D 0x01000000 | XHCI_REGS_LENGTH_CAP; break; case XHCI_HCCAP_REG_HCSPARAMS1: ret =3D ((xhci->numports_2+xhci->numports_3)<<24) @@ -2603,10 +2595,10 @@ static uint64_t xhci_cap_read(void *ptr, hwaddr reg= , unsigned size) } break; case XHCI_HCCAP_REG_DBOFF: - ret =3D OFF_DOORBELL; + ret =3D XHCI_REGS_OFFSET_DOORBELL; break; case XHCI_HCCAP_REG_RTSOFF: - ret =3D OFF_RUNTIME; + ret =3D XHCI_REGS_OFFSET_RUNTIME; break; =20 /* extended capabilities */ @@ -3256,22 +3248,26 @@ static void usb_xhci_realize(DeviceState *dev, Erro= r **errp) =20 memory_region_init(&xhci->mem, OBJECT(dev), "xhci", XHCI_LEN_REGS); memory_region_init_io(&xhci->mem_cap, OBJECT(dev), &xhci_cap_ops, xhci, - "capabilities", LEN_CAP); + "capabilities", XHCI_REGS_LENGTH_CAP); memory_region_init_io(&xhci->mem_oper, OBJECT(dev), &xhci_oper_ops, xh= ci, - "operational", 0x400); + "operational", XHCI_REGS_LENGTH_OPER); memory_region_init_io(&xhci->mem_runtime, OBJECT(dev), &xhci_runtime_o= ps, - xhci, "runtime", LEN_RUNTIME); + xhci, "runtime", XHCI_REGS_LENGTH_RUNTIME); memory_region_init_io(&xhci->mem_doorbell, OBJECT(dev), &xhci_doorbell= _ops, - xhci, "doorbell", LEN_DOORBELL); + xhci, "doorbell", XHCI_REGS_LENGTH_DOORBELL); =20 - memory_region_add_subregion(&xhci->mem, 0, &xhci->mem_cap); - memory_region_add_subregion(&xhci->mem, OFF_OPER, &xhci->mem_oper); - memory_region_add_subregion(&xhci->mem, OFF_RUNTIME, &xhci->mem_runti= me); - memory_region_add_subregion(&xhci->mem, OFF_DOORBELL, &xhci->mem_doorb= ell); + memory_region_add_subregion(&xhci->mem, XHCI_REGS_OFFSET_CAP, + &xhci->mem_cap); + memory_region_add_subregion(&xhci->mem, XHCI_REGS_OFFSET_OPER, + &xhci->mem_oper); + memory_region_add_subregion(&xhci->mem, XHCI_REGS_OFFSET_RUNTIME, + &xhci->mem_runtime); + memory_region_add_subregion(&xhci->mem, XHCI_REGS_OFFSET_DOORBELL, + &xhci->mem_doorbell); =20 for (i =3D 0; i < xhci->numports; i++) { XHCIPort *port =3D &xhci->ports[i]; - uint32_t offset =3D OFF_OPER + 0x400 + XHCI_PORT_PR_SZ * i; + uint32_t offset =3D XHCI_REGS_OFFSET_PORT + XHCI_PORT_PR_SZ * i; port->xhci =3D xhci; memory_region_init_io(&port->mem, OBJECT(dev), &xhci_port_ops, por= t, port->name, XHCI_PORT_PR_SZ); --=20 2.47.1