qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: Huacai Chen <chenhuacai@kernel.org>,
	qemu-devel@nongnu.org, f4bug@amsat.org
Subject: Re: [PATCH v2 03/13] vt82c686: Fix SMBus IO base and configuration registers
Date: Wed, 13 Jan 2021 10:24:53 +0800	[thread overview]
Message-ID: <d1a185bc-7b55-0389-a67c-2ed941293b51@flygoat.com> (raw)
In-Reply-To: <998ba27e-5d97-1456-a9ef-37e73ed4dc9a@eik.bme.hu>

在 2021/1/13 上午6:25, BALATON Zoltan 写道:
> On Tue, 12 Jan 2021, Jiaxun Yang wrote:
>> 在 2021/1/10 上午4:16, BALATON Zoltan 写道:
>>> The base address of the SMBus io ports and its enabled status is set
>>> by registers in the PCI config space but this was not correctly
>>> emulated. Instead the SMBus registers were mapped on realize to the
>>> base address set by a property to the address expected by fuloong2e
>>> firmware.
>>>
>>> Fix the base and config register handling to more closely model
>>> hardware which allows to remove the property and allows the guest to
>>> control this mapping. Do all this in reset instead of realize so it's
>>> correctly updated on reset.
>>
>> Hi,
>>
>> Thanks for your patch!
>>
>>>
>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>> ---
>>>   hw/isa/vt82c686.c   | 49 
>>> +++++++++++++++++++++++++++++++++------------
>>>   hw/mips/fuloong2e.c |  4 +---
>>>   2 files changed, 37 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
>>> index fe8961b057..9c4d153022 100644
>>> --- a/hw/isa/vt82c686.c
>>> +++ b/hw/isa/vt82c686.c
>>> @@ -22,6 +22,7 @@
>>>   #include "hw/i2c/pm_smbus.h"
>>>   #include "qapi/error.h"
>>>   #include "qemu/module.h"
>>> +#include "qemu/range.h"
>>>   #include "qemu/timer.h"
>>>   #include "exec/address-spaces.h"
>>>   #include "trace.h"
>>> @@ -34,7 +35,6 @@ struct VT686PMState {
>>>       ACPIREGS ar;
>>>       APMState apm;
>>>       PMSMBus smb;
>>> -    uint32_t smb_io_base;
>>>   };
>>>     static void pm_io_space_update(VT686PMState *s)
>>> @@ -50,11 +50,22 @@ static void pm_io_space_update(VT686PMState *s)
>>>       memory_region_transaction_commit();
>>>   }
>>>   +static void smb_io_space_update(VT686PMState *s)
>>> +{
>>> +    uint32_t smbase = pci_get_long(s->dev.config + 0x90) & 0xfff0UL;
>>> +
>>> +    memory_region_transaction_begin();
>>> +    memory_region_set_address(&s->smb.io, smbase);
>>> +    memory_region_set_enabled(&s->smb.io, s->dev.config[0xd2] & 
>>> BIT(0));
>>> +    memory_region_transaction_commit();
>>> +}
>>> +
>>>   static int vmstate_acpi_post_load(void *opaque, int version_id)
>>>   {
>>>       VT686PMState *s = opaque;
>>>         pm_io_space_update(s);
>>> +    smb_io_space_update(s);
>>>       return 0;
>>>   }
>>>   @@ -77,8 +88,18 @@ static const VMStateDescription vmstate_acpi = {
>>>     static void pm_write_config(PCIDevice *d, uint32_t addr, 
>>> uint32_t val, int len)
>>>   {
>>> +    VT686PMState *s = VT82C686B_PM(d);
>>> +
>>>       trace_via_pm_write(addr, val, len);
>>>       pci_default_write_config(d, addr, val, len);
>>> +    if (ranges_overlap(addr, len, 0x90, 4)) {
>>> +        uint32_t v = pci_get_long(s->dev.config + 0x90);
>>> +        pci_set_long(s->dev.config + 0x90, (v & 0xfff0UL) | 1);
>>
>> What does this "or 1" do?
>> The datasheet I found only mentioned the default value of BASE is 
>> 0000 0001
>> but didn't say anything about it's function :-/
>
> It says that in the summary table but later in data sheet there's also 
> detailed description of registers for each part where it says:
>
> Offset 93-90 – SMBus I/O Base ... RW
> 3-0 Fixed ... always reads 0001b
>
> The above mask and | 1 ensures this. I don't know why lowest bit is 
> always 1 but that seems to be the case for all such regs. Maybe 
> internally these are implemented like PCI BARs where lowest bit means 
> IO space.

Thanks!

In this case:

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

>
>>> +    }
>>> +    if (range_covers_byte(addr, len, 0xd2)) {
>>> +        s->dev.config[0xd2] &= 0xf;
>>> +        smb_io_space_update(s);
>>> +    }
>>>   }
>>>     static void pm_update_sci(VT686PMState *s)
>>> @@ -103,6 +124,17 @@ static void pm_tmr_timer(ACPIREGS *ar)
>>>       pm_update_sci(s);
>>>   }
>>>   +static void vt82c686b_pm_reset(DeviceState *d)
>>> +{
>>> +    VT686PMState *s = VT82C686B_PM(d);
>>> +
>>> +    /* SMBus IO base */
>>> +    pci_set_long(s->dev.config + 0x90, 1);
>>
>> Theoretically this kind of magic number should be avoided but
>> as the rest of the file was written in such style it seems fine for me.
>
> I could add defines for register offsets but did not think that would 
> make it much more readable to have random names instead of random 
> numbers. Likely you'll have to consult the data sheet to find out 
> their meaning anyway.

Agreed.

- Jiaxun

>
> Regards,
> BALATON Zoltan



  reply	other threads:[~2021-01-13  2:26 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-09 20:16 [PATCH v2 00/13] vt82c686b clean ups and vt8231 emulation BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 08/13] vt82c686: Move creation of ISA devices to the ISA bridge BALATON Zoltan
2021-01-10  0:21   ` Philippe Mathieu-Daudé
2021-01-10  0:43     ` BALATON Zoltan
2021-01-10 11:34       ` Philippe Mathieu-Daudé
2021-01-10 19:25         ` BALATON Zoltan
2021-01-11  1:38           ` Jiaxun Yang
2021-01-11 10:28             ` BALATON Zoltan
2021-01-25 17:57               ` Philippe Mathieu-Daudé
2021-02-01 20:04           ` BALATON Zoltan
2021-02-04 12:35             ` Jiaxun Yang
2021-02-04 13:10               ` BALATON Zoltan
2021-02-09 16:55             ` BALATON Zoltan
2021-02-17 20:36               ` BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 03/13] vt82c686: Fix SMBus IO base and configuration registers BALATON Zoltan
2021-01-12 12:54   ` Jiaxun Yang
2021-01-12 22:25     ` BALATON Zoltan
2021-01-13  2:24       ` Jiaxun Yang [this message]
2021-01-09 20:16 ` [PATCH v2 12/13] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 09/13] vt82c686: Fix superio_cfg_{read,write}() functions BALATON Zoltan
2021-02-20 19:24   ` Philippe Mathieu-Daudé
2021-02-20 22:00     ` BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 10/13] vt82c686: Implement control of serial port io ranges via config regs BALATON Zoltan
2021-02-20 19:30   ` Philippe Mathieu-Daudé
2021-02-20 22:53     ` BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 05/13] vt82c686: Set user_creatable=false for VT82C686B_PM BALATON Zoltan
2021-01-09 23:41   ` Philippe Mathieu-Daudé
2021-01-13  2:27   ` Jiaxun Yang
2021-01-09 20:16 ` [PATCH v2 02/13] vt82c686: Reorganise code BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 06/13] vt82c686: Make vt82c686b-pm an abstract base class and add vt8231-pm based on it BALATON Zoltan
2021-01-09 23:42   ` Philippe Mathieu-Daudé
2021-01-09 20:16 ` [PATCH v2 04/13] vt82c686: Fix up power management io base and config BALATON Zoltan
2021-02-20 18:58   ` Philippe Mathieu-Daudé
2021-02-20 22:33     ` BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 11/13] vt82c686: QOM-ify superio related functionality BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 13/13] vt82c686: Add emulation of VT8231 south bridge BALATON Zoltan
2021-01-09 20:16 ` [PATCH v2 01/13] vt82c686: Move superio memory region to SuperIOConfig struct BALATON Zoltan
2021-01-10  0:06   ` Philippe Mathieu-Daudé
2021-01-13  2:26   ` Jiaxun Yang
2021-01-09 20:16 ` [PATCH v2 07/13] vt82c686: Simplify vt82c686b_realize() BALATON Zoltan
2021-02-21  9:48 ` [PATCH v2 00/13] vt82c686b clean ups and vt8231 emulation 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=d1a185bc-7b55-0389-a67c-2ed941293b51@flygoat.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=balaton@eik.bme.hu \
    --cc=chenhuacai@kernel.org \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    /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).