From patchwork Mon Feb 26 11:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 775855 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp272232wrt; Mon, 26 Feb 2024 03:16:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVKTy24rNzyfo/mGpYyYxbbrV3C1Y2MGHSHOZP41iiyZsi0H7+ykbig718+ZYoQw4QsLazLkXm6evQoENiEO9Ub X-Google-Smtp-Source: AGHT+IF8WsYOF497kGfJjTAiZWxT4HGb1AuQMpEtPcuDRikUJBTbGo/xiyGcDzO1Su5zgWN3UgKg X-Received: by 2002:a05:6808:648e:b0:3c1:a943:871 with SMTP id fh14-20020a056808648e00b003c1a9430871mr392530oib.19.1708946174162; Mon, 26 Feb 2024 03:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708946174; cv=none; d=google.com; s=arc-20160816; b=ZYMuG8nSsx5xb5p9w1FwmVEK9ou8H5tquskCbBkxFAtQmSAuDw2lMLEFenpd/E6b0w 356ND1kadLlwyybJMSDhLLvfJJ6Huzh9QI85SBzREYOYdO/rjsf2a/XTU3K26uAfXXQT 7X8ZXd2bgHJzvRMI8800F3gmHIpjU6ANEPZF4Z73AMiGrti9lvI9p9N2K3pYFvsjelMp eK/C8KM71GSy6JvKjahLDTu3uM28TKE3roXS3wTXI/i/KLkRFCNNUpgAhFEKf1xSYERy /mqhJRXqqTQlK0A7IJX6JVZf5OrYXEpfit4UqDwdCSEqgk3lQEHFm/oOKecAYCSwNm27 qo6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s983EWlXUw8CoLKGoGbnyYE6HyzW/fgxYhU+WY62/gc=; fh=j4MxUKsQnom9H3Srwq13mMegTaYVxToeDvl/PNa+M5c=; b=BlSVtIH1PPOhegQGBSLmcsdWLomVZv7UG9FRGDS8PScXadNSdxVzmDwsE64qHnFBow 3sFqIwYY3INO3A2V414hDqqVpTvZZ2ttLo7UV/Z+Ae3wBxJIXNb2l5aqR1jSKDgVtwg7 d7ybweDq1FR2hSaiKMa9S3XswkRjvKNtyHTOfHgrjihAPuBvJarpCJT4/2RShibBITfn E5vq0R3Cd+39lC7pfVVX1Fa245t7zBs+S75QsWK/uG1hQ4iDuCCc9rS5KMLuwvx/wWqL l3SUV7srHBYfxlgEdBnMjretaswxuJcbViqaXxYOY3IgSwz9SzPbHNjnoZXeJWq6XhnC ARHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VaVQOcMv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w10-20020ac8718a000000b0042e7f2d4bf8si2566270qto.163.2024.02.26.03.16.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 03:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VaVQOcMv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reYxZ-0002hW-CE; Mon, 26 Feb 2024 06:15:53 -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 1reYxO-0002Cw-2L for qemu-devel@nongnu.org; Mon, 26 Feb 2024 06:15:38 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reYxL-0000NK-G8 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 06:15:37 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33d8d5165dbso1618050f8f.1 for ; Mon, 26 Feb 2024 03:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708946133; x=1709550933; 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=s983EWlXUw8CoLKGoGbnyYE6HyzW/fgxYhU+WY62/gc=; b=VaVQOcMvpdqLAioMyxVOjZzlBoFZeDex+ghTwq36g3NxlCuvP1q0ledzeF4QFGE462 ChrgE28ixs/VDC5G3eIU9sVUJYIz132Bm3xJkYdfxg54dY1QcIvZpMcJ/+bAZEkHvR12 OHMj3F+NjqYGgqqbafy675vT/WKm3pxeHhGdclc+xLh4iOrlH6hT+VY0Vm7S0zQFUDsA 9XZsacnjaVRbaXcljSRg3D+8/aVlRU8+EXlYAHcp2aD0S8rhPcvqmi5RjCIy6PdI3rIB 2mXCyagp02niX6X594Cvr88aC94pE3xAYGs/1vQfxpJEasyoNtXTKrXyLRBaJpw08d+5 4bEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708946133; x=1709550933; 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=s983EWlXUw8CoLKGoGbnyYE6HyzW/fgxYhU+WY62/gc=; b=OvtFqUv/hc3kSLbTfZnBwqrkpvWcgFBrOI9jay8AiDp+wzTZxN04F2YwbwBwaVDlkC Kq2qdiaDTzsII9HlA8scRI+Gk5wZXcoZ7TuCaaOvH+0wsHP3vTFID8bo41A45ZEylwUx 2u1vWKb36QM57pCNLnZyQcDoQB8DSP3Iwhd1CGo6wdn2WKPYrHRWOVHTQexNI1I1OSeP KJIB9dTeVRSk4U17fK1n9A7woWet5s1jEiQyxmkRnhOgBDJ1fXhtMunX0rJHF2OZc5pG xlfeuemGnmSUjLrkaPZcX7TxJ62gfkFnf7ejpJvAYLFWMmO7AAQtkN1yYoTBPhc7Y+vX 7glg== X-Gm-Message-State: AOJu0YxwqbURTavsLu6pnHCAy5O3TpIV7qvh6d3AheOO+J8gdp2E9Sg2 dhybW3TU0WSWFyP0IBJeexpPnskkRd9tVmgK+JCi17Am7zZ8eK5UulaUxXBEYJyTBleXBqLhuaL F X-Received: by 2002:adf:f350:0:b0:33d:855d:7457 with SMTP id e16-20020adff350000000b0033d855d7457mr4649165wrp.21.1708946133496; Mon, 26 Feb 2024 03:15:33 -0800 (PST) Received: from m1x-phil.lan ([176.176.164.69]) by smtp.gmail.com with ESMTPSA id g10-20020adfd1ea000000b0033d282c7537sm8202395wrd.23.2024.02.26.03.15.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 03:15:33 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Bernhard Beschow Cc: Laurent Vivier , Thomas Huth , BALATON Zoltan , Ani Sinha , qemu-block@nongnu.org, Marcel Apfelbaum , Eduardo Habkost , John Snow , Paolo Bonzini , "Michael S. Tsirkin" , Igor Mammedov , Richard Henderson , Mark Cave-Ayland , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PATCH v2 12/15] hw/southbridge/ich9: Add the SMBus function Date: Mon, 26 Feb 2024 12:14:11 +0100 Message-ID: <20240226111416.39217-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240226111416.39217-1-philmd@linaro.org> References: <20240226111416.39217-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Instantiate TYPE_ICH9_SMB_DEVICE in TYPE_ICH9_SOUTHBRIDGE. Since the PC machines can disable SMBus (see the PC_MACHINE_SMBUS dynamic property), add the 'smbus-enabled' property to disable it. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/southbridge/ich9.h | 32 -------------------------------- hw/i2c/ich9_smbus.c | 29 ++++++++++++++++++++++++++++- hw/i386/pc_q35.c | 10 ++-------- hw/southbridge/ich9.c | 21 +++++++++++++++++++++ hw/southbridge/Kconfig | 1 + 5 files changed, 52 insertions(+), 41 deletions(-) diff --git a/include/hw/southbridge/ich9.h b/include/hw/southbridge/ich9.h index ac7f9f4ff5..d4b299bf3c 100644 --- a/include/hw/southbridge/ich9.h +++ b/include/hw/southbridge/ich9.h @@ -173,38 +173,6 @@ struct ICH9LPCState { #define ICH9_APM_ACPI_ENABLE 0x2 #define ICH9_APM_ACPI_DISABLE 0x3 - -/* D31:F3 SMBus controller */ -#define TYPE_ICH9_SMB_DEVICE "ICH9-SMB" - -#define ICH9_A2_SMB_REVISION 0x02 -#define ICH9_SMB_PI 0x00 - -#define ICH9_SMB_SMBMBAR0 0x10 -#define ICH9_SMB_SMBMBAR1 0x14 -#define ICH9_SMB_SMBM_BAR 0 -#define ICH9_SMB_SMBM_SIZE (1 << 8) -#define ICH9_SMB_SMB_BASE 0x20 -#define ICH9_SMB_SMB_BASE_BAR 4 -#define ICH9_SMB_SMB_BASE_SIZE (1 << 5) -#define ICH9_SMB_HOSTC 0x40 -#define ICH9_SMB_HOSTC_SSRESET ((uint8_t)(1 << 3)) -#define ICH9_SMB_HOSTC_I2C_EN ((uint8_t)(1 << 2)) -#define ICH9_SMB_HOSTC_SMB_SMI_EN ((uint8_t)(1 << 1)) -#define ICH9_SMB_HOSTC_HST_EN ((uint8_t)(1 << 0)) - -/* D31:F3 SMBus I/O and memory mapped I/O registers */ -#define ICH9_SMB_DEV 31 -#define ICH9_SMB_FUNC 3 - -#define ICH9_SMB_HST_STS 0x00 -#define ICH9_SMB_HST_CNT 0x02 -#define ICH9_SMB_HST_CMD 0x03 -#define ICH9_SMB_XMIT_SLVA 0x04 -#define ICH9_SMB_HST_D0 0x05 -#define ICH9_SMB_HST_D1 0x06 -#define ICH9_SMB_HOST_BLOCK_DB 0x07 - #define ICH9_LPC_SMI_NEGOTIATED_FEAT_PROP "x-smi-negotiated-features" /* bit positions used in fw_cfg SMI feature negotiation */ diff --git a/hw/i2c/ich9_smbus.c b/hw/i2c/ich9_smbus.c index 35f526d71c..1c3b9964de 100644 --- a/hw/i2c/ich9_smbus.c +++ b/hw/i2c/ich9_smbus.c @@ -26,10 +26,37 @@ #include "migration/vmstate.h" #include "qemu/module.h" -#include "hw/southbridge/ich9.h" #include "qom/object.h" #include "hw/acpi/acpi_aml_interface.h" +/* D31:F3 SMBus controller */ + +#define ICH9_A2_SMB_REVISION 0x02 +#define ICH9_SMB_PI 0x00 + +#define ICH9_SMB_SMBMBAR0 0x10 +#define ICH9_SMB_SMBMBAR1 0x14 +#define ICH9_SMB_SMBM_BAR 0 +#define ICH9_SMB_SMBM_SIZE (1 << 8) +#define ICH9_SMB_SMB_BASE 0x20 +#define ICH9_SMB_SMB_BASE_BAR 4 +#define ICH9_SMB_SMB_BASE_SIZE (1 << 5) +#define ICH9_SMB_HOSTC 0x40 +#define ICH9_SMB_HOSTC_SSRESET ((uint8_t)(1 << 3)) +#define ICH9_SMB_HOSTC_I2C_EN ((uint8_t)(1 << 2)) +#define ICH9_SMB_HOSTC_SMB_SMI_EN ((uint8_t)(1 << 1)) +#define ICH9_SMB_HOSTC_HST_EN ((uint8_t)(1 << 0)) + +/* D31:F3 SMBus I/O and memory mapped I/O registers */ + +#define ICH9_SMB_HST_STS 0x00 +#define ICH9_SMB_HST_CNT 0x02 +#define ICH9_SMB_HST_CMD 0x03 +#define ICH9_SMB_XMIT_SLVA 0x04 +#define ICH9_SMB_HST_D0 0x05 +#define ICH9_SMB_HST_D1 0x06 +#define ICH9_SMB_HOST_BLOCK_DB 0x07 + static bool ich9_vmstate_need_smbus(void *opaque, int version_id) { return pm_smbus_vmstate_needed(); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 6903719b97..0ff94b7afd 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -224,6 +224,7 @@ static void pc_q35_init(MachineState *machine) OBJECT(pcms->pcibus), &error_abort); qdev_prop_set_bit(ich9, "d2p-enabled", false); qdev_prop_set_bit(ich9, "sata-enabled", pcms->sata_enabled); + qdev_prop_set_bit(ich9, "smbus-enabled", pcms->smbus_enabled); qdev_realize_and_unref(ich9, NULL, &error_fatal); /* create ISA bus */ @@ -294,15 +295,8 @@ static void pc_q35_init(MachineState *machine) } if (pcms->smbus_enabled) { - PCIDevice *smb; - + pcms->smbus = I2C_BUS(qdev_get_child_bus(ich9, "i2c")); /* TODO: Populate SPD eeprom data. */ - smb = pci_create_simple_multifunction(pcms->pcibus, - PCI_DEVFN(ICH9_SMB_DEV, - ICH9_SMB_FUNC), - TYPE_ICH9_SMB_DEVICE); - pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(smb), "i2c")); - smbus_eeprom_init(pcms->smbus, 8, NULL, 0); } diff --git a/hw/southbridge/ich9.c b/hw/southbridge/ich9.c index 37255bb941..413e9187e4 100644 --- a/hw/southbridge/ich9.c +++ b/hw/southbridge/ich9.c @@ -15,9 +15,11 @@ #include "hw/pci-bridge/ich9_dmi.h" #include "hw/ide/ahci-pci.h" #include "hw/ide/ide-dev.h" +#include "hw/i2c/ich9_smbus.h" #define ICH9_D2P_DEVFN PCI_DEVFN(30, 0) #define ICH9_SATA1_DEVFN PCI_DEVFN(31, 2) +#define ICH9_SMB_DEVFN PCI_DEVFN(31, 3) #define SATA_PORTS 6 @@ -26,10 +28,12 @@ struct ICH9State { I82801b11Bridge d2p; AHCIPCIState sata0; + ICH9SMBState smb; PCIBus *pci_bus; bool d2p_enabled; bool sata_enabled; + bool smbus_enabled; }; static Property ich9_props[] = { @@ -37,6 +41,7 @@ static Property ich9_props[] = { TYPE_PCIE_BUS, PCIBus *), DEFINE_PROP_BOOL("d2p-enabled", ICH9State, d2p_enabled, true), DEFINE_PROP_BOOL("sata-enabled", ICH9State, sata_enabled, true), + DEFINE_PROP_BOOL("smbus-enabled", ICH9State, smbus_enabled, true), DEFINE_PROP_END_OF_LIST(), }; @@ -83,6 +88,18 @@ static bool ich9_realize_sata(ICH9State *s, Error **errp) return true; } +static bool ich9_realize_smbus(ICH9State *s, Error **errp) +{ + object_initialize_child(OBJECT(s), "smb", &s->smb, TYPE_ICH9_SMB_DEVICE); + qdev_prop_set_int32(DEVICE(&s->smb), "addr", ICH9_SMB_DEVFN); + if (!qdev_realize(DEVICE(&s->smb), BUS(s->pci_bus), errp)) { + return false; + } + object_property_add_alias(OBJECT(s), "i2c", OBJECT(&s->smb), "i2c"); + + return true; +} + static void ich9_realize(DeviceState *dev, Error **errp) { ICH9State *s = ICH9_SOUTHBRIDGE(dev); @@ -99,6 +116,10 @@ static void ich9_realize(DeviceState *dev, Error **errp) if (s->sata_enabled && !ich9_realize_sata(s, errp)) { return; } + + if (s->smbus_enabled && !ich9_realize_smbus(s, errp)) { + return; + } } static void ich9_class_init(ObjectClass *klass, void *data) diff --git a/hw/southbridge/Kconfig b/hw/southbridge/Kconfig index f806033d48..03e89a55d1 100644 --- a/hw/southbridge/Kconfig +++ b/hw/southbridge/Kconfig @@ -5,3 +5,4 @@ config ICH9 depends on PCI_EXPRESS imply I82801B11 select AHCI_ICH9 + select ACPI_ICH9