From nobody Sun Feb 8 22:58:03 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1737184197; cv=none; d=zohomail.com; s=zohoarc; b=S0TAcqEJX8JpczbHbLRX12ob0tbAXryhtXmOo1jjy1hg0YqWYdw4+UKS+u59lwV2WOaRRQ+kReLs5nzMP8KnwPvNgQeJOf+cT/34ckMT/XqmVKZ4lDCOoHlCH1TKSpB3RatrhBAYoi10VFXqhwjtnea0VveDdB7q74BkQfWeyYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737184197; 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=/cx7Pxt/DNCLGhkMoyXvElc9TbIWqgkun0mAfcUqVZM=; b=SWJZnJj+XHxa/dplvUrVuB3q/IfOeRwqbd5+x9yIAlDsd9mNzUlNLM2U9TzOWKUIv9U1Jkh4l4+SFxQ4v+Kb7WTq6SYyCPY/sr12u5r6HREOuGTsEedUPuDkWW01yptJG2y2zL4cZXSqOZznM0rmGET9REh7b8HNQ76nU4IuaT8= 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 1737184197561273.09998752073136; Fri, 17 Jan 2025 23:09:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tZ2xS-0003Dc-PZ; Sat, 18 Jan 2025 02:09:27 -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 1tZ2xG-0003CP-Ru for qemu-devel@nongnu.org; Sat, 18 Jan 2025 02:09:17 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tZ2xE-0007oB-Qk for qemu-devel@nongnu.org; Sat, 18 Jan 2025 02:09:14 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2161eb94cceso35890205ad.2 for ; Fri, 17 Jan 2025 23:09:12 -0800 (PST) Received: from wheely.local0.net (124-169-212-233.tpgi.com.au. [124.169.212.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab9c95adsm3192880b3a.107.2025.01.17.23.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 23:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737184150; x=1737788950; 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=/cx7Pxt/DNCLGhkMoyXvElc9TbIWqgkun0mAfcUqVZM=; b=kiuHL/xee5wlwkfNvZbPWQB1y0NuwP9nwuQ08yScfdB4JOYcuoSTGn+fhLgr+YFh4s uJBbvBz0XbIlJDLDZeVelO4/ltbuldcFTPORVZPSZ6/O3pbygzcZ7Nu2UVD17BqZRvoT o2z70pTShwVVyvcV6oWWPGcuU1tyh8yF9fX+XmFSv+ucJ6WrkrFNTqvbiWJN/kiJwrWa SljWqIByAUOEiMNqKTbB9hBIgHkHr27CWZ5ARdoVG+j+NCnQ792unndnduPTeONAEUn0 2zNQlEJR5MxT+UMex/a8YmthoWmANoKHMvJCOi2KJa3uWU9xfTiyULmEIkCvkp5CbdeN zlIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737184150; x=1737788950; 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=/cx7Pxt/DNCLGhkMoyXvElc9TbIWqgkun0mAfcUqVZM=; b=U04OkVQhmEjuxCVJOQUAzRHK65Iuzs6eNf0GH9jHa+cfyGOmVFfnhuCBEv8zDCRL4T 6zUxlAY7Ip38sotZ0FndItFN6t9Q3d7x7dbUb/QKu7KHNEWPFGETunI+OWnq1ZdmlbK9 tLrklmhIcVbLB4OaRqByRtxo+6CeFTbc5qe/kAuNpI5j9jHb72rrac+HJlbXwGS0PyiK W8CrL+01qG6ufBRiWwRyF2vmL+jKKXYsEmZQg6KUjdLI3sIOfTSgqWSZZX/pCivRA+7L npZI39CRE2dR2Kmybd5pSA3VahIEmULFMiicNKn6vFypxBe0+D24Dsam4auwqvhK5/kF 2uig== X-Gm-Message-State: AOJu0Yy35Nrd5/aX7ct2Ipyld7+UuhW9t+C8J+In7wprDm3e+QgS+qn0 pg9GrmtCua4wqTIoM3WYdLC3YskeXvk7nTPAgjQxSLXY6Km1+7PfYLIo9g== X-Gm-Gg: ASbGncsJCPMR9mHavsenpHjnjWHaMWLsWzzU8wa2YlYRoCZUC8w/BSP9+DqZnfBWDfr UElV52NLDs1hX26KOx7Ic6L9iE3cfeUKcAEWfeMnR8rE+bZKqGWNvOyJ33dd5n0Id6zbnlfFVYU /Bfa3LJ9hjtIvwC5crgdiYsYHTKcy7hqltRGMnPJ1WL4ZipiFKI1Oxfkufkn/r7yzwzHYFFGCdh p1LmqjG4umFFCo+JQV9aZkfamccPNYyrGuGBwKycAUpqIs/nFsk9S3v+cIe6OJwHdSqDPhdTQWW J3UOGdZxq3ORGa9gzMx2xgKO1czN X-Google-Smtp-Source: AGHT+IFqOuidF1n+qV3hPTMWqVK5wrAuoYBjE8s6o6zAgBZpsRzpqVXTrXXYo5T7/G3RNeoWw0rybw== X-Received: by 2002:a05:6a21:164e:b0:1e0:d1c3:97d1 with SMTP id adf61e73a8af0-1eb215685b5mr10475199637.29.1737184150547; Fri, 17 Jan 2025 23:09:10 -0800 (PST) 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 Subject: [PATCH v2 2/8] hw/usb/xhci: Rename and move HCD register region constants to header Date: Sat, 18 Jan 2025 17:08:47 +1000 Message-ID: <20250118070853.653778-3-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250118070853.653778-1-npiggin@gmail.com> References: <20250118070853.653778-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::630; envelope-from=npiggin@gmail.com; helo=mail-pl1-x630.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: 1737184199680019000 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 bd1d8e8e81a..8557f59dafe 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 d21b0543957..76eb473c150 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 @@ -2582,7 +2574,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) @@ -2602,10 +2594,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 */ @@ -3255,22 +3247,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.45.2