From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, Bernhard Beschow <shentey@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Igor Mammedov" <imammedo@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Laurent Vivier" <lvivier@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 11/14] hw/southbridge/ich9: Add the SMBus function
Date: Mon, 19 Feb 2024 17:38:51 +0100 [thread overview]
Message-ID: <20240219163855.87326-12-philmd@linaro.org> (raw)
In-Reply-To: <20240219163855.87326-1-philmd@linaro.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é <philmd@linaro.org>
---
include/hw/southbridge/ich9.h | 32 --------------------------------
hw/i2c/smbus_ich9.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/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index 3980bca4c5..2c18278090 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.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 060358d449..7f6ced8a6e 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -236,6 +236,7 @@ static void pc_q35_init(MachineState *machine)
OBJECT(host_bus), &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);
/* irq lines */
@@ -309,15 +310,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(host_bus,
- 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 233dc1c5d7..4d2c298666 100644
--- a/hw/southbridge/ich9.c
+++ b/hw/southbridge/ich9.c
@@ -15,9 +15,11 @@
#include "hw/pci-bridge/ich_dmi_pci.h"
#include "hw/ide/ahci-pci.h"
#include "hw/ide.h"
+#include "hw/i2c/smbus_ich9.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(),
};
@@ -79,6 +84,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_init(Object *obj)
{
}
@@ -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
--
2.41.0
next prev parent reply other threads:[~2024-02-19 16:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 16:38 [PATCH 00/14] hw/southbridge: Extract ICH9 QOM container model Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 01/14] MAINTAINERS: Add 'ICH9 South Bridge' section Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 02/14] hw/i386/q35: Add local 'lpc_obj' variable Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 03/14] hw/acpi/ich9: Restrict definitions from 'hw/southbridge/ich9.h' Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 04/14] hw/acpi/ich9_tco: Include 'ich9' in names Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 05/14] hw/acpi/ich9_tco: Restrict ich9_generate_smi() declaration Philippe Mathieu-Daudé
2024-02-20 6:32 ` Philippe Mathieu-Daudé
2024-02-26 9:53 ` Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 06/14] hw/pci-bridge: Extract QOM ICH definitions to 'ich_dmi_pci.h' Philippe Mathieu-Daudé
2024-02-19 18:15 ` BALATON Zoltan
2024-02-19 18:24 ` BALATON Zoltan
2024-02-20 6:09 ` Philippe Mathieu-Daudé
2024-02-20 12:20 ` BALATON Zoltan
2024-02-20 12:55 ` Thomas Huth
2024-02-26 13:46 ` Philippe Mathieu-Daudé
2024-02-26 13:56 ` BALATON Zoltan
2024-02-20 19:25 ` Bernhard Beschow
2024-02-21 8:54 ` Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 07/14] hw/southbridge/ich9: Introduce TYPE_ICH9_SOUTHBRIDGE stub Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 08/14] hw/southbridge/ich9: Add the DMI-to-PCI bridge Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 09/14] hw/southbridge/ich9: Add a AHCI function Philippe Mathieu-Daudé
2024-02-19 18:31 ` BALATON Zoltan
2024-02-20 6:01 ` Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 10/14] hw/i2c/smbus: Extract QOM ICH9 definitions to 'smbus_ich9.h' Philippe Mathieu-Daudé
2024-02-19 16:38 ` Philippe Mathieu-Daudé [this message]
2024-02-19 16:38 ` [PATCH 12/14] hw/southbridge/ich9: Add the USB EHCI/UHCI functions Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 13/14] hw/southbridge/ich9: Extract LPC definitions to 'hw/isa/ich9_lpc.h' Philippe Mathieu-Daudé
2024-02-19 16:38 ` [PATCH 14/14] hw/southbridge/ich9: Add the LPC / ISA bridge function Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240219163855.87326-12-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=anisinha@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=shentey@gmail.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).